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

Remark plugin is un-escaping content #1245

Closed
4 tasks done
lopenchi opened this issue Oct 18, 2023 · 4 comments
Closed
4 tasks done

Remark plugin is un-escaping content #1245

lopenchi opened this issue Oct 18, 2023 · 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

@lopenchi
Copy link

lopenchi commented Oct 18, 2023

Initial checklist

Affected packages and versions

^12.0.0

Link to runnable example

Code Sandbox

Steps to reproduce

Reproducible example

import {remark} from 'remark'

const sourceMarkdown = "\{\{var\_name}}"


try {
  document.querySelector('#source')!.textContent = sourceMarkdown

  const file = await remark()
    // .use remark plugins here
    .process(sourceMarkdown)

  document.querySelector('#result')!.textContent = String(file)
  document.querySelector('#error')!.textContent = ''
} catch (error) {
  document.querySelector('#error')!.textContent = String(error)
}

Result removes the scape character for curly braces {, only maintain the one for underscore _.

It causes error in the mdx file

Expected behavior

Do not remove the scape character for curly braces

Actual behavior

Result removes the scape character for curly braces {, only maintain the one for underscore _.

It causes error in the mdx file

Runtime

Node v17

Package manager

npm 8

OS

macOS

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 Oct 18, 2023
@wooorm
Copy link
Member

wooorm commented Oct 18, 2023

Hey! Yes. It’s useless. That’s intended.

We don’t track which things were originally escaped or not. So we can’t do that.

@wooorm wooorm closed this as completed Oct 18, 2023
@wooorm wooorm added the 🙅 no/wontfix This is not (enough of) an issue for this project label Oct 18, 2023
@github-actions

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 Oct 18, 2023
@ChristianMurphy
Copy link
Member

Welcome @lopenchi! 👋
Sorry you ran into some confusion.

This behavior is intentional.
remark is a parser and formatter for CommonMark.
The escapes you add for MDX are not required nor recommended in CommonMark.

If you want to parse and format the MDX language, you can add support though remark-mdx (https://github.com/mdx-js/mdx/tree/main/packages/remark-mdx)

@matthias-ccri
Copy link

console.log('\{\{var\_name}}')
// > {{var_name}}

You didn't actually create a string containing backslashes.

In JavaScript strings, the \ character is treated as an escape character. In order to add a backslash to the string, you have to double up, like this:

console.log('\\{\\{var\\_name}}')
// > \{\{var\_name}}

Consider using eslint with the no-useless-escape rule.

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

4 participants