Add mfm tag to all processed content

This commit is contained in:
Sol Fisher Romanoff 2022-07-09 14:29:30 +03:00
parent 8e4cb2639b
commit 2dae330d4c
No known key found for this signature in database
GPG key ID: 9D3F2B64F2341B62
4 changed files with 13 additions and 13 deletions

View file

@ -138,7 +138,7 @@
});
}
return "<span class=\"_mfm_" + token.tag + "_\" " + options.join(' ') + ">" + this.parser.parseInline(token.tokens) + "</span>";
return "<span class=\"mfm _mfm_" + token.tag + "_\" " + options.join(' ') + ">" + this.parser.parseInline(token.tokens) + "</span>";
}
return "$[" + token.tag + " " + this.parser.parseInline(token.tokens) + "]";
@ -167,7 +167,7 @@
}
},
renderer: function renderer(token) {
return "<a href=\"https://google.com/search?q=" + token.query + "\" class=\"_mfm_search_\">" + token.raw + "</a>";
return "<a href=\"https://google.com/search?q=" + token.query + "\" class=\"mfm _mfm_search_\">" + token.raw + "</a>";
}
}]
};

View file

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

View file

@ -42,7 +42,7 @@ export default {
if (token.options) {
options = token.options.split(',').map((opt) => (opt.split('=').length === 2 ? `data-${opt.split('=')[0]}="${opt.split('=')[1]}"` : `data-${opt}`))
}
return `<span class="_mfm_${token.tag}_" ${options.join(' ')}>${this.parser.parseInline(token.tokens)}</span>`
return `<span class="mfm _mfm_${token.tag}_" ${options.join(' ')}>${this.parser.parseInline(token.tokens)}</span>`
}
return `$[${token.tag} ${this.parser.parseInline(token.tokens)}]`
},
@ -66,7 +66,7 @@ export default {
}
},
renderer (token) {
return `<a href="https://google.com/search?q=${token.query}" class="_mfm_search_">${token.raw}</a>`
return `<a href="https://google.com/search?q=${token.query}" class="mfm _mfm_search_">${token.raw}</a>`
},
},
],

View file

@ -4,42 +4,42 @@ import markedMfm from '../src/index.js'
describe('marked-mfm', () => {
test('inline', () => {
marked.use(markedMfm)
expect(marked('$[x2 this text is bigger]')).toBe('<p><span class="_mfm_x2_" >this text is bigger</span></p>\n')
expect(marked('$[x2 this text is bigger]')).toBe('<p><span class="mfm _mfm_x2_" >this text is bigger</span></p>\n')
})
test('multiline', () => {
marked.use(markedMfm)
expect(marked('$[x2 line1\nline2]')).toBe('<p><span class="_mfm_x2_" >line1\nline2</span></p>\n')
expect(marked('$[x2 line1\nline2]')).toBe('<p><span class="mfm _mfm_x2_" >line1\nline2</span></p>\n')
})
test('nested', () => {
marked.use(markedMfm)
expect(marked('$[x2 x2 $[sparkle sparkle]]')).toBe('<p><span class="_mfm_x2_" >x2 <span class="_mfm_sparkle_" >sparkle</span></span></p>\n')
expect(marked('$[x2 x2 $[sparkle sparkle]]')).toBe('<p><span class="mfm _mfm_x2_" >x2 <span class="mfm _mfm_sparkle_" >sparkle</span></span></p>\n')
})
test('lazy matching', () => {
marked.use(markedMfm)
expect(marked('$[x2 one] $[x2 two]')).toBe('<p><span class="_mfm_x2_" >one</span> <span class="_mfm_x2_" >two</span></p>\n')
expect(marked('$[x2 one] $[x2 two]')).toBe('<p><span class="mfm _mfm_x2_" >one</span> <span class="mfm _mfm_x2_" >two</span></p>\n')
})
test('nested & lazy matching', () => {
marked.use(markedMfm)
expect(marked('$[x2 one $[x2 two]] $[x2 three]')).toBe('<p><span class="_mfm_x2_" >one <span class="_mfm_x2_" >two</span></span> <span class="_mfm_x2_" >three</span></p>\n')
expect(marked('$[x2 one $[x2 two]] $[x2 three]')).toBe('<p><span class="mfm _mfm_x2_" >one <span class="mfm _mfm_x2_" >two</span></span> <span class="mfm _mfm_x2_" >three</span></p>\n')
})
test('invalid', () => {
marked.use(markedMfm)
expect(marked('$[invalid $[x2 test]]')).toBe('<p>$[invalid <span class="_mfm_x2_" >test</span>]</p>\n')
expect(marked('$[invalid $[x2 test]]')).toBe('<p>$[invalid <span class="mfm _mfm_x2_" >test</span>]</p>\n')
})
test('one option', () => {
marked.use(markedMfm)
expect(marked('$[twitch.speed=2s test]')).toBe('<p><span class="_mfm_twitch_" data-speed="2s">test</span></p>\n')
expect(marked('$[twitch.speed=2s test]')).toBe('<p><span class="mfm _mfm_twitch_" data-speed="2s">test</span></p>\n')
})
test('multiple options', () => {
marked.use(markedMfm)
expect(marked('$[spin.alternate,speed=0.5s test]')).toBe('<p><span class="_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('search', () => {