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

"$20,000 and $30,000" should’t parse as math (if remark-math and micromark-extension-math follows Pandoc as remark-math 3.0 did) #6

Closed
4 tasks done
seiyab opened this issue Feb 12, 2024 · 4 comments
Labels
🙅 no/wontfix This is not (enough of) an issue for this project 👎 phase/no Post cannot or will not be acted on

Comments

@seiyab
Copy link

seiyab commented Feb 12, 2024

Older remark-math handled it same as pandoc: remarkjs/remark-math#35. I consider this a regression.

Initial checklist

Affected packages and versions

remark-math 6.0.0

Link to runnable example

Codesandbox

Steps to reproduce

Codesandbox

import remarkParse from "remark-parse";
import { unified } from "unified";
import remarkMath from "remark-math";

const sourceMarkdown = `$20,000 and $30,000`;

document.getElementById("source").textContent = sourceMarkdown;

const processor = unified().use(remarkParse).use(remarkMath);

processor
  .run(processor.parse(sourceMarkdown))
  .then((file) => {
    document.getElementById("result").textContent = JSON.stringify(
      file,
      null,
      2
    );
  })
  .catch((err) => (document.getElementById("error").textContent = err));

Expected behavior

It shouldn't parse as math.

Actual behavior

parses as inline math.

{
  "type": "root",
  "children": [
    {
      "type": "paragraph",
      "children": [
        {
          "type": "inlineMath",
          "value": "20,000 and ",
          "data": {
            "hName": "code",
            "hProperties": {
              "className": [
                "language-math",
                "math-inline"
              ]
            },
            "hChildren": [
              {
                "type": "text",
                "value": "20,000 and "
              }
            ]
          },
          "position": {
            "start": {
              "line": 1,
              "column": 1,
              "offset": 0
            },
            "end": {
              "line": 1,
              "column": 14,
              "offset": 13
            }
          }
        },
        {
          "type": "text",
          "value": "30,000",
          "position": {
            "start": {
              "line": 1,
              "column": 14,
              "offset": 13
            },
            "end": {
              "line": 1,
              "column": 20,
              "offset": 19
            }
          }
        }
      ],
      "position": {
        "start": {
          "line": 1,
          "column": 1,
          "offset": 0
        },
        "end": {
          "line": 1,
          "column": 20,
          "offset": 19
        }
      }
    }
  ],
  "position": {
    "start": {
      "line": 1,
      "column": 1,
      "offset": 0
    },
    "end": {
      "line": 1,
      "column": 20,
      "offset": 19
    }
  }
}

Runtime

No response

Package manager

No response

OS

No response

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 Feb 12, 2024
@wooorm
Copy link
Member

wooorm commented Feb 12, 2024

Hi

The behavior is intended. Pandoc is not a reference. How code works in CommonMark is a reference.

`20,000 and `30,000

20,000 and 30,000

You can escape dollars and backticks in markdown if you want:

\`20,000 and `30,000

`20,000 and `30,000

You can also turn off singleDollarTextMath in this extension. This is what I would recommend to everyone. With that, math is unlikely to interfere with regular text. That is also how I implemented syntax highlighting, which is used in places where math may or may not work, such as right here:

$math?$

$$math?$$

@wooorm wooorm closed this as not planned Won't fix, can't repro, duplicate, stale Feb 12, 2024
@wooorm wooorm added the 🙅 no/wontfix This is not (enough of) an issue for this project label Feb 12, 2024

This comment has been minimized.

@github-actions github-actions bot added 👎 phase/no Post cannot or will not be acted on and removed 🤞 phase/open Post is being triaged manually labels Feb 12, 2024
@wooorm
Copy link
Member

wooorm commented Feb 12, 2024

The PR you reference also says what I say now. Pandoc is not a reference. remarkjs/remark-math#35

@seiyab
Copy link
Author

seiyab commented Feb 13, 2024

Thank you for your response. I understand. I'm working on Prettier and will suggest turning off singleDollarTextMath with breaking change or having our own tokenizer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🙅 no/wontfix This is not (enough of) an issue for this project 👎 phase/no Post cannot or will not be acted on
Development

No branches or pull requests

2 participants