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

How to "re" parse AST to markdown? #248

Closed
icefery opened this issue Oct 16, 2021 · 1 comment
Closed

How to "re" parse AST to markdown? #248

icefery opened this issue Oct 16, 2021 · 1 comment

Comments

@icefery
Copy link

icefery commented Oct 16, 2021

Question

How to "re" parse AST to markdown?

I'm sorry that I am not very good at English, to find some helpful information from issues seems to be difficult for me.

Context

I want to for-each all the image node and migrate images to a new path, which means steps as follow:

  1. Parse markdown to AST
  2. Change AST
  3. Parse AST to markdown
import { Parser } from 'commonmark'

const md = `![](./image/1.jpg)`
const walker = parser.parse(md).walker()

let event = null
while ((event = walker.next())) {
  if (event.entering && event.node.type === 'image') {
    // move
    const filepath = mv(event.node.destination)
    // change
    event.node.destination = filepath
  }
}

// TODO: How to "re" parse AST to markdown?
@jgm
Copy link
Member

jgm commented Oct 17, 2021

See #83 (open issue).

@jgm jgm closed this as completed Oct 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants