Skip to content

Commit

Permalink
[#69556] support colon fenced blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
Trzcin committed Nov 29, 2024
1 parent 6aec69a commit 9695957
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/hooks/markdownFence.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import markdownIt from "markdown-it";

const colonFenceRegex = /:{3,}/g;

export function colonFencedBlocks(/** @type {markdownIt} */ md) {
md.core.ruler.before("block", "colon", (state) => {
state.src = state.src.replace(colonFenceRegex, (match) => "`".repeat(match.length));
});
}
2 changes: 2 additions & 0 deletions src/hooks/useText.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { ensureSyntaxTree } from "@codemirror/language";
import { MystState } from "../mystState";
import { useComputed } from "@preact/signals";
import markdownCheckboxes from "markdown-it-checkbox";
import { colonFencedBlocks } from "./markdownFence";

const countOccurences = (str, pattern) => (str?.match(pattern) || []).length;

Expand Down Expand Up @@ -110,6 +111,7 @@ export const useText = ({ preview }) => {
.use(markdownMermaid, { lineMap, parent: options.parent })
.use(markdownSourceMap)
.use(checkLinks)
.use(colonFencedBlocks)
.use(markdownCheckboxes);

if (options.backslashLineBreak.value) md.use(backslashLineBreakPlugin);
Expand Down

0 comments on commit 9695957

Please sign in to comment.