mirror of
https://activitypub.software/TransFem-org/sfm-js
synced 2024-11-21 21:55:09 +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
|
## 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
|
mergeText
|
||||||
} = require('./parser-utils');
|
} = require('./parser-utils');
|
||||||
|
|
||||||
|
const emojiRegex = require('./twemoji').default;
|
||||||
|
|
||||||
function applyParser(input, startRule) {
|
function applyParser(input, startRule) {
|
||||||
let parseFunc = peg$parse;
|
let parseFunc = peg$parse;
|
||||||
return parseFunc(input, startRule ? { startRule } : { });
|
return parseFunc(input, startRule ? { startRule } : { });
|
||||||
|
@ -14,7 +16,7 @@ rootParser
|
||||||
= ts:(block / inline)* { return mergeText(ts); }
|
= ts:(block / inline)* { return mergeText(ts); }
|
||||||
|
|
||||||
plainParser
|
plainParser
|
||||||
= ts:(text /*/ emoji*/)* { return mergeText(ts); }
|
= ts:(customEmoji / textOrEmoji)* { return mergeText(ts); }
|
||||||
|
|
||||||
inlineParser
|
inlineParser
|
||||||
= ts:(inline)* { return mergeText(ts); }
|
= ts:(inline)* { return mergeText(ts); }
|
||||||
|
@ -43,12 +45,8 @@ inline
|
||||||
// / hashtag
|
// / hashtag
|
||||||
// / url
|
// / url
|
||||||
// / link
|
// / link
|
||||||
// / emoji
|
/ customEmoji
|
||||||
/ text
|
/ textOrEmoji
|
||||||
|
|
||||||
text
|
|
||||||
= c:. { return createTree('text', { text: c }); }
|
|
||||||
|
|
||||||
|
|
||||||
// block: title
|
// 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
|
// Core rules
|
||||||
|
|
||||||
CHAR
|
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