Replace space with non-breaking space in footnotes backreference #9847
Replies: 5 comments 5 replies
-
This behavior is produced by remark-gfm which tries to align with the behavior of GitHub. If you don't like this behavior, you'd have to contact GitHub to change this behavior in the first place because I don't think the gfm plugin will be ok to make an exception to diverge from GitHub behavior. See also: https://github.com/micromark/micromark-extension-gfm-footnote Here is a simple footnote[^1]. With some additional text after it.
[^1]: My reference. Here is a simple footnote1. With some additional text after it. Using the MDX playground, you can see how this code is compiled to React: Technically you could solve this problem yourself to alter how this is rendered. Solution 1You could create a rehype plugin that process this const node = {
type: "element",
tagName: "p",
properties: {},
children: [
{
type: "text",
value: "My reference. ",
},
{
type: "element",
tagName: "a",
properties: {
href: "#user-content-fnref-1",
dataFootnoteBackref: "",
ariaLabel: "Back to reference 1",
className: ["data-footnote-backref"],
},
children: [
{
type: "text",
value: "↩",
},
],
},
],
}; Solution 2You could also register a custom React component for https://docusaurus.io/docs/markdown-features/react#mdx-component-scope It's a bit complicated to explain so here's a demo sandbox to help you: import React from 'react';
import MDXComponents from '@theme-original/MDXComponents';
function MyCustomParagraph(props) {
// Here you can override how we render the backref paragraph you don't like
const isFootnoteBackref =
typeof props?.children?.[1]?.props?.['data-footnote-backref'] !==
'undefined';
if (isFootnoteBackref) {
const children = [...props.children];
children[0] = children[0].trim() + '🚀🚀🚀🚀🚀🚀🚀';
return <p {...props} children={children} />;
}
return <p {...props} />;
}
export default {
...MDXComponents,
p: MyCustomParagraph,
}; Result: Footnotes
|
Beta Was this translation helpful? Give feedback.
-
Thanks, I suspected this was coming from a 3rd-party plugin; I appreciate the confirmation and the example workarounds. |
Beta Was this translation helpful? Give feedback.
-
Codepen demonstrating the error: https://stackblitz.com/edit/github-axpson-vcyooy?file=src%2Fpages%2Findex.md |
Beta Was this translation helpful? Give feedback.
-
Understood & appreciated. |
Beta Was this translation helpful? Give feedback.
-
Quick follow-up for anyone who might see this issue: it turns out there's a much simpler solution, which is to use the CSS
|
Beta Was this translation helpful? Give feedback.
-
The backreference link appearing at the end of every footnote is currently separated from the footnote copy by a breaking space, sometimes resulting in a typographic orphan. In other words, the link can appear on the next line all by itself.
I'd like to see that space replaced by a non-breaking space
to prevent typographic orphans.I tried to find the code that generates the backlinks but failed. I suspect it's actually in the Markdown parser?
Beta Was this translation helpful? Give feedback.
All reactions