Add backslash escaping

This commit is contained in:
Sol Fisher Romanoff 2022-08-01 09:06:55 +03:00
parent d6e115fbb8
commit 2dcb6d82be
No known key found for this signature in database
GPG key ID: 9D3F2B64F2341B62
4 changed files with 36 additions and 1 deletions

View file

@ -147,6 +147,23 @@
return "$[" + token.tag + " " + this.parser.parseInline(token.tokens) + "]"; 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', name: 'center',
level: 'block', level: 'block',

View file

@ -1,6 +1,6 @@
{ {
"name": "marked-mfm", "name": "marked-mfm",
"version": "0.4.0", "version": "0.5.0",
"description": "Marked.js extension for Misskey-flavored Markdown", "description": "Marked.js extension for Misskey-flavored Markdown",
"main": "./src/index.js", "main": "./src/index.js",
"browser": "./lib/index.umd.js", "browser": "./lib/index.umd.js",

View file

@ -50,6 +50,19 @@ export default {
return `$[${token.tag} ${this.parser.parseInline(token.tokens)}]` 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', name: 'center',
level: 'block', level: 'block',

View file

@ -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') 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', () => { test('center', () => {
marked.use(markedMfm) marked.use(markedMfm)
expect(marked('<center>test *italic*</center>')).toBe('<center>test <em>italic</em></center>\n') expect(marked('<center>test *italic*</center>')).toBe('<center>test <em>italic</em></center>\n')