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

Backslash prepended to the input [ #28

Closed
4 tasks done
srmagura opened this issue Oct 25, 2022 · 3 comments
Closed
4 tasks done

Backslash prepended to the input [ #28

srmagura opened this issue Oct 25, 2022 · 3 comments
Labels
🙋 no/question This does not need any changes 👎 phase/no Post cannot or will not be acted on

Comments

@srmagura
Copy link

Initial checklist

Affected packages and versions

remark@14.0.2, strip-markdown@5.0.0

Link to runnable example

No response

Steps to reproduce

  1. Go to the playground: http://remarkjs.github.io/strip-markdown/
  2. Enter [

Expected behavior

The output is [.

Actual behavior

The output is \[.

I am not sure if this is intentional escaping or a bug.

I have a string of Markdown, and I want to convert it to plain text. With the current behavior, I will end up displaying backslashes that were not in the original text.

Runtime

Node v16

Package manager

yarn 2

OS

macOS

Build and bundle tools

Other (please specify in steps to reproduce)

@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 25, 2022
@ChristianMurphy
Copy link
Member

The escaping is intentional.
Some more context on a recent question asking the same thing: https://github.com/orgs/syntax-tree/discussions/87

Repeating some of that here:

Taking a step back, remark is an AST ecosystem.
Meaning it will preserve the structure/presentation of the content, but will not retain the exact characters.
You can read more about this is some previous discussions on AST vs CST.
https://github.com/remarkjs/remark/search?q=cst&type=issues and https://github.com/orgs/remarkjs/discussions?discussions_q=cst

In this case the escaped output is fine, it doesn't matter if it is escaped, the final presentation will be the same.

Adding on some additional context, if you are looking for full plain text rather than stripped down markdown text.
Consider using https://github.com/syntax-tree/mdast-util-to-string rather than remark-stringify to generate plain text rather than markdown text.

@ChristianMurphy ChristianMurphy closed this as not planned Won't fix, can't repro, duplicate, stale Oct 25, 2022
@ChristianMurphy ChristianMurphy added the 🙋 no/question This does not need any changes label Oct 25, 2022
@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 25, 2022
@srmagura
Copy link
Author

Thanks @ChristianMurphy! mdast-util-to-string is doing exactly what I needed:

const tree = fromMarkdown(markdown);
return toString(tree);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🙋 no/question This does not need any changes 👎 phase/no Post cannot or will not be acted on
Development

No branches or pull requests

2 participants