Skip to content

Code feedback #1300

Answered by babakfp
babakfp asked this question in Q&A
Mar 21, 2024 · 2 comments · 2 replies
Discussion options

You must be logged in to vote

Thanks.
I did this, and I think it's good enough 👍

import { visit } from "unist-util-visit"
import { Transformer } from "unified"
import type {
    Blockquote,
    FootnoteDefinition,
    ListItem,
    Paragraph,
    Root,
} from "mdast"

// Examples: `"svelte:head"`, `"svelte:head/"`
const SVELTE_SPECIAL_ELEMENTS_NAME = /^svelte:[a-z]+\/?$/i
const SVELTE_SPECIAL_ELEMENTS_OPEN = /<svelte:[a-z]+(?:\s+[^>]*)?\/?>/i
const SVELTE_SPECIAL_ELEMENTS_CLOSE = /<\/svelte:[a-z]+(?:\s+[^>]*)?>/i

export default (): Transformer<Root> => {
    return (tree) => {
        fixSpecialElements(tree)
        removeEmptyParagraph(tree)
    }
}

/** Converts incorrect type of Svelte Special Elements to `"html"…

Replies: 2 comments 2 replies

Comment options

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

Answer selected by babakfp
Comment options

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

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