defuddle icon indicating copy to clipboard operation
defuddle copied to clipboard

Multi-line code written as <p><code> with <br> collapses into one inline span

Open kazionovm opened this issue 3 weeks ago • 0 comments

Description

Some sites write multi-line code as a paragraph with <br> line breaks inside <code>, without a <pre>. Browsers render it as several lines, but Defuddle collapses it into a single inline code span and the line breaks are lost.

I hit this on the Webflow-based LangChain blog, for example In software, the code documents the app. In AI, the traces do (section "Why Code Doesn't Document Agent Behavior"). Obsidian Web Clipper uses Defuddle, so clips of such pages end up the same way.

Steps to reproduce

echo '<html><body><article><h1>Test</h1>
<p>Some text before the code so the article has enough content to be extracted.</p>
<p><code>agent = Agent(<br/>    model="gpt-4",<br/>    tools=[search_tool]<br/>)<br/>result = agent.run(user_query)<br/></code></p>
<p>Some text after the code block, long enough to look like a real paragraph.</p>
</article></body></html>' | npx defuddle parse --markdown

Actual result

`agent = Agent(       model="gpt-4",       tools=[search_tool]   )   result = agent.run(user_query)   `

Expected result

```
agent = Agent(
    model="gpt-4",
    tools=[search_tool]
)
result = agent.run(user_query)
```

Notes

  • Version: defuddle 0.19.6 (CLI).
  • Related: #24. That fix covers code blocks marked with white-space: pre, but not <br> line breaks inside <code>.
  • Workaround I use before parsing: turn a <p><code> that contains <br> into <pre><code>, replacing each <br> with \n.

kazionovm avatar Nov 12 '26 05:11 kazionovm