fabianmichael / kirby-markdown-field

Super-sophisticated markdown editor for Kirby 3, community built.
Other
160 stars 14 forks source link

Re-use `toggleInlineFormat()` inside of inline extension? #186

Closed tobimori closed 6 months ago

tobimori commented 7 months ago

Doing something like this, similiar to how it is in the core, doesn't work:

    get command() {
      return () => this.editor.toggleInlineFormat('^')
    },
fabianmichael commented 6 months ago

This is a bit more complicated, since toggleInlineFormat() accepts a token name as parameter instead of the delimiter. The token itself has to be part of the language definition for this to work properly, since a lot of magic happens behind the scenes for this to work with more complex situations like nested formats. So I am afraid this won’t be possible by now. But if you got an important use case, please share it with me and we could consider to add an extension point for that.

https://github.com/fabianmichael/kirby-markdown-field/blob/d7fb8e4e53f31cbd6595638d3c3e972034ec8aad/src/components/Extensions/KirbytextLanguage.js#L245-L254

https://github.com/fabianmichael/kirby-markdown-field/blob/d7fb8e4e53f31cbd6595638d3c3e972034ec8aad/src/components/Extensions/KirbytextLanguage.js#L82-L105

https://github.com/fabianmichael/kirby-markdown-field/blob/7b482a5a8002ea182356d4b4ad51ffa6eddd69f9/src/components/Utils/markup.js

tobimori commented 6 months ago

I simply want to build an extension for a custom mark. The examples only show how to insert/replace text but not how to replicate the behavior from the built-in Marks.

fabianmichael commented 6 months ago

A simple highlight extension just runs a regex on the editor content and adds a span round text, where it matches. But toggling inline formats really requires extending the language definition and requires the editor to be able to recognize the highlight as a language feature, so toggling cannot work without that. There’s a reason why src/components/Utils/markup.js is such a monster. But what exactly do you want to add to the editor? If it would be of interest for other users, I’d be happy to integrate it into the core language definition.

tobimori commented 6 months ago

It's pretty specific to the design, a mark for smaller text size, but one could probably use subscript for that.

fabianmichael commented 6 months ago

@tobimori Okay, since this is not a generat use case and providing an extension point for additional inline formats would add a lot of complexity, so I close this as I don’t have the capacity for implementing this.