mirror of
https://activitypub.software/TransFem-org/sfm-js
synced 2024-11-24 23:15:14 +00:00
implement syntax: emoji, custom emoji
This commit is contained in:
parent
36b2e27a05
commit
c76e32070f
3 changed files with 37 additions and 8 deletions
|
@ -41,4 +41,9 @@ npm run parse
|
|||
```
|
||||
|
||||
## License
|
||||
This software is released under the [MIT License](LICENSE).
|
||||
This software is released under the [MIT License](LICENSE) unless otherwise noted.
|
||||
|
||||
This software includes code of therd paty softwares below:
|
||||
- twemoji-parser
|
||||
Copyright (c) 2018 Twitter, Inc.
|
||||
MIT Licence: https://github.com/twitter/twemoji-parser/blob/master/LICENSE.md
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
mergeText
|
||||
} = require('./parser-utils');
|
||||
|
||||
const emojiRegex = require('./twemoji').default;
|
||||
|
||||
function applyParser(input, startRule) {
|
||||
let parseFunc = peg$parse;
|
||||
return parseFunc(input, startRule ? { startRule } : { });
|
||||
|
@ -14,7 +16,7 @@ rootParser
|
|||
= ts:(block / inline)* { return mergeText(ts); }
|
||||
|
||||
plainParser
|
||||
= ts:(text /*/ emoji*/)* { return mergeText(ts); }
|
||||
= ts:(customEmoji / textOrEmoji)* { return mergeText(ts); }
|
||||
|
||||
inlineParser
|
||||
= ts:(inline)* { return mergeText(ts); }
|
||||
|
@ -43,12 +45,8 @@ inline
|
|||
// / hashtag
|
||||
// / url
|
||||
// / link
|
||||
// / emoji
|
||||
/ text
|
||||
|
||||
text
|
||||
= c:. { return createTree('text', { text: c }); }
|
||||
|
||||
/ customEmoji
|
||||
/ textOrEmoji
|
||||
|
||||
// block: title
|
||||
|
||||
|
@ -276,6 +274,27 @@ mathInline
|
|||
}
|
||||
|
||||
|
||||
// inline: custom emoji
|
||||
|
||||
customEmoji
|
||||
= ":" name:$[a-z0-9_+-]+ ":"
|
||||
{
|
||||
return createTree('emoji', { name: name });
|
||||
}
|
||||
|
||||
|
||||
// inline: text or emoji
|
||||
|
||||
textOrEmoji
|
||||
= c:((a:[\uD800-\uDBFF] b:[\uDC00-\uDFFF] { return a + b; }) / .)
|
||||
{
|
||||
if (emojiRegex.test(c)) {
|
||||
return createTree('emoji', { emoji: c });
|
||||
}
|
||||
return createTree('text', { text: c });
|
||||
}
|
||||
|
||||
|
||||
// Core rules
|
||||
|
||||
CHAR
|
||||
|
|
5
src/parser/twemoji.ts
Normal file
5
src/parser/twemoji.ts
Normal file
File diff suppressed because one or more lines are too long
Loading…
Reference in a new issue