Add backslash escaping
This commit is contained in:
parent
d6e115fbb8
commit
2dcb6d82be
4 changed files with 36 additions and 1 deletions
|
@ -147,6 +147,23 @@
|
|||
|
||||
return "$[" + token.tag + " " + this.parser.parseInline(token.tokens) + "]";
|
||||
}
|
||||
}, {
|
||||
name: 'escapedMfm',
|
||||
level: 'inline',
|
||||
start: function start(src) {
|
||||
return src.match(/\\\$\[/);
|
||||
},
|
||||
tokenizer: function tokenizer(src, tokens) {
|
||||
if (/^\\\$\[/.exec(src)) {
|
||||
return {
|
||||
type: 'escapedMfm',
|
||||
raw: '\\$['
|
||||
};
|
||||
}
|
||||
},
|
||||
renderer: function renderer(token) {
|
||||
return '$[';
|
||||
}
|
||||
}, {
|
||||
name: 'center',
|
||||
level: 'block',
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "marked-mfm",
|
||||
"version": "0.4.0",
|
||||
"version": "0.5.0",
|
||||
"description": "Marked.js extension for Misskey-flavored Markdown",
|
||||
"main": "./src/index.js",
|
||||
"browser": "./lib/index.umd.js",
|
||||
|
|
13
src/index.js
13
src/index.js
|
@ -50,6 +50,19 @@ export default {
|
|||
return `$[${token.tag} ${this.parser.parseInline(token.tokens)}]`
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'escapedMfm',
|
||||
level: 'inline',
|
||||
start (src) { return src.match(/\\\$\[/) },
|
||||
tokenizer (src, tokens) {
|
||||
if (/^\\\$\[/.exec(src)) {
|
||||
return { type: 'escapedMfm', raw: '\\$[' }
|
||||
}
|
||||
},
|
||||
renderer (token) {
|
||||
return '$['
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'center',
|
||||
level: 'block',
|
||||
|
|
|
@ -42,6 +42,11 @@ describe('marked-mfm', () => {
|
|||
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('escaped', () => {
|
||||
marked.use(markedMfm)
|
||||
expect(marked('\\$[spin test]')).toBe('<p>$[spin test]</p>\n')
|
||||
})
|
||||
|
||||
test('center', () => {
|
||||
marked.use(markedMfm)
|
||||
expect(marked('<center>test *italic*</center>')).toBe('<center>test <em>italic</em></center>\n')
|
||||
|
|
Loading…
Reference in a new issue