Disabling Markdown Superscript Syntax to Prevent Conflicts with LaTeX Formulas in Ghost

I am currently using MathJax to render LaTeX formulas in my posts. However, I noticed that the superscript symbol ^ in LaTeX formulas overlaps with the Markdown syntax for superscripts. As a result, the editor interprets the content between two ^ symbols as Markdown superscript, which breaks the LaTeX formula and causes rendering to fail.

This issue can be resolved by using an HTML block, but it becomes inconvenient for inline formulas. My idea is to disable the Markdown superscript syntax (i.e., ^text^) in the Ghost editor. How can I achieve this?
image

I don’t think it’s possible without hacking the core.

Here’s the source of the markdown renderer:

And here’s the commit that added sub/sup support:

Thank you so much for your guidance—it worked perfectly! :raised_hands:

Here’s how I solved the issue:

  1. Markdown Card Superscript/Subscript Syntax:
    I removed the lines related to superscript/subscript syntax in markdown-html-renderer.js and package.json in the foler kg-markdown-html-renderer. This disables the superscript and subscript functionality in the markdown card.
  2. Editor Superscript/Subscript Syntax:
    To disable this feature in the editor, I modified the file packages/koenig-lexical/src/plugins/MarkdownShortcutPlugin.jsx. The default syntax uses ^ for superscript and ~ for subscript, so instead of deleting these lines, I replaced them with different symbols to avoid conflicts.

Since I’m using a Docker deployment of Ghost, the process was a bit different. The code structure vary slightly in Docker, so here’s where I found the relevant files:

  • For the editor syntax: koenig-lexical.js and koenig-lexical-umd.js
  • For the markdown card: markdown-html-renderer.js, kg-markdown-html-renderer/package.json, markdown-it-sub.js, markdown-it-sup.js, markdown-it-sub.min.js, and markdown-it-sup.min.js.

Thanks again for your help! :blush:

1 Like