-
-
Notifications
You must be signed in to change notification settings - Fork 4
Parse weirdly if nested html elements (like a figure element in an anchor) are in one line #27
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
Comments
Hi! This has to do with markdown. Not with HTML, or this package. Here’s your input pasted on the CommonMark dingus: https://spec.commonmark.org/dingus/?text=%3Ca%20href%3D%22https%3A%2F%2Fexample.com%22%3E%3Cfigure%3E%3Cimg%20src%3D%22image.png%22%20alt%3D%22%22%3E%3C%2Ffigure%3E%3C%2Fa%3E%0A%0A%3Ca%20href%3D%22https%3A%2F%2Fexample.com%22%3E%0A%3Cfigure%3E%3Cimg%20src%3D%22image.png%22%20alt%3D%22%22%3E%3C%2Ffigure%3E%0A%3C%2Fa%3E. You should be able to see the same here on GH too. |
This comment has been minimized.
This comment has been minimized.
When I go to dingus, I see the input pasted; then, when I click the <p><a href="https://example.com"><figure><img src="image.png" alt=""></figure></a></p> It is expected output as should be (not weird one). Am I doing wrong? or am I right about the issue? |
It’s about the |
Perhaps I am unclear what you mean. Can you maybe make your input/actual/expected examples smaller? |
It is not about const unified = require('unified');
const remarkParse = require('remark-parse');
const remarkRehype = require('remark-rehype');
const rehypeRaw = require('rehype-raw');
const rehypeStringify = require('rehype-stringify');
const html = unified()
.use(remarkParse)
.use(remarkRehype, { allowDangerousHtml: true })
.use(rehypeRaw)
.use(rehypeStringify)
.processSync(input); input markdown (in one line, outer <a href="https://example.com"><figure><img src="image.png" alt=""></figure></a> actual output (weird, empty anchor within <p><a href="https://example.com"></a></p><figure><a href="https://example.com"><img src="image.png" alt=""></a></figure><p></p> expected output (I saw the expected output in dingus <p><a href="https://example.com"><figure><img src="image.png" alt=""></figure></a></p> On the other hand, I changed the order of nesting elements to see the behavior: input markdown (in one line, outer <figure><a href="https://example.com"><img src="image.png" alt=""></a></figure> actual output (not weird, it is expected, and no problem !): <figure><a href="https://example.com"><img src="image.png" alt=""></a></figure> I stress that the two inputs are in one line, just changed the order of nesting. |
Thanks for providing more info! I made your example smaller: /**
* @import {Root} from 'hast'
*/
import {raw} from 'hast-util-raw'
/** @type {Root} */
const tree = {
type: 'root',
children: [
{
type: 'element',
tagName: 'p',
properties: {},
children: [
{type: 'raw', value: '<a>'},
{type: 'raw', value: '<figure>'},
{type: 'raw', value: '</figure>'},
{type: 'raw', value: '</a>'}
]
}
]
}
const reformatted = raw(tree)
console.dir(reformatted, {depth: null}) Yields: {
type: 'root',
children: [
{
type: 'element',
tagName: 'p',
properties: {},
children: [
{ type: 'element', tagName: 'a', properties: {}, children: [] }
]
},
{
type: 'element',
tagName: 'figure',
properties: {},
children: []
},
{ type: 'element', tagName: 'p', properties: {}, children: [] }
],
data: { quirksMode: false }
} Perhaps this smaller example will make it more visible: the “problem” is that there is a You can see the same behavior in a browser by pasting this in an empty new tab: |
Initial checklist
Affected package
hast-util-raw
Steps to reproduce
Here is a markdown input containing simple nested html elements are in one line:
Actual behavior
If the html elements are in one line, it produces weird anchor behavior and empty paragraph at the end:
But if the input is like:
it behaves normal and produces the expected result.
Expected behavior
I expect it can handle this kind of simple nested html input in one line and the result to be:
I mean
hast-util-raw
should handle nested html elements even if they are in one line.Runtime
node
Package manager
npm
Operating system
macos
Build and bundle tools
No response
The text was updated successfully, but these errors were encountered: