diff options
| author | Aya Morisawa <AyaMorisawa4869@gmail.com> | 2019-01-25 23:08:06 +0900 |
|---|---|---|
| committer | Aya Morisawa <AyaMorisawa4869@gmail.com> | 2019-01-25 23:08:06 +0900 |
| commit | 79d2374d8ec1de10740d36309c26d00e5ab44c68 (patch) | |
| tree | b5abfda351f46ce39375f6ed495572a59856e983 /src/mfm | |
| parent | Refactor (diff) | |
| download | misskey-79d2374d8ec1de10740d36309c26d00e5ab44c68.tar.gz misskey-79d2374d8ec1de10740d36309c26d00e5ab44c68.tar.bz2 misskey-79d2374d8ec1de10740d36309c26d00e5ab44c68.zip | |
Add multiline math syntax
Co-authored-by: syuilo <syuilotan@yahoo.co.jp>
Diffstat (limited to 'src/mfm')
| -rw-r--r-- | src/mfm/html.ts | 8 | ||||
| -rw-r--r-- | src/mfm/parser.ts | 23 |
2 files changed, 22 insertions, 9 deletions
diff --git a/src/mfm/html.ts b/src/mfm/html.ts index 6af2833858..b86d33a39a 100644 --- a/src/mfm/html.ts +++ b/src/mfm/html.ts @@ -87,7 +87,13 @@ export default (tokens: MfmForest, mentionedRemoteUsers: INote['mentionedRemoteU return el; }, - math(token) { + mathInline(token) { + const el = doc.createElement('code'); + el.textContent = token.node.props.formula; + return el; + }, + + mathBlock(token) { const el = doc.createElement('code'); el.textContent = token.node.props.formula; return el; diff --git a/src/mfm/parser.ts b/src/mfm/parser.ts index b86e1d5559..01b69c9690 100644 --- a/src/mfm/parser.ts +++ b/src/mfm/parser.ts @@ -103,7 +103,8 @@ const mfm = P.createLanguage({ r.blockCode, r.inlineCode, r.quote, - r.math, + r.mathInline, + r.mathBlock, r.search, r.title, r.center, @@ -121,7 +122,7 @@ const mfm = P.createLanguage({ r.mention, r.hashtag, r.emoji, - r.math, + r.mathInline, r.text ).atLeast(1).tryParse(x), {})), //#endregion @@ -135,7 +136,7 @@ const mfm = P.createLanguage({ r.mention, r.hashtag, r.emoji, - r.math, + r.mathInline, r.text ).atLeast(1).tryParse(x), {})), //#endregion @@ -180,7 +181,7 @@ const mfm = P.createLanguage({ r.mention, r.hashtag, r.emoji, - r.math, + r.mathInline, r.url, r.link, r.text @@ -274,10 +275,16 @@ const mfm = P.createLanguage({ }), //#endregion - //#region Math - math: r => + //#region Math (inline) + mathInline: r => P.regexp(/\\\((.+?)\\\)/, 1) - .map(x => createLeaf('math', { formula: x })), + .map(x => createLeaf('mathInline', { formula: x })), + //#endregion + + //#region Math (block) + mathBlock: r => + P.regexp(/\\\[([\s\S]+?)\\\]/, 1) + .map(x => createLeaf('mathBlock', { formula: x.trim() })), //#endregion //#region Mention @@ -311,7 +318,7 @@ const mfm = P.createLanguage({ r.emoji, r.url, r.link, - r.math, + r.mathInline, r.text ).atLeast(1).tryParse(x), {})), //#endregion |