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

HTML blocks inside table cells not treated as blocks #10

Closed
matteson opened this issue Mar 1, 2021 · 3 comments
Closed

HTML blocks inside table cells not treated as blocks #10

matteson opened this issue Mar 1, 2021 · 3 comments
Labels
🤷 no/invalid This cannot be acted upon

Comments

@matteson
Copy link

matteson commented Mar 1, 2021

HTML inside table cells is not parsed as expected.

In the minimum example below, I expect to have this node:

    {
      type: 'html',
      value: '<div>Test<i>foo</i></div>',
      position: ...
    }

as a child of a tableCell node. Instead, I get:

{
  type: 'tableCell',
  children: [
    { type: 'html', value: '<div>', position: [Object] },
    { type: 'text', value: 'Test', position: [Object] },
    { type: 'html', value: '<i>', position: [Object] },
    { type: 'text', value: 'foo', position: [Object] },
    { type: 'html', value: '</i>', position: [Object] },
    { type: 'html', value: '</div>', position: [Object] }
  ],
  position: ...
}

Minimal example:

var unified = require('unified')
var remarkParse = require('remark-parse')
var remarkGfm = require('remark-gfm')

var processor = unified()
    .use(remarkParse)
    .use(remarkGfm)


const text = '\nParameter | Default \n --------- | ------- \n  <div>Test<i>foo</i></div> | value \n';

const root = processor.parse(text);

function descend(tree) {
    console.log(tree);
    if (tree.children) {
        tree.children.map(item => descend(item));
    }
}

descend(root)

Your environment

  • OS: Mac
  • Packages:
    "remark-parse": "^9.0.0"
    "remark-gfm": "^1.0.0"
  • Env: node 14
@matteson matteson added 🐛 type/bug This is a problem 🙉 open/needs-info This needs some more info labels Mar 1, 2021
@wooorm
Copy link
Member

wooorm commented Mar 1, 2021

This is an https://xyproblem.info. What is your actual Q?

There are no blocks in table cells. Table cells include stuff like emphasis and such, not blocks like blockquotes

@ChristianMurphy ChristianMurphy added 🧘 status/waiting and removed 🐛 type/bug This is a problem 🙉 open/needs-info This needs some more info labels Mar 1, 2021
@matteson
Copy link
Author

matteson commented Mar 1, 2021

I may be using some terminology wrong then. I'm trying to put HTML in a table cell.

The markdown implements a table. One cell contains an html string. I'm expecting it to come back as an html node, with the same structure as if I parsed it outside of a table cell. Instead, it comes back with a different structure, as described in the example.

@wooorm
Copy link
Member

wooorm commented Mar 2, 2021

This is how HTML works in “inline” parsing of HTML. Take this for example: https://spec.commonmark.org/dingus/?text=a%20%3Cdiv%3E*b*%3C%2Fdiv%3E. The markdown between the tags works because the tags are separate.

If you want to work with HTML, there’s rehype for that:

unified()
  .use(remarkParse)
  .use(remarkGfm)
  .use(remarkRehype, {allowDangerousHtml: true})
  .use(rehypeRaw)
  .use(/* now you have an HTML AST! */)

@wooorm wooorm closed this as completed Apr 11, 2021
@wooorm wooorm added 🤷 no/invalid This cannot be acted upon and removed 🧘 status/waiting labels Apr 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤷 no/invalid This cannot be acted upon
Development

No branches or pull requests

3 participants