rehype-pretty / rehype-pretty-code

Beautiful code blocks for Markdown or MDX.
https://rehype-pretty.pages.dev
MIT License
1.01k stars 63 forks source link

plaintext does not render empty lines (\n line breaks) #157

Closed ben519 closed 8 months ago

ben519 commented 8 months ago

When I set the language to plaintext, it loses formatting and copy-paste'ability regarding empty lines. For example,

```plaintext
Hello

World

becomes
Hello
World


(Same thing happens when I set `defaultLang: "plaintext"`)

---

@atomiks I'd like to sponsor you if you're open to it. Appreciate the hard work you put into this package!
atomiks commented 8 months ago

Yeah this is due to the display: grid option.

That's what this part fixes, which you saw in the other issue:

onVisitLine(node: { children: string | any[] }) {
  // Prevent lines from collapsing in `display: grid` mode, and allow empty
  // lines to be copy/pasted
  if (node.children.length === 0) {
    node.children = [{ type: "text", value: " " }]
  }
},

This is done internally for the grid: true option, but I think it's skipped for plaintext language, since it returns early to avoid highlighting...


btw, thank you for the offer, but I don't have a GitHub Sponsor page set up

ben519 commented 8 months ago

Thanks for the quick patch! If you set up a sponsor page, let me know.