forked from nbsp/marked-mfm
Add search MFM
This commit is contained in:
parent
409c0f854c
commit
3e53ff92c0
2 changed files with 27 additions and 0 deletions
22
src/index.js
22
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 `<a href="https://google.com/search?q=${token.query}">${token.raw}</a>`
|
||||
},
|
||||
},
|
||||
],
|
||||
}
|
||||
|
|
|
@ -26,4 +26,9 @@ describe('marked-mfm', () => {
|
|||
marked.use(markedMfm)
|
||||
expect(marked('$[spin.alternate,speed=0.5s test]')).toBe('<p><span style="display: inline-block; animation: mfm-spin 0.5s linear infinite; animation-direction: alternate;" class="spin">test</span></p>\n')
|
||||
})
|
||||
|
||||
test('search', () => {
|
||||
marked.use(markedMfm)
|
||||
expect(marked('syuilo thighs search')).toBe('<a href="https://google.com/search?q=syuilo thighs">syuilo thighs search</a>')
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue