We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The wiki example contains incorrect regex patterns, leading to unexpected results.
Let's say we are trying to convert mdText with the following default classes:
mdText
const mdText = ` This is a paragraph \`\`\` This is a code block. \`\`\` ` const classMap = { p: 'text-sm', }
If we use the code in the wiki example, the <pre> tag would be incorrectly replaced.
<pre>
const oldBindings = Object.keys(classMap) .map(key => ({ type: 'output', regex: new RegExp(`<${key}(.*)>`, 'g'), replace: `<${key} class="${classMap[key]}" $1>` })); const oldConv = new Showdown.Converter({ extensions: [...oldBindings] }); console.log(oldConv.makeHtml(mdText)) // Output is: // <p class="text-sm" >This is a paragraph</p> // <p class="text-sm" re><code>This is a code block. // </code></pre>
Notice that <pre> is replaced by <p class="text-sm" re>.
<p class="text-sm" re>
I suggest using this regex pattern:
const newBindings = Object.keys(classMap) .map(key => ({ type: 'output', regex: new RegExp(`(?:<${key}>)|(?:<${key} (.*)>)`, 'g'), replace: `<${key} class="${classMap[key]}" $1>` })); const newConv = new Showdown.Converter({ extensions: [...newBindings] }) console.log(newConv.makeHtml(mdText)) // Output is: // <p class="text-sm" >This is a paragraph</p> // <pre><code>This is a code block. // </code></pre>
This new regex pattern ensures proper replacement without affecting other HTML tags.
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Description
The wiki example contains incorrect regex patterns, leading to unexpected results.
Example
Let's say we are trying to convert
mdText
with the following default classes:If we use the code in the wiki example, the
<pre>
tag would be incorrectly replaced.Notice that
<pre>
is replaced by<p class="text-sm" re>
.Suggestion
I suggest using this regex pattern:
This new regex pattern ensures proper replacement without affecting other HTML tags.
The text was updated successfully, but these errors were encountered: