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

Footnotes get user-content-user-content ids and do not work #13

Closed
4 tasks done
michaelrommel opened this issue Nov 22, 2024 · 5 comments
Closed
4 tasks done

Footnotes get user-content-user-content ids and do not work #13

michaelrommel opened this issue Nov 22, 2024 · 5 comments
Labels
🙋 no/question This does not need any changes 👎 phase/no Post cannot or will not be acted on

Comments

@michaelrommel
Copy link

Initial checklist

Affected package

remark-gfm#@3.0.1

Steps to reproduce

Hello,
when using the following sequence of plugins (shortened), I get issues with the footnotes.

	const vfile = await unified()
		.use(remarkParse)
		.use(remarkToc, { maxDepth: 2, tight: true, prefix: 'user-content-' })
		.use(remarkGfm, { singleTilde: false, clobberPrefix: '' })
		.use(remarkSupersub)
		.use(remarkRehype)
		.use(rehypeSlug)
		.use(rehypeAutolinkHeadings, { behaviour: 'wrap' })
		.use(rehypeSanitize, {
			...defaultSchema,
			attributes: {
				...defaultSchema.attributes,
				// The `language-*` regex is allowed by default.
				div: [
					...(defaultSchema.attributes.div || []),
					[
						'className',
						/^language-./,
						'math-inline',
						'math-display',
						'grid-left-right',
						'img-right'
					]
				],
				span: [
					...(defaultSchema.attributes.span || []),
					['className', 'line', 'math-inline']
				],
				SvelteComponent: [
					'componentname',
					'data',
					'xSelector',
					'file',
					'dpr',
					'inertia'
				]
			},
			tagNames: [...defaultSchema.tagNames, 'SvelteComponent']
		})

At the remarkRehype stage already the footnotes have a user-content- prefix and rehypeSanitize adds another one on top of it. Before remarkSanitize it works fine. So in order to not have the footnotes already come with a user-content prefix, I wanted to supply the remarkGfm with a clobberPrefix of "" but it does not trickle down to the footnote plugin.

Is there a way to inherit this?

Probably here?

gfmFootnote(),

Thanks,

Michael.

Actual behavior

Footnote

  • ids get a user-content-user-content prefix.

    Expected behavior

    I'd like the footnotes before remark-sanitize have NO user-content- prefix

    Runtime

    node@22.7

    Package manager

    pnpm

    Operating system

    linux

    Build and bundle tools

    Vite

  • @github-actions github-actions bot added 👋 phase/new Post is being triaged automatically 🤞 phase/open Post is being triaged manually and removed 👋 phase/new Post is being triaged automatically labels Nov 22, 2024
    @michaelrommel michaelrommel changed the title Footnotes get user-content-user-content labels and do not work Footnotes get user-content-user-content ids and do not work Nov 22, 2024
    @michaelrommel
    Copy link
    Author

    image

    @michaelrommel
    Copy link
    Author

    The example of footnotes not working is live here: https://michaelrommel.com/create/2022-01-25-markdown-sample#user-content-superscript--subscript

    The sourcecode to that function is here: https://github.com/michaelrommel/blog/blob/main/src/lib/markdown.js

    @michaelrommel
    Copy link
    Author

    I think, now I solved it. I have set clobberPrefix in the sanitize schema to '' and added a prefix to the rehypeSlug.
    I'll keep this open, so that you can share your thoughts on what should be the best way. Feel free to close it, I think (!) it works now. Need further testing...

    @wooorm
    Copy link
    Member

    wooorm commented Nov 25, 2024

    Hi!

    Different things indeed add prefixes. The way to solve that is to do it once, at the end. By rehype-sanitize.
    Do not pass to prefix: 'user-content-' to remark-toc, that duplicates things.

    This package itself, micromark-extension-gfm has an option, but that option applies only when you compile directly to HTML, not when you use it with ASTs, as you are doing with remark-gfm.
    So, this issue, how you pass that option in your example, that option doesn’t exist. It doesn’t do anything.

    Importantly, the markdown is either dangerous or not. If it is not dangerous, you do not need to sanitize it, you do not need prefix things.
    If it is dangerous, that means dangerous users can write dangerous things, and you need to prefix them. Still, likely it’s fine, so you want nice URLs. But that means the IDs have to be prefixed, but the links not.
    This is explained in the in-depth guide: https://github.com/rehypejs/rehype-sanitize#example-headings-dom-clobbering.

    @wooorm wooorm closed this as not planned Won't fix, can't repro, duplicate, stale Nov 25, 2024
    @wooorm wooorm added the 🙋 no/question This does not need any changes label Nov 25, 2024

    This comment has been minimized.

    @github-actions github-actions bot added 👎 phase/no Post cannot or will not be acted on and removed 🤞 phase/open Post is being triaged manually labels Nov 25, 2024
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    🙋 no/question This does not need any changes 👎 phase/no Post cannot or will not be acted on
    Development

    No branches or pull requests

    2 participants