Skip to content

How to prevent some characters from getting encoded? #167

Closed Answered by babakfp
babakfp asked this question in Q&A
Discussion options

You must be logged in to vote

I think I solved it.

constants.ts:

export const STRINGIFY_ENTITIES_DEFAULT_DANGEROUS_CHARACTERS = [
    '"',
    "&",
    "'",
    "<",
    ">",
    "`",
] as const

export const STRINGIFY_ENTITIES_DEFAULT_SVELTE_DANGEROUS_CHARACTERS = [
    "{",
    "}",
] as const

rehype-sanitize-md-code.ts:

import { stringifyEntities } from "stringify-entities"
import { visit } from "unist-util-visit"
import type { Plugin } from "unified"

import {
    STRINGIFY_ENTITIES_DEFAULT_DANGEROUS_CHARACTERS,
    STRINGIFY_ENTITIES_DEFAULT_SVELTE_DANGEROUS_CHARACTERS,
} from "./constants.js"

export const rehypeSanitizeMdCode: Plugin = () => {
    return (tree) => {
        visit(tree, "element", (node) => {

Replies: 2 comments 8 replies

Comment options

You must be logged in to vote
7 replies
@babakfp
Comment options

@ChristianMurphy
Comment options

@babakfp
Comment options

@ChristianMurphy
Comment options

@ChristianMurphy
Comment options

Comment options

You must be logged in to vote
1 reply
@ChristianMurphy
Comment options

Answer selected by babakfp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants