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

querySelectorAll does not work as expected #259

Open
PacoVK opened this issue Dec 1, 2023 · 1 comment
Open

querySelectorAll does not work as expected #259

PacoVK opened this issue Dec 1, 2023 · 1 comment

Comments

@PacoVK
Copy link

PacoVK commented Dec 1, 2023

Description

Given the input

<div class="sect2">
    <ul>
        <li>
            <p>Update </p>
            <ul>
                <li>
                    <p>login with credentials</p></li>
                <li>
                    <p>do something</p>
                    <p>
                    <div class="content">
                   <pre class="highlightjs highlight">
                       <code class="language-bash hljs" data-lang="bash">systemctl stop service
            systemctl start service</code>
                   </pre>
                    </div></p></li>
            </ul></li>
    </ul>
</div>

when i call

const content = parse(inputGivenAbove)
const codeElements = content.querySelectorAll('pre > code') 

I would expect

codeElements.length === 1

actually it is

codeElements.length === 0

Context

Node 21.2.0

"devDependencies": {
    "@jest/globals": "^29.7.0",
    "@types/node": "^20.10.0",
    "jest": "^29.7.0",
    "ts-jest": "^29.1.1",
    "ts-node": "^10.9.1",
    "typescript": "^5.3.2"
  },
  "dependencies": {
    "node-html-parser": "^6.1.11"
  }
@PacoVK
Copy link
Author

PacoVK commented Dec 1, 2023

Seems like the parse needs further configuration here. After using

const content = parse(inputGivenAbove, {blockTextElements: {code: true}})
const codeElements = content.querySelectorAll('pre > code') 

the output is now as expected

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