From d6e115fbb80563f306807ac440ef7e3e85e830ba Mon Sep 17 00:00:00 2001 From: Sol Fisher Romanoff Date: Sun, 31 Jul 2022 21:49:42 +0300 Subject: [PATCH] Add non-rawhtml center tag --- lib/index.umd.js | 24 ++++++++++++++++++++++++ src/index.js | 22 ++++++++++++++++++++++ test/index.test.js | 5 +++++ 3 files changed, 51 insertions(+) diff --git a/lib/index.umd.js b/lib/index.umd.js index 352f068..1cd2362 100644 --- a/lib/index.umd.js +++ b/lib/index.umd.js @@ -147,6 +147,30 @@ return "$[" + token.tag + " " + this.parser.parseInline(token.tokens) + "]"; } + }, { + name: 'center', + level: 'block', + start: function start(src) { + return src.match(/
/); + }, + tokenizer: function tokenizer(src, tokens) { + var rule = /^
([\S\s]*)<\/center>/; + var match = rule.exec(src); + + if (match) { + var token = { + type: 'center', + raw: match[0], + text: match[1], + tokens: [] + }; + this.lexer.inline(token.text, token.tokens); + return token; + } + }, + renderer: function renderer(token) { + return "
" + this.parser.parseInline(token.tokens) + "
\n"; + } }] }; diff --git a/src/index.js b/src/index.js index f4d337b..86299ec 100644 --- a/src/index.js +++ b/src/index.js @@ -50,5 +50,27 @@ export default { return `$[${token.tag} ${this.parser.parseInline(token.tokens)}]` }, }, + { + name: 'center', + level: 'block', + start (src) { return src.match(/
/) }, + tokenizer (src, tokens) { + const rule = /^
([\S\s]*)<\/center>/ + const match = rule.exec(src) + if (match) { + const token = { + type: 'center', + raw: match[0], + text: match[1], + tokens: [], + } + this.lexer.inline(token.text, token.tokens) + return token + } + }, + renderer (token) { + return `
${this.parser.parseInline(token.tokens)}
\n` + }, + }, ], } diff --git a/test/index.test.js b/test/index.test.js index 35b11bf..bcdb63a 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -41,4 +41,9 @@ describe('marked-mfm', () => { marked.use(markedMfm) expect(marked('$[spin.alternate,speed=0.5s test]')).toBe('

test

\n') }) + + test('center', () => { + marked.use(markedMfm) + expect(marked('
test *italic*
')).toBe('
test italic
\n') + }) })