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

example print-rcdom parses <pre> contents #580

Closed
qknight opened this issue Mar 9, 2025 · 1 comment
Closed

example print-rcdom parses <pre> contents #580

qknight opened this issue Mar 9, 2025 · 1 comment

Comments

@qknight
Copy link

qknight commented Mar 9, 2025

The example print-rcdom shows that it parses the contents of the <pre>. In HTML it is usually only relevant for browsers using the given CSS for styling but not as a general concept.

My use-case is that I want to have arbitrary data in the <pre><code> section, even invalid html and I don't want any interpretation of it. See https://lastlog.de/blog/vscodium_and_nix_develop.html where I have bash output inside these boxes.

So my question is:

How to parse <pre> content as NodeData::Text instead of yet another bunch of HTML tags?

The example below shows that all the html code is actually parsed.

[nixos@nixos:~/html5ever/rcdom/examples]$ cargo run --example print-rcdom
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.04s
     Running `/home/nixos/html5ever/target/debug/examples/print-rcdom`
<div><p> test </p><pre><code>
<p>foo1</p>
  <p>foo2</p><p>foo3</p>
  3</code></pre></div>
#Document
    <html>
        <head>
        <body>
            <div>
                <p>
                    #text:  test 
                <pre>
                    <code>
                        #text: \n
                        <p>
                            #text: foo1
                        #text: \n  
                        <p>
                            #text: foo2
                        <p>
                            #text: foo3
                        #text: \n  3
            #text: \n

Parse errors:
    Unexpected token
@qknight
Copy link
Author

qknight commented Mar 13, 2025

The html5ever implementation for <pre> is alright and my problem was caused by the post-processing of the let dom = parse_document(RcDom::default(), opts).one(input); later on.

@qknight qknight closed this as completed Mar 13, 2025
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

1 participant