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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug]: The rehype-jargon plugin seems unable to handle nested elements inside em elements gracefully #6471

Open
jlvandenhout opened this issue Mar 28, 2024 · 4 comments 路 May be fixed by #6778
Labels
馃悰 bug Something isn't working 馃摝 rehype-jargon

Comments

@jlvandenhout
Copy link

jlvandenhout commented Mar 28, 2024

What seems to be the problem? 馃

The rehype-jargon plugin seems unable to handle nested elements inside em elements gracefully. For example, our website has an element like this: <em><strong>Deprecated</strong></em>. The following line then tries to get the value of the em element, which isn't there I guess, because there is a nested strong
element:

Object.keys(options.jargon).indexOf(node.children[0].value.toLowerCase()) !== -1

This results in the following error:

Module build failed (from ./node_modules/@docusaurus/mdx-loader/lib/index.js):
Error: MDX compilation failed for file "/home/develop/repositories/iota-wiki/docs/build/identity.rs/1.1/docs/references/api/wasm.md"
Cause: Cannot read properties of undefined (reading 'toLowerCase')
Details:
TypeError: Cannot read properties of undefined (reading 'toLowerCase')
    at e (/home/develop/repositories/iota-wiki/node_modules/rehype-jargon/dist/index.mjs:12:334)
    at n (/home/develop/repositories/iota-wiki/node_modules/rehype-jargon/dist/index.mjs:12:372)
    at overload (/home/develop/repositories/iota-wiki/node_modules/unist-util-visit/lib/index.js:475:155)
    at node (element<em>) (/home/develop/repositories/iota-wiki/node_modules/unist-util-visit-parents/lib/index.js:471:27)
    at node (element<p>) (/home/develop/repositories/iota-wiki/node_modules/unist-util-visit-parents/lib/index.js:471:496)
    at node (root) (/home/develop/repositories/iota-wiki/node_modules/unist-util-visit-parents/lib/index.js:471:496)
    at visitParents (/home/develop/repositories/iota-wiki/node_modules/unist-util-visit-parents/lib/index.js:464:121)
    at visit (/home/develop/repositories/iota-wiki/node_modules/unist-util-visit/lib/index.js:472:96)
    at /home/develop/repositories/iota-wiki/node_modules/rehype-jargon/dist/index.mjs:12:584
    at wrapped (file:///home/develop/repositories/iota-wiki/node_modules/trough/lib/index.js:160:27)
    at next (file:///home/develop/repositories/iota-wiki/node_modules/trough/lib/index.js:86:23)
    at done (file:///home/develop/repositories/iota-wiki/node_modules/trough/lib/index.js:194:7)
    at then (file:///home/develop/repositories/iota-wiki/node_modules/trough/lib/index.js:204:5)
    at wrapped (file:///home/develop/repositories/iota-wiki/node_modules/trough/lib/index.js:181:9)
    at next (file:///home/develop/repositories/iota-wiki/node_modules/trough/lib/index.js:86:23)
    at done (file:///home/develop/repositories/iota-wiki/node_modules/trough/lib/index.js:194:7)
    at then (file:///home/develop/repositories/iota-wiki/node_modules/trough/lib/index.js:204:5)
    at wrapped (file:///home/develop/repositories/iota-wiki/node_modules/trough/lib/index.js:181:9)
    at next (file:///home/develop/repositories/iota-wiki/node_modules/trough/lib/index.js:86:23)
    at done (file:///home/develop/repositories/iota-wiki/node_modules/trough/lib/index.js:194:7)
    at then (file:///home/develop/repositories/iota-wiki/node_modules/trough/lib/index.js:204:5)
    at wrapped (file:///home/develop/repositories/iota-wiki/node_modules/trough/lib/index.js:181:9)
    at next (file:///home/develop/repositories/iota-wiki/node_modules/trough/lib/index.js:86:23)
    at done (file:///home/develop/repositories/iota-wiki/node_modules/trough/lib/index.js:194:7)
    at then (file:///home/develop/repositories/iota-wiki/node_modules/trough/lib/index.js:204:5)
    at Object.mdxLoader (/home/develop/repositories/iota-wiki/node_modules/@docusaurus/mdx-loader/lib/loader.js:130:25)

Design / Plugin / Package 馃

packages/rehype-jargon

Additional context

No response

@jlvandenhout jlvandenhout added the 馃悰 bug Something isn't working label Mar 28, 2024
Copy link

boring-cyborg bot commented Mar 28, 2024

Thanks for opening your first issue here at FreeSewing 馃
One of our contributors should triage this soon so that it gets some attention. If it's urgent, you can join us on Discord where we tend to hang out.

@jlvandenhout
Copy link
Author

I'm happy to open a PR to resolve this, but I guess there is a choice to be made: either disregard em elements that contain nested elements or traverse down to the text node, regardless of nested elements.

@joostdecock
Copy link
Member

Thanks for reporting this @jlvandenhout

I guess there is a choice to be made: either disregard em elements that contain nested elements or traverse down to the text node, regardless of nested elements.

I am leaning towards the conservative approach to ignore em tags that contain nested elements.
If you really wanted to bold a term, you could always inverse the tag order:

<strong><em>Deprecated</em></strong>

If you're up for submitting a PR to implement that, it would be much appreciated 馃檹

@jlvandenhout
Copy link
Author

Sure! I'll give it a shot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
馃悰 bug Something isn't working 馃摝 rehype-jargon
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants