Skip to content
New issue

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

fix(code-block): escape html chars to text content #169

Merged
merged 1 commit into from
Jan 18, 2024

Conversation

nobkd
Copy link
Collaborator

@nobkd nobkd commented Jan 17, 2024

Partial fix for #168

Escapes chars from code blocks to prevent them from being parsed as HTML.

This is not ideal, as code markup parsers have to then check for replaced char codes.

But replacing after running the fn function is also not great, because it potentially appends real HTML parts (e.g., <span>s) to do, for example, highlighting.

export function renderCodeBlock({ name, code, attr }, fn) {
// console.info(name, code, attr, fn)
if (name) attr.class = concat(`syntax-${name}`, attr.class)
const body = join(code)
const body = join(code).replace(replaceSpecialChars, c => specialChars[c])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be replaceAll, here? otherwise, would only replace the first one.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like there is a 'g' flag on the RegExp which makes it global (replace all)

@tipiirai tipiirai merged commit c4c5d9f into nuejs:master Jan 18, 2024
3 checks passed
@tipiirai
Copy link
Contributor

Looks solid. I might later apply this regexp only if there is no custom syntax highlighter provided on the fn argument. I'm introducing a Nue-specific highlighter later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants