Replies: 2 comments
-
You can get current Markdown AST and use import { visit } from 'unist-util-visit'
import { directive } from 'micromark-extension-directive'
import {gfm} from 'micromark-extension-gfm'
import { directiveFromMarkdown, directiveToMarkdown } from 'mdast-util-directive'
import {gfmFromMarkdown, gfmToMarkdown} from 'mdast-util-gfm'
export const parseMarkdownToAST = (markdown: string) => {
const mdast = fromMarkdown(markdown, {
extensions: [directive(), gfm()],
mdastExtensions: [
directiveFromMarkdown(),
gfmFromMarkdown()
]
})
visit(mdast, 'image', (node: any, ...rest: any) => {
console.log(node) // all image nodes in the markdown content. Parent node and current node's index under its parent can get through rest props.
})
} |
Beta Was this translation helpful? Give feedback.
0 replies
-
And if you don't want import much more packages for getting abstract markdown tree, you can also use Milkdown // command use for traversal.
export const getAllNodes = $command('getAllNodes', (ctx) => (params?: any) => (state, dispatch) => {
state.doc.descendants(node => {
console.log(node.type, node.attrs)
})
return true;
}) Call customized command to get specified nodes, and add logic you want: import { callCommand } from '@milkdown/utils'
editorInstance.action((ctx) => {
return callCommand(getAllNodes.key)(ctx)
}) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Initial checklist
Problem
Clean up/removal of image.
Solution
Similar to how there is functionality to add an image. Would it be possible to have a clean up process? Or is there someway of accessing the URLs of all the image such that we can remove (delete from server) when an image is removed.
Alternatives
Unsure.
Beta Was this translation helpful? Give feedback.
All reactions