tylingsoft / markdown-it-regex

Plugin for markdown-it, replaces strings that match a regular expression pattern.
7 stars 6 forks source link

Cannot detect spaces #1

Closed gldraphael closed 6 years ago

gldraphael commented 6 years ago

The regex /([ ]{2, })/ which should capture two or more consecutive spaces does not work.

You may check this commit for an example and paste the following on your terminal to see it in action:

git clone -b nbsp-with-tylingsofts-plugin https://github.com/gldraphael/chordsheet.git --depth 1
cd chordsheet
yarn
yarn test

Typescript code for completeness:

const nbspPlugin = {
  name: 'nbsp',
  regex: /([ ]{2, })/,
  replace: (match: RegExpMatchArray) => {
    console.log('is it working?')
    return `  `
  }
}
const markdownIt = md(defaultChordsheetOptions.markdownItOptions as md.Options)
    .use(mdRegex, nbspPlugin)
console.log(markdownIt.render(`Hey     There`))
tylerlong commented 6 years ago

It works for me

const mdi = markdownIt()
mdi.use(markdownItRegex, {
  name: 'spaces',
  regex: /([ ]{2,})/,
  replace: (match) => {
    return `  `
  }
})
console.log(mdi.render('Hey       There'))
<p>Hey&nbsp;&nbsp;There</p>

I've added it to test case: https://github.com/tylingsoft/markdown-it-regex/blob/master/test/index.js#L37