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

What is replacing soft line breaks with ensp? #15

Open
bwklein opened this issue Mar 30, 2024 · 1 comment
Open

What is replacing soft line breaks with ensp? #15

bwklein opened this issue Mar 30, 2024 · 1 comment
Assignees

Comments

@bwklein
Copy link
Contributor

bwklein commented Mar 30, 2024

In the tree output from the toHast function there is a string like

lineBreak\u000bThis line contains a shift-enter soft line-break here\u000bThis bit is after the line break.

This string contains the "U+000B Line Tabulation" control character.

This is replaced by   in the HTML code, after running it through the following code:

let html = unified()
  .use(rehypeStringify, { collapseEmptyAttributes: true })
  .stringify(tree);

Do you know how I can preserve this control character or replace it with the HTML hex reference ?

@ka2n
Copy link

ka2n commented Oct 13, 2024

This is rehypeStringify behavior. You can replace the tree before passing to unified() process.

As a side node, my solution was replacing it with <br />:

function convertVerticalTabToBr(node: RootContent): void {
  visit(node, "text", function (node, index, parent) {
    if (node.type === "text") {
      const textNode = node as Text
      if (textNode.value.includes("\u000b")) {
        const texts = textNode.value
          .split("\u000b")
          .flatMap((item) => [{ ...textNode, value: item }, h("br")])
          .slice(0, -1)
        if (index !== null && parent) {
          // remove and insert
          parent.children.splice(index, 1, ...texts)
        }
      }
    }
  })
}

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

No branches or pull requests

3 participants