Skip to content

Instantly share code, notes, and snippets.

@bates64
Last active March 5, 2018 22:37
Show Gist options
  • Save bates64/7d71098f712f26a0169ad7fda51ce7bf to your computer and use it in GitHub Desktop.
Save bates64/7d71098f712f26a0169ad7fda51ce7bf to your computer and use it in GitHub Desktop.
Strikethrough extension for mrk (https://github.com/heyitsmeuralex/mrk)
const markStrikethrough = mrk({
extendPatterns: {
strikethroughStart: ({ read, has }) => {
// If this function returns a truthy value, it will be parsed as a strikethroughStart token
// See mrk.js for how `read` and `has` work, plus other functions you get access to.
return read(2) === '~~' // Next 2 characters should be `~~`
&& !has('strikethroughStart', 'strikethroughEnd') // Not already strikethrough!
},
strikethroughEnd: ({ read, has }) => {
return read(2) === '~~' // Next 2 characters should be `~~`
&& has('strikethroughStart', 'strikethroughEnd') // Must have a strikethroughStart before this token
},
},
extendPairs: {
// If there is a strikethroughStart token on its own without a strikethroughEnd token to be paired
// to, it will be discarded and parsed as text.
strikethroughStart: 'strikethroughEnd'
},
extendHtmlify: {
// Declares how to convert these tokens into HTML strings.
strikethroughStart = () => '<s>',
strikethroughEnd = () => '</s>'
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment