Custom markdown format

Hello. Im fully aware of the current state of schema API, but can I get pointers on how to extending the markdown syntax for prosemirror?

I got that I need to make a markdown from/to converter, but I have trouble reading the from_markdown source.

Could someone give me pointers? Do I need to make a new fromMarkdown function and pass it to defineSource? Or make new tokens for my new syntax?

Thank you

The markdown parser and serializer aren’t extendable at all yet. I’m about to start working on integrating schemas with serialization and parsing, so if you check back in a week or so, the situation should be improved.

Ok thanks. We’re branching out from one of your previous commits to do customization.

Another suggestion, allow markdown rendering for styles to modify the content of the text. For example: I have Some content. When I apply our custom style to that text, I want to be able render something like [[!! id="42 content="Some content" !!]].

The current implementation doesnt allow this easily, because Some content is always at the start of the rendered markdown after open_style.

Thank you for the project!

I see there have been some changes in the schema area, but are we able to extend the markdown parser yet? (Looking at the source code it doesn’t look like it).

It would be nice to be able use some of the markdown-it extensions and write my own. Unless I’m doing something silly at the moment I can’t get custom schema to play nicely with the markdown docFormat. As soon as the editor is reloaded any custom MarkTypes are not recognised by markdown-it and are rendered as plain text.

A serializeMarkdown method can completely override the way a node is rendered. In your example, if you don’t allow further markup in the content, you should be able to use that. If you do, I guess you’ll also need to escape quotes, which the current API isn’t powerful enough to do yet.

It wasn’t possible to declare a way to load and configure the markdown parser, which indeed is going to be necessary to do something like this. I’ve added an interface for that in this patch, which you can use along with the existing interface for associating parser functions with markdown-it token types to do what you want. This hasn’t been used yet, so do tell me when you run into issues.

1 Like

@marijn wait… .did you just add that patch today? nice one! :+1:

I’ll have a look and let you know.

I get an error when the registered configureMarkdown function is called:

Citation.register('configureMarkdown', 'citation', parser => {
    console.log('configuration citation');
    return parser.use(markdownItCitation);

The stack trace:

Uncaught TypeError: Cannot read property 'length' of undefined
    sortedInsert @ sortedinsert.js?76a2:3
    (anonymous function) @ from_markdown.js?d0ac:215
    registry @ schema.js?3713:
    (anonymous function) @ from_markdown.js?d0ac:
    configFromSchema @ from_markdown.js?d0ac:
    configureMarkdown @ from_markdown.js?d0ac:
    fromMarkdown @ from_markdown.js?d0ac:
    parseFrom @ register.js?4acf:
    ProseMirror @ main.js?2848:
    componentWillMount @ index.js?149a:

The line that causes the exception is:

sortedInsert(found, {f, rank}, (a, b) => a.rank - b.rank)

Somehow in the sortedInsert function array.length is undefined, which is odd because it is checked a few lines earlier. If I comment out my configureMarkdown code it runs fine.

Am I doing something funky? Would you prefer me to raise a github issue?

EDIT actually looking at the patch again, the sortedInsert is only called when found is undefined or false - this means the array.length call in sortedInsert will always be an error.

@wilsk Yeah, there was a bug in my patch. Try with this one.

Ok great, that fixed the error - thanks!