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

Block starting with HTML tag interpreted as one JSX component #611

Closed
danburzo opened this issue Jun 20, 2019 · 3 comments · Fixed by #1039
Closed

Block starting with HTML tag interpreted as one JSX component #611

danburzo opened this issue Jun 20, 2019 · 3 comments · Fixed by #1039
Labels
🗄 area/interface This affects the public interface 💪 phase/solved Post is done 🧑 semver/major This is a change 🦋 type/enhancement This is great to have

Comments

@danburzo
Copy link

Subject of the issue

I stumbled opon this bug recently: A block starting with a HTML tag, like in the example below, is interpreted as one JSX component.

<sup>1</sup> A footnote

Output from ASTExplorer (using mdxhast-0.20.2):

{
  "type": "root",
  "children": [
    {
      "type": "jsx",
      "value": "<sup>1</sup> A footnote",
      "position": {
        "start": {
          "line": 1,
          "column": 1,
          "offset": 0
        },
        "end": {
          "line": 1,
          "column": 24,
          "offset": 23
        },
        "indent": []
      }
    }
  ],
  "position": {
    "start": {
      "line": 1,
      "column": 1,
      "offset": 0
    },
    "end": {
      "line": 1,
      "column": 24,
      "offset": 23
    }
  }
}

Your environment

macOS Mojave. npm ls | grep "mdx":

├─┬ @mdx-js/[email protected]
│ ├─┬ @mdx-js/[email protected]
│ │ ├─┬ [email protected]
│ ├── @mdx-js/[email protected]
├── @next/[email protected]

Expected behaviour

A JSX element for the <sup> tag, followed by plain text.

Actual behaviour

Text becomes part of the JSX element.

@johno
Copy link
Member

johno commented Jul 15, 2019

This is a bit of a tricky one. Right now block-level JSX is defined as any line that begins with a tag.

One option is to detect for inline HTML elements and instead parse that as an inline JSX block (which is what remark core does). However, that wouldn't address React components since we can't detect whether they render inline or block level HTML elements. I'm not sure if the difference between inline HTML elements and JSX would be expected or not. 🤔🤔🤔

It's also interesting to note that remark does bundle up all block-level elements into a single node (which is what MDX parsing is currently doing for all tags).

Input Markdown
<h1>hi</h1> hi there
Output AST
{
  "type": "root",
  "children": [
    {
      "type": "html",
      "value": "<h1>hi</h1> hi there",
      "position": {
        "start": {
          "line": 1,
          "column": 1,
          "offset": 0
        },
        "end": {
          "line": 1,
          "column": 21,
          "offset": 20
        },
        "indent": []
      }
    }
  ],
  "position": {
    "start": {
      "line": 1,
      "column": 1,
      "offset": 0
    },
    "end": {
      "line": 1,
      "column": 21,
      "offset": 20
    }
  }
}

@wooorm
Copy link
Member

wooorm commented Apr 23, 2020

We’re working on rewriting the parser to solve amongst other things, this problem, in 2.0.0. Out relatively soon!

We’re updating block v. inline as: it’s a block if the opening tag is the first thing, and closing tag the last thing. In this case, theres a phrase after the closing (“a footnote”), so it will be seen as inline.

@wooorm
Copy link
Member

wooorm commented Dec 18, 2020

Hi all! I’m going to close this as it landed on the main, the (now default) branch we’re using to gear up to the MDX@2 release.

The reason is so that it’s more clear which issues still need to be solved already and don’t require further work.

Expect another next release soonish, which might include it, or maybe it’s already released as a beta!

For more info, see #1041.

@wooorm wooorm closed this as completed Dec 18, 2020
@wooorm wooorm added ⛵️ status/released 🗄 area/interface This affects the public interface 🦋 type/enhancement This is great to have 🧑 semver/major This is a change labels Dec 18, 2020
@wooorm wooorm added the 💪 phase/solved Post is done label Dec 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🗄 area/interface This affects the public interface 💪 phase/solved Post is done 🧑 semver/major This is a change 🦋 type/enhancement This is great to have
Development

Successfully merging a pull request may close this issue.

3 participants