mirror of https://github.com/usememos/memos.git
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>
This commit is contained in:
parent
1cf047707b
commit
48ce4ccc26
|
|
@ -11,6 +11,7 @@ import useCurrentUser from "@/hooks/useCurrentUser";
|
|||
import { cn } from "@/lib/utils";
|
||||
import { memoStore } from "@/store";
|
||||
import { useTranslate } from "@/utils/i18n";
|
||||
import { remarkDisableSetext } from "@/utils/remark-plugins/remark-disable-setext";
|
||||
import { remarkPreserveType } from "@/utils/remark-plugins/remark-preserve-type";
|
||||
import { remarkTag } from "@/utils/remark-plugins/remark-tag";
|
||||
import { isSuperUser } from "@/utils/user";
|
||||
|
|
@ -59,7 +60,7 @@ const MemoContent = observer((props: MemoContentProps) => {
|
|||
onDoubleClick={onDoubleClick}
|
||||
>
|
||||
<ReactMarkdown
|
||||
remarkPlugins={[remarkGfm, remarkBreaks, remarkMath, remarkTag, remarkPreserveType]}
|
||||
remarkPlugins={[remarkDisableSetext, remarkGfm, remarkBreaks, remarkMath, remarkTag, remarkPreserveType]}
|
||||
rehypePlugins={[rehypeRaw, rehypeKatex, [rehypeSanitize, SANITIZE_SCHEMA]]}
|
||||
components={{
|
||||
// Conditionally render custom components based on AST node type
|
||||
|
|
|
|||
|
|
@ -0,0 +1,30 @@
|
|||
/**
|
||||
* Remark plugin to disable setext header syntax.
|
||||
*
|
||||
* Setext headers use underlines (=== or ---) to create headings:
|
||||
* Heading 1
|
||||
* =========
|
||||
*
|
||||
* Heading 2
|
||||
* ---------
|
||||
*
|
||||
* This plugin disables the setext heading construct at the micromark parser level,
|
||||
* preventing these patterns from being recognized as headers.
|
||||
*/
|
||||
export function remarkDisableSetext(this: any) {
|
||||
const data = this.data();
|
||||
|
||||
add("micromarkExtensions", {
|
||||
disable: {
|
||||
null: ["setextUnderline"],
|
||||
},
|
||||
});
|
||||
|
||||
/**
|
||||
* Add a micromark extension to the parser configuration.
|
||||
*/
|
||||
function add(field: string, value: any) {
|
||||
const list = data[field] ? data[field] : (data[field] = []);
|
||||
list.push(value);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue