Remove search
fuck search
This commit is contained in:
parent
c748bacc0f
commit
4d885754fd
5 changed files with 3 additions and 55 deletions
|
@ -2,6 +2,7 @@
|
|||
a [Marked.js](https://marked.js.org) custom extension for [Misskey-flavored Markdown](https://github.com/misskey-dev/mfm.js/blob/develop/docs/syntax.md).
|
||||
|
||||
this is a reimplementation of [the original MFM parser](https://github.com/misskey-dev/mfm.js/blob/develop/docs/syntax.md), which was written from the ground up using PEG.js instead of as an extension of CommonMark, and therefore was not up to spec.
|
||||
this extension is mostly compatible with the original, except it only implements `$[tags]`. mentions, hashtags and the `search` markup are out of scope.
|
||||
|
||||
## usage
|
||||
|
||||
|
@ -11,5 +12,5 @@ const markedMfm = require('marked-mfm')
|
|||
|
||||
marked.use(markedMfm)
|
||||
marked.parse('$[x2 beeg text]')
|
||||
// <p><span class="_mfm_x2_" >beeg text</span></p>
|
||||
// <p><span class="mfm _mfm_x2_" >beeg text</span></p>
|
||||
```
|
||||
|
|
|
@ -147,32 +147,6 @@
|
|||
|
||||
return "$[" + token.tag + " " + this.parser.parseInline(token.tokens) + "]";
|
||||
}
|
||||
}, {
|
||||
name: 'mfmSearch',
|
||||
level: 'inline',
|
||||
start: function start(src) {
|
||||
var _src$match2;
|
||||
|
||||
return (_src$match2 = src.match(/(?<=^|<br>).+ search(?=$|<br>)/)) == null ? void 0 : _src$match2.index;
|
||||
},
|
||||
tokenizer: function tokenizer(src, tokens) {
|
||||
var rule = /^(?!.*<br>)(.+) search(?=$|<br>)/;
|
||||
var match = rule.exec(src);
|
||||
|
||||
if (match) {
|
||||
var token = {
|
||||
type: 'mfmSearch',
|
||||
raw: match[0],
|
||||
query: match[1].trim(),
|
||||
tokens: []
|
||||
};
|
||||
this.lexer.inline(token.text, token.tokens);
|
||||
return token;
|
||||
}
|
||||
},
|
||||
renderer: function renderer(token) {
|
||||
return "<a href=\"https://google.com/search?q=" + token.query + "\" class=\"mfm _mfm_search_\">" + token.raw + "</a>";
|
||||
}
|
||||
}]
|
||||
};
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "marked-mfm",
|
||||
"version": "0.3.2",
|
||||
"version": "0.4.0",
|
||||
"description": "Marked.js extension for Misskey-flavored Markdown",
|
||||
"main": "./src/index.js",
|
||||
"browser": "./lib/index.umd.js",
|
||||
|
|
22
src/index.js
22
src/index.js
|
@ -50,27 +50,5 @@ export default {
|
|||
return `$[${token.tag} ${this.parser.parseInline(token.tokens)}]`
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'mfmSearch',
|
||||
level: 'inline',
|
||||
start (src) { return src.match(/(?<=^|<br>).+ search(?=$|<br>)/)?.index },
|
||||
tokenizer (src, tokens) {
|
||||
const rule = /^(?!.*<br>)(.+) search(?=$|<br>)/
|
||||
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}" class="mfm _mfm_search_">${token.raw}</a>`
|
||||
},
|
||||
},
|
||||
],
|
||||
}
|
||||
|
|
|
@ -41,9 +41,4 @@ describe('marked-mfm', () => {
|
|||
marked.use(markedMfm)
|
||||
expect(marked('$[spin.alternate,speed=0.5s test]')).toBe('<p><span class="mfm _mfm_spin_" data-alternate data-speed="0.5s">test</span></p>\n')
|
||||
})
|
||||
|
||||
test('search', () => {
|
||||
marked.use(markedMfm)
|
||||
expect(marked('syuilo thighs search')).toBe('<p><a href="https://google.com/search?q=syuilo thighs" class="mfm _mfm_search_">syuilo thighs search</a></p>\n')
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue