[MFM] Improve italic syntax detection

This commit is contained in:
syuilo
2019-01-25 16:41:51 +09:00
parent 501379c82c
commit 42cd7c8a75
3 changed files with 18 additions and 1 deletions

View File

@ -224,7 +224,16 @@ const mfm = P.createLanguage({
//#region Italic
italic: r =>
P.alt(P.regexp(/<i>([\s\S]+?)<\/i>/, 1), P.regexp(/(\*|_)([a-zA-Z0-9]+?[\s\S]*?)\1/, 2))
P.alt(
P.regexp(/<i>([\s\S]+?)<\/i>/, 1),
P((input, i) => {
const text = input.substr(i);
const match = text.match(/^(\*|_)([a-zA-Z0-9]+?[\s\S]*?)\1/);
if (!match) return P.makeFailure(i, 'not a italic');
if (input[i - 1] != null && input[i - 1].match(/[a-z0-9]/i)) return P.makeFailure(i, 'not a italic');
return P.makeSuccess(i + match[0].length, match[2]);
})
)
.map(x => createTree('italic', P.alt(
r.bold,
r.strike,