Skip to content

Commit 48ce4cc

Browse files
boojackclaude
andcommitted
fix(web): disable setext header syntax (#5314)
Add custom remark plugin to prevent setext headers (headers using === or --- underlines) from being recognized by the markdown parser. The plugin disables the setextUnderline construct at the micromark parser level. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 1cf0477 commit 48ce4cc

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

web/src/components/MemoContent/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import useCurrentUser from "@/hooks/useCurrentUser";
1111
import { cn } from "@/lib/utils";
1212
import { memoStore } from "@/store";
1313
import { useTranslate } from "@/utils/i18n";
14+
import { remarkDisableSetext } from "@/utils/remark-plugins/remark-disable-setext";
1415
import { remarkPreserveType } from "@/utils/remark-plugins/remark-preserve-type";
1516
import { remarkTag } from "@/utils/remark-plugins/remark-tag";
1617
import { isSuperUser } from "@/utils/user";
@@ -59,7 +60,7 @@ const MemoContent = observer((props: MemoContentProps) => {
5960
onDoubleClick={onDoubleClick}
6061
>
6162
<ReactMarkdown
62-
remarkPlugins={[remarkGfm, remarkBreaks, remarkMath, remarkTag, remarkPreserveType]}
63+
remarkPlugins={[remarkDisableSetext, remarkGfm, remarkBreaks, remarkMath, remarkTag, remarkPreserveType]}
6364
rehypePlugins={[rehypeRaw, rehypeKatex, [rehypeSanitize, SANITIZE_SCHEMA]]}
6465
components={{
6566
// Conditionally render custom components based on AST node type
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* Remark plugin to disable setext header syntax.
3+
*
4+
* Setext headers use underlines (=== or ---) to create headings:
5+
* Heading 1
6+
* =========
7+
*
8+
* Heading 2
9+
* ---------
10+
*
11+
* This plugin disables the setext heading construct at the micromark parser level,
12+
* preventing these patterns from being recognized as headers.
13+
*/
14+
export function remarkDisableSetext(this: any) {
15+
const data = this.data();
16+
17+
add("micromarkExtensions", {
18+
disable: {
19+
null: ["setextUnderline"],
20+
},
21+
});
22+
23+
/**
24+
* Add a micromark extension to the parser configuration.
25+
*/
26+
function add(field: string, value: any) {
27+
const list = data[field] ? data[field] : (data[field] = []);
28+
list.push(value);
29+
}
30+
}

0 commit comments

Comments
 (0)