mirror of
https://github.com/jackyzha0/quartz.git
synced 2026-03-24 15:05:42 -05:00
Obsidian Parser (Comments)
This commit is contained in:
parent
f83ca160b8
commit
e5558c7621
49
quartz/plugins/parsers/obsidian/comments.ts
Normal file
49
quartz/plugins/parsers/obsidian/comments.ts
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
import { QuartzParserPlugin } from "../../types"
|
||||||
|
import { ReplaceFunction, findAndReplace as mdastFindReplace } from "mdast-util-find-and-replace"
|
||||||
|
import { JSResource } from "../../../util/resources"
|
||||||
|
import { Root } from "mdast"
|
||||||
|
import { Pluggable } from "unified"
|
||||||
|
|
||||||
|
interface Options {
|
||||||
|
enabled: Boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
const defaultOptions: Options = {
|
||||||
|
enabled: true,
|
||||||
|
}
|
||||||
|
|
||||||
|
const commentRegex = new RegExp(/%%[\s\S]*?%%/g)
|
||||||
|
|
||||||
|
export const ObsidianComments: QuartzParserPlugin<Partial<Options>> = (userOpts) => {
|
||||||
|
const opts: Options = { ...defaultOptions, ...userOpts }
|
||||||
|
return {
|
||||||
|
name: "ObsidianComments",
|
||||||
|
textTransform(_ctx, src: string | Buffer) {
|
||||||
|
// do comments at text level
|
||||||
|
if (src instanceof Buffer) {
|
||||||
|
src = src.toString()
|
||||||
|
}
|
||||||
|
|
||||||
|
src = src.replace(commentRegex, "")
|
||||||
|
|
||||||
|
return src
|
||||||
|
},
|
||||||
|
markdownPlugins(_ctx) {
|
||||||
|
const plug: Pluggable = (tree: Root, _file) => {
|
||||||
|
if (opts.enabled) {
|
||||||
|
const replacements: [RegExp, string | ReplaceFunction][] = []
|
||||||
|
mdastFindReplace(tree, replacements)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return plug
|
||||||
|
},
|
||||||
|
htmlPlugins(_ctx) {
|
||||||
|
const plug: Pluggable = () => {}
|
||||||
|
return plug
|
||||||
|
},
|
||||||
|
externalResources(_ctx) {
|
||||||
|
const js = [] as JSResource[]
|
||||||
|
return { js }
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,4 +1,5 @@
|
|||||||
export { ObsidianArrow } from "./arrows"
|
export { ObsidianArrow } from "./arrows"
|
||||||
export { ObsidianCallouts } from "./callouts"
|
export { ObsidianCallouts } from "./callouts"
|
||||||
|
export { ObsidianComments } from "./comments"
|
||||||
export { ObsidianHighlights } from "./highlights"
|
export { ObsidianHighlights } from "./highlights"
|
||||||
export { ObsidianWikilinks } from "./wikilinks"
|
export { ObsidianWikilinks } from "./wikilinks"
|
||||||
|
|||||||
@ -38,6 +38,7 @@ import rehypeAutolinkHeadings from "rehype-autolink-headings"
|
|||||||
import {
|
import {
|
||||||
ObsidianArrow,
|
ObsidianArrow,
|
||||||
ObsidianCallouts,
|
ObsidianCallouts,
|
||||||
|
ObsidianComments,
|
||||||
ObsidianHighlights,
|
ObsidianHighlights,
|
||||||
ObsidianWikilinks,
|
ObsidianWikilinks,
|
||||||
} from "../parsers/obsidian"
|
} from "../parsers/obsidian"
|
||||||
@ -178,6 +179,7 @@ export const ObsidianFlavoredMarkdown: QuartzTransformerPlugin<Partial<ObsidianO
|
|||||||
return {
|
return {
|
||||||
name: "ObsidianFlavoredMarkdown",
|
name: "ObsidianFlavoredMarkdown",
|
||||||
textTransform(ctx, src) {
|
textTransform(ctx, src) {
|
||||||
|
src = ObsidianComments({ enabled: opts.comments }).textTransform(ctx, src)
|
||||||
src = ObsidianCallouts({ enabled: opts.callouts }).textTransform(ctx, src)
|
src = ObsidianCallouts({ enabled: opts.callouts }).textTransform(ctx, src)
|
||||||
src = ObsidianWikilinks({ enabled: opts.wikilinks }).textTransform(ctx, src)
|
src = ObsidianWikilinks({ enabled: opts.wikilinks }).textTransform(ctx, src)
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user