You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
collapse-whitespace behaves perfectly for block PRE elements, such as the default <PRE> tag.
But there are use cases where users need preformatted behavior on inline elements. For example, GitLab's CSS for the <code> tag is set as white-space: pre-wrap;. The browser behavior is then as follows, but collapse-whitespace is not consistent with that.
<divclass="test"><code>four spaces</code></div><divclass="result"><code>four spaces</code></div><divclass="test">Space <code>no space</code> more space</div><divclass="result">Space <code>no space</code> more space</div><divclass="test">Space <code> leading code space</code> more space</div><divclass="result">Space <code> leading code space</code> more space</div><divclass="test">Space <code>trailing code space </code> more space</div><divclass="result">Space <code>trailing code space </code> more space</div><divclass="test">Space <code>trailing code space </code><b> more space in tag</b></div><divclass="result">Space <code>trailing code space </code><b> more space in tag</b></div><divclass="test">Space <code>trailing code space </code><b> more space after code and tag</b></div><divclass="result">Space <code>trailing code space </code><b>more space after code and tag</b></div><divclass="test"><b>Space before tag </b><code>my code</code></div><divclass="result"><b>Space before tag </b><code>my code</code></div><divclass="test"><b>Space before tag and code </b><code>my code</code></div><divclass="result"><b>Space before tag and code </b><code>my code</code></div>
Code copied to clipboard from highlightJs rendered blocks (example on their website: https://highlightjs.org/, explore raw clipboard html content by pasting to https://evercoder.github.io/clipboard-inspector/ ) is HTML sequence of only tags with heavy styling. There are no div's at all, and line breaks rely on white-space: pre; classes.
Turndown conversion to markdown returns single-line, and does not have line breaks, let alone whitespace indentation. This is NOT currently controlled by the "preformattedCode" option which links to this issue from README.md. Therefore this issue remains unresolved.
Use-Case: a Chat UI applications that wants to allow clipboard pasting rich content into the message box. Since we need to send a plain text or markdown to the LLMs, we are trying to use turndown for "best effort" content conversion to markdown at pasting time. So that the user could see how this content will look like to LLM, edit, etc. Primarily so that that chaptered, bullet-point, tabular content pasted from Gmail, Word, Google Docs, Notion, Slack etc preserved at least some structure.
Impact: code copied&pasted from websites or web apps, and AI chatbots (and our own app) that happen to use highlightJs to format code, is losing both newlines and indentation.
Activity
Add support for inline pre elements. Fix lucthev#16.
Add support for preformatted code, also submitted to lucthev/collapse…
Add support for preformatted code, also submitted to lucthev/collapse…
DmitriyAlergant commentedon Dec 20, 2025
Code copied to clipboard from highlightJs rendered blocks (example on their website: https://highlightjs.org/, explore raw clipboard html content by pasting to https://evercoder.github.io/clipboard-inspector/ ) is HTML sequence of only tags with heavy styling. There are no div's at all, and line breaks rely on white-space: pre; classes.
Turndown conversion to markdown returns single-line, and does not have line breaks, let alone whitespace indentation. This is NOT currently controlled by the "preformattedCode" option which links to this issue from README.md. Therefore this issue remains unresolved.
Use-Case: a Chat UI applications that wants to allow clipboard pasting rich content into the message box. Since we need to send a plain text or markdown to the LLMs, we are trying to use turndown for "best effort" content conversion to markdown at pasting time. So that the user could see how this content will look like to LLM, edit, etc. Primarily so that that chaptered, bullet-point, tabular content pasted from Gmail, Word, Google Docs, Notion, Slack etc preserved at least some structure.
Impact: code copied&pasted from websites or web apps, and AI chatbots (and our own app) that happen to use highlightJs to format code, is losing both newlines and indentation.