This commit is contained in:
Sol Fisher Romanoff 2022-07-08 13:03:03 +03:00
parent 336f890781
commit 409c0f854c
Signed by: nbsp
GPG Key ID: 9D3F2B64F2341B62
1 changed files with 23 additions and 27 deletions

View File

@ -3,7 +3,7 @@ export default {
{
name: 'mfm',
level: 'inline',
start(src) { return src.match(/\$\[/)?.index },
start (src) { return src.match(/\$\[/)?.index },
tokenizer (src, tokens) {
const rule = /^\$\[(?<markup>[\w\d]+)(?:\.(?<options>\S+))? (?<text>.+)\]$/
const match = rule.exec(src)
@ -14,7 +14,7 @@ export default {
markup: match.groups.markup,
options: match.groups.options,
text: match.groups.text,
tokens: []
tokens: [],
}
this.lexer.inline(token.text, token.tokens)
return token
@ -28,33 +28,29 @@ export default {
return i
}, {})
}
const el = (mfmClass, mfmStyle = "") => `<span style="display: inline-block;${mfmStyle}" class="${mfmClass}">${this.parser.parseInline(token.tokens)}</span>`
const el = (mfmClass, mfmStyle = '') => `<span style="display: inline-block;${mfmStyle}" class="${mfmClass}">${this.parser.parseInline(token.tokens)}</span>`
switch (token.markup) {
case 'x2': {
return el('x2')
break
}
case 'twitch': {
const speed = options.speed || '0.5s'
return el('twitch', ` animation: mfm-twitch ${speed} ease infinite;`)
break
}
case 'sparkle': {
return el('sparkle')
break
}
case 'spin': {
const direction = options.left ? 'reverse' : options.alternate ? 'alternate' : 'normal'
const anime = options.x ? 'mfm-spinX' : options.y ? 'mfm-spinY' : 'mfm-spin'
const speed = options.speed || '1.5s'
return el('spin', ` animation: ${anime} ${speed} linear infinite; animation-direction: ${direction};`)
break
}
default: {
return `$[${token.markup} ${this.parser.parseInline(token.tokens)}]`
}
case 'x2': {
return el('x2')
}
case 'twitch': {
const speed = options.speed || '0.5s'
return el('twitch', ` animation: mfm-twitch ${speed} ease infinite;`)
}
case 'sparkle': {
return el('sparkle')
}
case 'spin': {
const direction = options.left ? 'reverse' : options.alternate ? 'alternate' : 'normal'
const anime = options.x ? 'mfm-spinX' : options.y ? 'mfm-spinY' : 'mfm-spin'
const speed = options.speed || '1.5s'
return el('spin', ` animation: ${anime} ${speed} linear infinite; animation-direction: ${direction};`)
}
default: {
return `$[${token.markup} ${this.parser.parseInline(token.tokens)}]`
}
}
},
},
]
],
}