halo icon indicating copy to clipboard operation
halo copied to clipboard

Support conversion between default editor and Markdown

Open xinkeng0 opened this issue 1 year ago • 3 comments

Your current Halo version

main

Describe this feature

We can add this feature to the core code of the default editor,plugins can implement their own parse function in addOptions().#5157 Perhaps it could look something like this:

addOptions() {
  return {
    ...this.parent?.(),
    serializer(markdowSerializer: MarkdownSerializer ) {
        // Node
        markdowSerializer.nodes['custome-node'] = (state, node) => {
        state.write(node.attrs.content)
        // Mark
        markdowSerializer.mark['custome-mark'] = (state, node) => {
        state.write(node.attrs.content)
      }
    },
  };
}
  • https://github.com/ProseMirror/prosemirror-markdown

Additional information

/kind improvement

xinkeng0 avatar Jan 10 '24 06:01 xinkeng0

+1 for this feature even though it's not perfect.

JohnNiang avatar Jan 10 '24 07:01 JohnNiang

This approach would be dependent on the editor, and I am unable to envision a use case for it. If the goal is simply to export HTML to Markdown, there are already libraries available for that purpose, such as turndown. For tags that are not native HTML, we can export them as they are.

ruibaby avatar Jan 10 '24 07:01 ruibaby

For tags that are not native HTML, we can export them as they are.

Couldn't agree more, but I think there's an opportunity for us to do even better.

We can give some plugins a chance , that if they can be converted to Markdown.

For example, Katex can be represented as $x_y$in Markdown.

xinkeng0 avatar Jan 10 '24 07:01 xinkeng0