mirror of
https://github.com/jackyzha0/quartz.git
synced 2026-03-24 15:05:42 -05:00
Rewrite parser application
This commit is contained in:
parent
c1c8e26722
commit
8f96809bf3
@ -65,7 +65,7 @@ const config: QuartzConfig = {
|
||||
},
|
||||
keepBackground: false,
|
||||
}),
|
||||
Plugin.ObsidianFlavoredMarkdown({ enableInHtmlEmbed: false }),
|
||||
//Plugin.ObsidianFlavoredMarkdown({ enableInHtmlEmbed: false }),
|
||||
Plugin.GitHubFlavoredMarkdown(),
|
||||
Plugin.TableOfContents(),
|
||||
Plugin.CrawlLinks({ markdownLinkResolution: "shortest" }),
|
||||
@ -77,8 +77,8 @@ const config: QuartzConfig = {
|
||||
Plugin.AliasRedirects(),
|
||||
Plugin.ComponentResources(),
|
||||
Plugin.ContentPage(),
|
||||
//Plugin.FolderPage(),
|
||||
//Plugin.TagPage(),
|
||||
Plugin.FolderPage(),
|
||||
Plugin.TagPage(),
|
||||
Plugin.ContentIndex({
|
||||
enableSiteMap: true,
|
||||
enableRSS: true,
|
||||
|
||||
@ -3,6 +3,8 @@ import { ReplaceFunction, findAndReplace as mdastFindReplace } from "mdast-util-
|
||||
import { JSResource } from "../../../util/resources"
|
||||
import { Root } from "mdast"
|
||||
import { Pluggable } from "unified"
|
||||
import { visit } from "unist-util-visit"
|
||||
import { Element, Literal, Root as HtmlRoot } from "hast"
|
||||
|
||||
interface Options {
|
||||
enabled: Boolean
|
||||
@ -22,16 +24,16 @@ export const CustomDefault: QuartzParser<Partial<Options>> = (userOpts) => {
|
||||
}
|
||||
return src
|
||||
},
|
||||
markdownPlugins(_ctx) {
|
||||
const replacements: [RegExp, string | ReplaceFunction][] = []
|
||||
const plug: Pluggable = (tree: Root, _file) => {
|
||||
mdastFindReplace(tree, replacements)
|
||||
}
|
||||
return replacements
|
||||
markdownPlugins(tree, file) {
|
||||
return [new RegExp(""), ""] as [RegExp, string | ReplaceFunction]
|
||||
},
|
||||
htmlPlugins() {
|
||||
const plug: Pluggable = () => {}
|
||||
return plug
|
||||
htmlPlugins(tree, file) {
|
||||
if (opts.enabled) {
|
||||
return () => {
|
||||
visit(tree!, "element", (node) => {})
|
||||
}
|
||||
}
|
||||
return {} as Pluggable
|
||||
},
|
||||
externalResources() {
|
||||
const js = {} as JSResource
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
import { QuartzParser } from "../../types"
|
||||
import { JSResource } from "../../../util/resources"
|
||||
import { ReplaceFunction, findAndReplace as mdastFindReplace } from "mdast-util-find-and-replace"
|
||||
import { Pluggable } from "unified"
|
||||
import rehypeSlug from "rehype-slug"
|
||||
import rehypeAutolinkHeadings from "rehype-autolink-headings"
|
||||
@ -22,9 +23,8 @@ export const GitHubLinkheadings: QuartzParser<Partial<Options>> = (userOpts) =>
|
||||
}
|
||||
return src
|
||||
},
|
||||
markdownPlugins(_ctx) {
|
||||
const plug: Pluggable = () => {}
|
||||
return plug
|
||||
markdownPlugins(tree, file) {
|
||||
return [new RegExp(""), ""] as [RegExp, string | ReplaceFunction]
|
||||
},
|
||||
htmlPlugins() {
|
||||
if (opts.enabled) {
|
||||
@ -74,10 +74,9 @@ export const GitHubLinkheadings: QuartzParser<Partial<Options>> = (userOpts) =>
|
||||
},
|
||||
},
|
||||
],
|
||||
] as Pluggable[]
|
||||
} else {
|
||||
return [] as Pluggable[]
|
||||
] as Pluggable
|
||||
}
|
||||
return [] as Pluggable
|
||||
},
|
||||
externalResources() {
|
||||
const js = {} as JSResource
|
||||
|
||||
@ -22,11 +22,11 @@ export const GitHubSmartypants: QuartzParser<Partial<Options>> = (userOpts) => {
|
||||
}
|
||||
return src
|
||||
},
|
||||
markdownPlugins(_ctx) {
|
||||
markdownPlugins() {
|
||||
if (opts.enabled) {
|
||||
return [remarkGfm, smartypants]
|
||||
return smartypants as Pluggable
|
||||
}
|
||||
return [remarkGfm]
|
||||
return {} as Pluggable
|
||||
},
|
||||
htmlPlugins() {
|
||||
const plug: Pluggable = () => {}
|
||||
|
||||
@ -8,12 +8,10 @@ import { mdastFindReplaceInHtml } from "../../transformers/markdown"
|
||||
|
||||
interface Options {
|
||||
enabled: Boolean
|
||||
inHtml: Boolean
|
||||
}
|
||||
|
||||
const defaultOptions: Options = {
|
||||
enabled: true,
|
||||
inHtml: false,
|
||||
}
|
||||
|
||||
const arrowMapping: Record<string, string> = {
|
||||
@ -41,11 +39,9 @@ export const ObsidianArrow: QuartzParser<Partial<Options>> = (userOpts) => {
|
||||
}
|
||||
return src
|
||||
},
|
||||
markdownPlugins(_ctx) {
|
||||
const replacements: [RegExp, string | ReplaceFunction][] = []
|
||||
const plug: Pluggable = (tree: Root, _path) => {
|
||||
markdownPlugins() {
|
||||
if (opts.enabled) {
|
||||
replacements.push([
|
||||
return [
|
||||
arrowRegex,
|
||||
(value: string, ..._capture: string[]) => {
|
||||
const maybeArrow = arrowMapping[value]
|
||||
@ -55,10 +51,9 @@ export const ObsidianArrow: QuartzParser<Partial<Options>> = (userOpts) => {
|
||||
value: `<span>${maybeArrow}</span>`,
|
||||
}
|
||||
},
|
||||
])
|
||||
] as [RegExp, string | ReplaceFunction]
|
||||
}
|
||||
}
|
||||
return replacements
|
||||
return [new RegExp(""), ""] as [RegExp, string | ReplaceFunction]
|
||||
},
|
||||
htmlPlugins() {
|
||||
const plug: Pluggable = () => {}
|
||||
|
||||
@ -26,18 +26,14 @@ export const ObsidianBlockReference: QuartzParser<Partial<Options>> = (userOpts)
|
||||
}
|
||||
return src
|
||||
},
|
||||
markdownPlugins(_ctx) {
|
||||
const replacements: [RegExp, string | ReplaceFunction][] = []
|
||||
const plug: Pluggable = (tree: Root, _file) => {
|
||||
mdastFindReplace(tree, replacements)
|
||||
}
|
||||
return replacements
|
||||
markdownPlugins(_tree, _file) {
|
||||
return [new RegExp(""), ""] as [RegExp, string | ReplaceFunction]
|
||||
},
|
||||
htmlPlugins() {
|
||||
htmlPlugins(tree, file) {
|
||||
const inlineTagTypes = new Set(["p", "li"])
|
||||
const blockTagTypes = new Set(["blockquote"])
|
||||
if (opts.enabled) {
|
||||
const plug: Pluggable = (tree: HtmlRoot, file) => {
|
||||
return () => {
|
||||
file.data.blocks = {}
|
||||
|
||||
visit(tree, "element", (node, index, parent) => {
|
||||
@ -106,7 +102,6 @@ export const ObsidianBlockReference: QuartzParser<Partial<Options>> = (userOpts)
|
||||
|
||||
file.data.htmlAst = tree
|
||||
}
|
||||
return plug
|
||||
}
|
||||
return {} as Pluggable
|
||||
},
|
||||
|
||||
@ -77,10 +77,8 @@ export const ObsidianCallouts: QuartzParser<Partial<Options>> = (userOpts) => {
|
||||
|
||||
return src
|
||||
},
|
||||
markdownPlugins(_ctx) {
|
||||
const replacements: [RegExp, string | ReplaceFunction][] = []
|
||||
const plug: Pluggable = (tree: Root, _path) => {
|
||||
if (opts.enabled) {
|
||||
markdownPlugins(tree, _file) {
|
||||
if (opts.enabled && tree !== undefined) {
|
||||
visit(tree, "blockquote", (node) => {
|
||||
if (node.children.length === 0) {
|
||||
return
|
||||
@ -182,8 +180,7 @@ export const ObsidianCallouts: QuartzParser<Partial<Options>> = (userOpts) => {
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
return replacements
|
||||
return [new RegExp(""), ""] as [RegExp, string | ReplaceFunction]
|
||||
},
|
||||
htmlPlugins() {
|
||||
const plug: Pluggable = () => {}
|
||||
|
||||
@ -29,12 +29,8 @@ export const ObsidianCheckboxes: QuartzParser<Partial<Options>> = (userOpts) =>
|
||||
}
|
||||
return src
|
||||
},
|
||||
markdownPlugins(_ctx) {
|
||||
const replacements: [RegExp, string | ReplaceFunction][] = []
|
||||
const plug: Pluggable = (tree: Root, _file) => {
|
||||
mdastFindReplaceInHtml(tree, replacements, opts.inHtml)
|
||||
}
|
||||
return replacements
|
||||
markdownPlugins(_tree, _file) {
|
||||
return [new RegExp(""), ""] as [RegExp, string | ReplaceFunction]
|
||||
},
|
||||
htmlPlugins() {
|
||||
if (opts.enabled) {
|
||||
|
||||
@ -3,6 +3,7 @@ import { ReplaceFunction, findAndReplace as mdastFindReplace } from "mdast-util-
|
||||
import { JSResource } from "../../../util/resources"
|
||||
import { Root } from "mdast"
|
||||
import { Pluggable } from "unified"
|
||||
import { visit } from "unist-util-visit"
|
||||
import { mdastFindReplaceInHtml } from "../../transformers/markdown"
|
||||
|
||||
interface Options {
|
||||
@ -32,14 +33,16 @@ export const ObsidianComments: QuartzParser<Partial<Options>> = (userOpts) => {
|
||||
|
||||
return src
|
||||
},
|
||||
markdownPlugins(_ctx) {
|
||||
const replacements: [RegExp, string | ReplaceFunction][] = []
|
||||
const plug: Pluggable = (tree: Root, _file) => {}
|
||||
return replacements
|
||||
markdownPlugins(tree, file) {
|
||||
return [new RegExp(""), ""] as [RegExp, string | ReplaceFunction]
|
||||
},
|
||||
htmlPlugins() {
|
||||
const plug: Pluggable = () => {}
|
||||
return plug
|
||||
htmlPlugins(tree, file) {
|
||||
if (opts.enabled) {
|
||||
return () => {
|
||||
visit(tree, "element", (node) => {})
|
||||
}
|
||||
}
|
||||
return {} as Pluggable
|
||||
},
|
||||
externalResources() {
|
||||
const js = {} as JSResource
|
||||
|
||||
@ -7,12 +7,10 @@ import { mdastFindReplaceInHtml } from "../../transformers/markdown"
|
||||
|
||||
interface Options {
|
||||
enabled: Boolean
|
||||
inHtml: Boolean
|
||||
}
|
||||
|
||||
const defaultOptions: Options = {
|
||||
enabled: true,
|
||||
inHtml: false,
|
||||
}
|
||||
|
||||
const highlightRegex = new RegExp(/==([^=]+)==/g)
|
||||
@ -29,11 +27,9 @@ export const ObsidianHighlights: QuartzParser<Partial<Options>> = (userOpts) =>
|
||||
}
|
||||
return src
|
||||
},
|
||||
markdownPlugins(_ctx) {
|
||||
const replacements: [RegExp, string | ReplaceFunction][] = []
|
||||
const plug: Pluggable = (tree: Root, _path) => {
|
||||
markdownPlugins() {
|
||||
if (opts.enabled) {
|
||||
replacements.push([
|
||||
return [
|
||||
highlightRegex,
|
||||
(_value: string, ...capture: string[]) => {
|
||||
const [inner] = capture
|
||||
@ -42,10 +38,9 @@ export const ObsidianHighlights: QuartzParser<Partial<Options>> = (userOpts) =>
|
||||
value: `<span class="text-highlight">${inner}</span>`,
|
||||
}
|
||||
},
|
||||
])
|
||||
] as [RegExp, string | ReplaceFunction]
|
||||
}
|
||||
}
|
||||
return replacements
|
||||
return [new RegExp(""), ""] as [RegExp, string | ReplaceFunction]
|
||||
},
|
||||
htmlPlugins() {
|
||||
const plug: Pluggable = () => {}
|
||||
|
||||
71
quartz/plugins/parsers/obsidian/html.ts
Normal file
71
quartz/plugins/parsers/obsidian/html.ts
Normal file
@ -0,0 +1,71 @@
|
||||
import { QuartzParser } from "../../types"
|
||||
import { ReplaceFunction, findAndReplace as mdastFindReplace } from "mdast-util-find-and-replace"
|
||||
import { JSResource } from "../../../util/resources"
|
||||
import { Root, Html, Paragraph } from "mdast"
|
||||
import { Pluggable } from "unified"
|
||||
import { mdastFindReplaceInHtml } from "../../transformers/markdown"
|
||||
import { SKIP, visit } from "unist-util-visit"
|
||||
import { toHast } from "mdast-util-to-hast"
|
||||
import { toHtml } from "hast-util-to-html"
|
||||
import { PhrasingContent } from "mdast-util-find-and-replace/lib"
|
||||
|
||||
interface Options {
|
||||
enabled: Boolean
|
||||
}
|
||||
|
||||
const defaultOptions: Options = {
|
||||
enabled: true,
|
||||
}
|
||||
|
||||
const mdastToHtml = (ast: PhrasingContent | Paragraph) => {
|
||||
const hast = toHast(ast, { allowDangerousHtml: true })!
|
||||
return toHtml(hast, { allowDangerousHtml: true })
|
||||
}
|
||||
|
||||
export const ObsidianHtml: QuartzParser<Partial<Options>> = (userOpts) => {
|
||||
const opts: Options = { ...defaultOptions, ...userOpts }
|
||||
return {
|
||||
name: "ObsidianHtml",
|
||||
textTransform(_ctx, src: string | Buffer) {
|
||||
if (opts.enabled) {
|
||||
if (src instanceof Buffer) {
|
||||
src = src.toString()
|
||||
}
|
||||
}
|
||||
return src
|
||||
},
|
||||
markdownPlugins(tree, _file, replacements) {
|
||||
if (opts.enabled && tree !== undefined && replacements !== undefined) {
|
||||
return visit(tree, "html", (node: Html) => {
|
||||
for (const [regex, replace] of replacements) {
|
||||
if (typeof replace === "string") {
|
||||
node.value = node.value.replace(regex, replace)
|
||||
} else {
|
||||
node.value = node.value.replace(regex, (substring: string, ...args) => {
|
||||
const replaceValue = replace(substring, ...args)
|
||||
if (typeof replaceValue === "string") {
|
||||
return replaceValue
|
||||
} else if (Array.isArray(replaceValue)) {
|
||||
return replaceValue.map(mdastToHtml).join("")
|
||||
} else if (typeof replaceValue === "object" && replaceValue !== null) {
|
||||
return mdastToHtml(replaceValue)
|
||||
} else {
|
||||
return substring
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
return [new RegExp(""), ""] as [RegExp, string | ReplaceFunction]
|
||||
},
|
||||
htmlPlugins() {
|
||||
const plug: Pluggable = () => {}
|
||||
return plug
|
||||
},
|
||||
externalResources() {
|
||||
const js = {} as JSResource
|
||||
return js
|
||||
},
|
||||
}
|
||||
}
|
||||
@ -4,6 +4,7 @@ export { ObsidianCallouts } from "./callouts"
|
||||
export { ObsidianCheckboxes } from "./checkboxes"
|
||||
export { ObsidianComments } from "./comments"
|
||||
export { ObsidianHighlights } from "./highlights"
|
||||
export { ObsidianHtml } from "./html"
|
||||
export { ObsidianMermaid } from "./mermaid"
|
||||
export { ObsidianTags } from "./tags"
|
||||
export { ObsidianWikilinks } from "./wikilinks"
|
||||
|
||||
@ -25,10 +25,8 @@ export const ObsidianMermaid: QuartzParser<Partial<Options>> = (userOpts) => {
|
||||
}
|
||||
return src
|
||||
},
|
||||
markdownPlugins() {
|
||||
const replacements: [RegExp, string | ReplaceFunction][] = []
|
||||
const plug: Pluggable = (tree: Root, _file) => {
|
||||
if (opts.enabled) {
|
||||
markdownPlugins(tree, _file) {
|
||||
if (opts.enabled && tree !== undefined) {
|
||||
visit(tree, "code", (node: Code) => {
|
||||
if (node.lang === "mermaid") {
|
||||
node.data = {
|
||||
@ -39,8 +37,6 @@ export const ObsidianMermaid: QuartzParser<Partial<Options>> = (userOpts) => {
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
return replacements
|
||||
},
|
||||
htmlPlugins() {
|
||||
const plug: Pluggable = () => {}
|
||||
|
||||
@ -8,13 +8,11 @@ import { Pluggable } from "unified"
|
||||
import { mdastFindReplaceInHtml } from "../../transformers/markdown"
|
||||
|
||||
interface Options {
|
||||
enabled: Boolean
|
||||
inHtml: Boolean
|
||||
enabled: ConstrainBoolean
|
||||
}
|
||||
|
||||
const defaultOptions: Options = {
|
||||
enabled: true,
|
||||
inHtml: false,
|
||||
}
|
||||
|
||||
// (?:^| ) -> non-capturing group, tag should start be separated by a space or be the start of the line
|
||||
@ -35,12 +33,11 @@ export const ObsidianTags: QuartzParser<Partial<Options>> = (userOpts) => {
|
||||
}
|
||||
return src
|
||||
},
|
||||
markdownPlugins(_ctx) {
|
||||
const replacements: [RegExp, string | ReplaceFunction][] = []
|
||||
const plug: Pluggable = (tree: Root, file) => {
|
||||
if (opts.enabled) {
|
||||
markdownPlugins(_tree, file) {
|
||||
console.log(file)
|
||||
if (opts.enabled && file !== undefined) {
|
||||
const base = pathToRoot(file.data.slug!)
|
||||
replacements.push([
|
||||
return [
|
||||
tagRegex,
|
||||
(_value: string, tag: string) => {
|
||||
// Check if the tag only includes numbers and slashes
|
||||
@ -70,10 +67,9 @@ export const ObsidianTags: QuartzParser<Partial<Options>> = (userOpts) => {
|
||||
],
|
||||
}
|
||||
},
|
||||
])
|
||||
] as [RegExp, string | ReplaceFunction]
|
||||
}
|
||||
}
|
||||
return replacements
|
||||
return [new RegExp(""), ""] as [RegExp, string | ReplaceFunction]
|
||||
},
|
||||
htmlPlugins() {
|
||||
const plug: Pluggable = () => {}
|
||||
|
||||
@ -24,9 +24,8 @@ export const ObsidianVideo: QuartzParser<Partial<Options>> = (userOpts) => {
|
||||
}
|
||||
return src
|
||||
},
|
||||
markdownPlugins(_ctx) {
|
||||
const plug: Pluggable = (tree: Root, _file) => {
|
||||
if (opts.enabled) {
|
||||
markdownPlugins(tree, _file) {
|
||||
if (opts.enabled && tree !== undefined) {
|
||||
visit(tree, "image", (node, index, parent) => {
|
||||
if (parent && index != undefined && videoExtensionRegex.test(node.url)) {
|
||||
const newNode: Html = {
|
||||
@ -39,8 +38,6 @@ export const ObsidianVideo: QuartzParser<Partial<Options>> = (userOpts) => {
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
return plug
|
||||
},
|
||||
htmlPlugins() {
|
||||
const plug: Pluggable = () => {}
|
||||
|
||||
@ -9,12 +9,10 @@ import path from "path"
|
||||
|
||||
interface Options {
|
||||
enabled: Boolean
|
||||
inHtml: Boolean
|
||||
}
|
||||
|
||||
const defaultOptions: Options = {
|
||||
enabled: true,
|
||||
inHtml: false,
|
||||
}
|
||||
|
||||
const externalLinkRegex = /^https?:\/\//i
|
||||
@ -82,11 +80,9 @@ export const ObsidianWikilinks: QuartzParser<Partial<Options>> = (userOpts) => {
|
||||
|
||||
return src
|
||||
},
|
||||
markdownPlugins(_ctx) {
|
||||
const replacements: [RegExp, string | ReplaceFunction][] = []
|
||||
const plug: Pluggable = (tree: Root, file) => {
|
||||
markdownPlugins() {
|
||||
if (opts.enabled) {
|
||||
replacements.push([
|
||||
return [
|
||||
wikilinkRegex,
|
||||
(value: string, ...capture: string[]) => {
|
||||
let [rawFp, rawHeader, rawAlias] = capture
|
||||
@ -119,9 +115,7 @@ export const ObsidianWikilinks: QuartzParser<Partial<Options>> = (userOpts) => {
|
||||
type: "html",
|
||||
value: `<video src="${url}" controls></video>`,
|
||||
}
|
||||
} else if (
|
||||
[".mp3", ".webm", ".wav", ".m4a", ".ogg", ".3gp", ".flac"].includes(ext)
|
||||
) {
|
||||
} else if ([".mp3", ".webm", ".wav", ".m4a", ".ogg", ".3gp", ".flac"].includes(ext)) {
|
||||
return {
|
||||
type: "html",
|
||||
value: `<audio src="${url}" controls></audio>`,
|
||||
@ -158,10 +152,9 @@ export const ObsidianWikilinks: QuartzParser<Partial<Options>> = (userOpts) => {
|
||||
],
|
||||
}
|
||||
},
|
||||
])
|
||||
] as [RegExp, string | ReplaceFunction]
|
||||
}
|
||||
}
|
||||
return replacements
|
||||
return [new RegExp(""), ""] as [RegExp, string | ReplaceFunction]
|
||||
},
|
||||
htmlPlugins() {
|
||||
const plug: Pluggable = () => {}
|
||||
|
||||
@ -27,16 +27,12 @@ export const ObsidianYouTube: QuartzParser<Partial<Options>> = (userOpts) => {
|
||||
}
|
||||
return src
|
||||
},
|
||||
markdownPlugins(_ctx) {
|
||||
const replacements: [RegExp, string | ReplaceFunction][] = []
|
||||
const plug: Pluggable = (tree: Root, _file) => {
|
||||
mdastFindReplace(tree, replacements)
|
||||
}
|
||||
return replacements
|
||||
markdownPlugins(_file, _tree) {
|
||||
return [new RegExp(""), ""] as [RegExp, string | ReplaceFunction]
|
||||
},
|
||||
htmlPlugins() {
|
||||
htmlPlugins(tree, _file) {
|
||||
if (opts.enabled) {
|
||||
const plug: Pluggable = (tree: HtmlRoot, _file) => {
|
||||
return () => {
|
||||
visit(tree, "element", (node) => {
|
||||
if (node.tagName === "img" && typeof node.properties.src === "string") {
|
||||
const match = node.properties.src.match(ytLinkRegex)
|
||||
@ -68,7 +64,6 @@ export const ObsidianYouTube: QuartzParser<Partial<Options>> = (userOpts) => {
|
||||
}
|
||||
})
|
||||
}
|
||||
return plug
|
||||
}
|
||||
return {} as Pluggable
|
||||
},
|
||||
|
||||
@ -44,6 +44,7 @@ import {
|
||||
ObsidianCheckboxes,
|
||||
ObsidianComments,
|
||||
ObsidianHighlights,
|
||||
ObsidianHtml,
|
||||
ObsidianMermaid,
|
||||
ObsidianTags,
|
||||
ObsidianVideo,
|
||||
@ -249,14 +250,14 @@ export const GitHubFlavoredMarkdown: QuartzTransformerPlugin<Partial<GitHubOptio
|
||||
const opts = { ...defaultGitHubOptions, ...userOpts }
|
||||
return {
|
||||
name: "GitHubFlavoredMarkdown",
|
||||
textTransform(ctx, src) {
|
||||
/*textTransform(ctx, src) {
|
||||
return src
|
||||
},
|
||||
markdownPlugins(ctx) {
|
||||
const plugins: PluggableList = []
|
||||
},*/
|
||||
markdownPlugins() {
|
||||
const plugins: PluggableList = [remarkGfm]
|
||||
|
||||
plugins.push(
|
||||
GitHubSmartypants({ enabled: opts.enableSmartyPants }).markdownPlugins(ctx) as Pluggable,
|
||||
GitHubSmartypants({ enabled: opts.enableSmartyPants }).markdownPlugins() as Pluggable,
|
||||
)
|
||||
|
||||
return plugins
|
||||
@ -264,15 +265,15 @@ export const GitHubFlavoredMarkdown: QuartzTransformerPlugin<Partial<GitHubOptio
|
||||
htmlPlugins() {
|
||||
const plugins: PluggableList = []
|
||||
|
||||
plugins.push.apply(GitHubLinkheadings({ enabled: opts.linkHeadings }).htmlPlugins())
|
||||
plugins.push(GitHubLinkheadings({ enabled: opts.linkHeadings }).htmlPlugins())
|
||||
|
||||
return plugins
|
||||
},
|
||||
externalResources() {
|
||||
/*externalResources() {
|
||||
const js: JSResource[] = []
|
||||
|
||||
return { js }
|
||||
},
|
||||
},*/
|
||||
}
|
||||
}
|
||||
|
||||
@ -289,67 +290,61 @@ export const ObsidianFlavoredMarkdown: QuartzTransformerPlugin<Partial<ObsidianO
|
||||
|
||||
return src
|
||||
},
|
||||
markdownPlugins(ctx) {
|
||||
markdownPlugins(_ctx) {
|
||||
const plugins: PluggableList = []
|
||||
|
||||
const inHtml = opts.enableInHtmlEmbed
|
||||
|
||||
plugins.push((tree: Root, file) => {
|
||||
const replacements: [RegExp, string | ReplaceFunction][] = []
|
||||
|
||||
replacements.push.apply(
|
||||
ObsidianWikilinks({ enabled: opts.wikilinks, inHtml: inHtml }).markdownPlugins(ctx),
|
||||
)
|
||||
replacements.push.apply(
|
||||
ObsidianHighlights({ enabled: opts.highlight, inHtml: inHtml }).markdownPlugins(ctx),
|
||||
)
|
||||
replacements.push.apply(
|
||||
ObsidianArrow({ enabled: opts.parseArrows, inHtml: inHtml }).markdownPlugins(ctx),
|
||||
)
|
||||
replacements.push.apply(
|
||||
ObsidianTags({ enabled: opts.parseTags, inHtml: inHtml }).markdownPlugins(ctx),
|
||||
)
|
||||
|
||||
plugins.push(() => {
|
||||
return (tree: Root, file) => {
|
||||
mdastFindReplaceInHtml(tree, replacements, inHtml)
|
||||
if (file !== undefined && file.data !== undefined) {
|
||||
const base = pathToRoot(file.data.slug!)
|
||||
}
|
||||
|
||||
replacements.push(
|
||||
ObsidianWikilinks({ enabled: opts.wikilinks }).markdownPlugins() as [
|
||||
RegExp,
|
||||
string | ReplaceFunction,
|
||||
],
|
||||
)
|
||||
replacements.push(
|
||||
ObsidianHighlights({ enabled: opts.highlight }).markdownPlugins() as [
|
||||
RegExp,
|
||||
string | ReplaceFunction,
|
||||
],
|
||||
)
|
||||
replacements.push(
|
||||
ObsidianArrow({ enabled: opts.parseArrows }).markdownPlugins() as [
|
||||
RegExp,
|
||||
string | ReplaceFunction,
|
||||
],
|
||||
)
|
||||
replacements.push(
|
||||
ObsidianTags({ enabled: opts.parseTags }).markdownPlugins() as [
|
||||
RegExp,
|
||||
string | ReplaceFunction,
|
||||
],
|
||||
)
|
||||
|
||||
/*ObsidianHtml({ enabled: opts.enableInHtmlEmbed }).markdownPlugins(
|
||||
tree,
|
||||
undefined,
|
||||
replacements,
|
||||
)*/
|
||||
|
||||
mdastFindReplace(tree, replacements)
|
||||
})
|
||||
|
||||
/*plugins.push(() => {
|
||||
return (tree: Root, file) => {
|
||||
//const replacements: [RegExp, string | ReplaceFunction][] = []
|
||||
//const base = pathToRoot(file.data.slug!)
|
||||
|
||||
ObsidianWikilinks({ enabled: opts.wikilinks }).markdownPlugins(ctx)
|
||||
|
||||
ObsidianHighlights({ enabled: opts.highlight }).markdownPlugins(ctx)
|
||||
|
||||
ObsidianArrow({ enabled: opts.parseArrows }).markdownPlugins(ctx)
|
||||
|
||||
//mdastFindReplace(tree, replacements)
|
||||
}
|
||||
return (tree: Root, file) =>
|
||||
ObsidianVideo({ enabled: opts.enableVideoEmbed }).markdownPlugins(tree)
|
||||
})
|
||||
plugins.push(() => {
|
||||
return (tree: Root, file) =>
|
||||
ObsidianCallouts({ enabled: opts.callouts }).markdownPlugins(tree)
|
||||
})
|
||||
plugins.push(() => {
|
||||
return (tree: Root, file) =>
|
||||
ObsidianMermaid({ enabled: opts.mermaid }).markdownPlugins(tree)
|
||||
})*/
|
||||
/*plugins.push(
|
||||
ObsidianWikilinks({ enabled: opts.wikilinks, inHtml: inHtml }).markdownPlugins(ctx),
|
||||
)
|
||||
plugins.push(
|
||||
ObsidianHighlights({ enabled: opts.highlight, inHtml: inHtml }).markdownPlugins(ctx),
|
||||
)
|
||||
plugins.push(
|
||||
ObsidianArrow({ enabled: opts.parseArrows, inHtml: inHtml }).markdownPlugins(ctx),
|
||||
)
|
||||
plugins.push(ObsidianTags({ enabled: opts.parseTags, inHtml: inHtml }).markdownPlugins(ctx))*/
|
||||
plugins.push(() => {
|
||||
return (tree: Root, file) =>
|
||||
ObsidianVideo({ enabled: opts.enableVideoEmbed }).markdownPlugins(ctx)
|
||||
})
|
||||
plugins.push(() => {
|
||||
return (tree: Root, file) =>
|
||||
ObsidianCallouts({ enabled: opts.callouts }).markdownPlugins(ctx)
|
||||
})
|
||||
plugins.push(() => {
|
||||
return (tree: Root, file) => ObsidianMermaid({ enabled: opts.mermaid }).markdownPlugins(ctx)
|
||||
})
|
||||
|
||||
return plugins
|
||||
},
|
||||
@ -357,12 +352,12 @@ export const ObsidianFlavoredMarkdown: QuartzTransformerPlugin<Partial<ObsidianO
|
||||
const plugins: PluggableList = [rehypeRaw]
|
||||
|
||||
plugins.push(() => {
|
||||
return (tree: Root, file) =>
|
||||
ObsidianBlockReference({ enabled: opts.parseBlockReferences }).htmlPlugins() as Pluggable
|
||||
return (tree: HtmlRoot, file) =>
|
||||
ObsidianBlockReference({ enabled: opts.parseBlockReferences }).htmlPlugins(tree, file)
|
||||
})
|
||||
plugins.push(() => {
|
||||
return (tree: Root, file) =>
|
||||
ObsidianYouTube({ enabled: opts.enableYouTubeEmbed }).htmlPlugins() as Pluggable
|
||||
return (tree: HtmlRoot, file) =>
|
||||
ObsidianYouTube({ enabled: opts.enableYouTubeEmbed }).htmlPlugins(tree, file)
|
||||
})
|
||||
/*plugins.push(() => {
|
||||
return (tree: HtmlRoot, file) => ObsidianCheckboxes({ enabled: opts.enableCheckbox }).htmlPlugins() as Pluggable}
|
||||
|
||||
@ -6,6 +6,8 @@ import { QuartzComponent } from "../components/types"
|
||||
import { FilePath } from "../util/path"
|
||||
import { BuildCtx } from "../util/ctx"
|
||||
import DepGraph from "../depgraph"
|
||||
import { Root } from "mdast-util-find-and-replace/lib"
|
||||
import { Element, Literal, Root as HtmlRoot } from "hast"
|
||||
|
||||
export interface PluginTypes {
|
||||
transformers: QuartzTransformerPluginInstance[]
|
||||
@ -57,7 +59,11 @@ export type QuartzParser<Options extends OptionType = undefined> = (
|
||||
export type QuartzParserInstance = {
|
||||
name: string
|
||||
textTransform: (ctx: BuildCtx, src: string | Buffer) => string | Buffer
|
||||
markdownPlugins: (ctx: BuildCtx) => [RegExp, string | ReplaceFunction][]
|
||||
htmlPlugins: () => Pluggable | Pluggable[]
|
||||
markdownPlugins: (
|
||||
tree?: Root,
|
||||
file?: any,
|
||||
replacements?: [RegExp, string | ReplaceFunction][],
|
||||
) => [RegExp, string | ReplaceFunction] | Pluggable | void
|
||||
htmlPlugins: (tree?: HtmlRoot, file?: any) => Pluggable
|
||||
externalResources: () => JSResource | string
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user