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

control character and puntuation cause extra emphasis to appear #92

Open
4 tasks done
ChristianMurphy opened this issue Sep 25, 2021 · 3 comments
Open
4 tasks done
Labels
🤞 phase/open Post is being triaged manually

Comments

@ChristianMurphy
Copy link
Member

Initial checklist

Affected packages and versions

3.0.5

Link to runnable example

https://stackblitz.com/edit/node-njevp4?file=index.js

Steps to reproduce

import { micromark } from 'micromark';
import { Parser, HtmlRenderer } from 'commonmark';
import rehypeParse from 'rehype-parse';
import { unified } from 'unified';
import { visit } from 'unist-util-visit';
import lodash from 'lodash';

const reader = new Parser();
const writer = new HtmlRenderer();
function scrubber(tree) {
  visit(tree, function (node) {
    node.data = undefined;
    node.value = undefined;
    node.position = undefined;
  });

  return tree;
}

const commonmark = (buf) => writer.render(reader.parse(buf));

const content = `example*�.*example example**`;

const micromarkHtml = micromark(content, {
  allowDangerousHtml: true,
  allowDangerousProtocol: true,
}).trim();
const commonmarkHtml = commonmark(content).trim();

const micromarkHtmlAst = scrubber(
  unified().use(rehypeParse, { fragment: true }).parse(micromarkHtml)
);
const commonmarkHtmlAst = scrubber(
  unified().use(rehypeParse, { fragment: true }).parse(commonmarkHtml)
);

console.log('micromark');
console.log(micromarkHtml);
console.log('');
console.log(JSON.stringify(micromarkHtmlAst, null, 4));
console.log('');
console.log('commonmark');
console.log(commonmark(content));
console.log('');
console.log(JSON.stringify(commonmarkHtmlAst, null, 2));
console.log(lodash.isEqual(micromarkHtmlAst, commonmarkHtmlAst));

Expected behavior

single emphasis in the document

<p>example*�.<em>example example</em>*</p>

with the HTML structure

{
  "type": "root",
  "children": [
    {
      "type": "element",
      "tagName": "p",
      "properties": {},
      "children": [
        {
          "type": "text"
        },
        {
          "type": "element",
          "tagName": "em",
          "properties": {},
          "children": [
            {
              "type": "text"
            }
          ]
        },
        {
          "type": "text"
        }
      ]
    }
  ]
}

Actual behavior

extra emphasis is added

<p>example<em>�.<em>example example</em></em></p>

changing the structure

{
    "type": "root",
    "children": [
        {
            "type": "element",
            "tagName": "p",
            "properties": {},
            "children": [
                {
                    "type": "text"
                },
                {
                    "type": "element",
                    "tagName": "em",
                    "properties": {},
                    "children": [
                        {
                            "type": "text"
                        },
                        {
                            "type": "element",
                            "tagName": "em",
                            "properties": {},
                            "children": [
                                {
                                    "type": "text"
                                }
                            ]
                        }
                    ]
                }
            ]
        }
    ]
}

Runtime

Node v16

Package manager

npm v7

OS

Linux

Build and bundle tools

No response

@github-actions github-actions bot added 👋 phase/new Post is being triaged automatically 🤞 phase/open Post is being triaged manually and removed 👋 phase/new Post is being triaged automatically labels Sep 25, 2021
@ChristianMurphy ChristianMurphy changed the title control character and space cause extra emphasis to appear control character and puntuation cause extra emphasis to appear Sep 25, 2021
@ChristianMurphy
Copy link
Member Author

other example with same issue

example*�+*example example**
example*�.*example example**

@ChristianMurphy
Copy link
Member Author

possibly related to syntax-tree/mdast-util-from-markdown#15

@ChristianMurphy
Copy link
Member Author

Also potentially related to #91 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤞 phase/open Post is being triaged manually
Development

No branches or pull requests

1 participant