From 3e53ff92c0a38c5b76a56f117bfa2c6898650ef5 Mon Sep 17 00:00:00 2001 From: Sol Fisher Romanoff Date: Fri, 8 Jul 2022 13:33:03 +0300 Subject: [PATCH] Add search MFM --- src/index.js | 22 ++++++++++++++++++++++ test/index.test.js | 5 +++++ 2 files changed, 27 insertions(+) diff --git a/src/index.js b/src/index.js index b80f932..fd3fc57 100644 --- a/src/index.js +++ b/src/index.js @@ -52,5 +52,27 @@ export default { } }, }, + { + name: 'mfmSearch', + level: 'block', + start (src) { return src.match(/[^\n]+ search/)?.index }, + tokenizer (src, tokens) { + const rule = /^([^\n]+) search$/ + const match = rule.exec(src) + if (match) { + const token = { + type: 'mfmSearch', + raw: match[0], + query: match[1].trim(), + tokens: [], + } + this.lexer.inline(token.text, token.tokens) + return token + } + }, + renderer (token) { + return `${token.raw}` + }, + }, ], } diff --git a/test/index.test.js b/test/index.test.js index 356a4fb..17e141a 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -26,4 +26,9 @@ describe('marked-mfm', () => { marked.use(markedMfm) expect(marked('$[spin.alternate,speed=0.5s test]')).toBe('

test

\n') }) + + test('search', () => { + marked.use(markedMfm) + expect(marked('syuilo thighs search')).toBe('syuilo thighs search') + }) }) -- 2.34.1