Skip to content

Commit

Permalink
Updated parsers with new typing
Browse files Browse the repository at this point in the history
  • Loading branch information
saberzero1 committed Sep 19, 2024
1 parent c3f1695 commit 50bbc82
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 7 deletions.
18 changes: 16 additions & 2 deletions quartz/plugins/parsers/obsidian/arrows.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { QuartzTransformerPlugin } from "../../types"
import { QuartzParserPlugin } from "../../types"
import { ReplaceFunction, findAndReplace as mdastFindReplace } from "mdast-util-find-and-replace"
import { JSResource } from "../../../util/resources"
import { SKIP } from "unist-util-visit"
import { Root } from "mdast"
import { PluggableList } from "unified"
Expand All @@ -25,10 +26,16 @@ const arrowMapping: Record<string, string> = {

const arrowRegex = new RegExp(/(-{1,2}>|={1,2}>|<-{1,2}|<={1,2})/g)

export const ObsidianArrow: QuartzTransformerPlugin<Partial<Options>> = (userOpts) => {
export const ObsidianArrow: QuartzParserPlugin<Partial<Options>> = (userOpts) => {
const opts: Options = { ...defaultOptions, ...userOpts }
return {
name: "ObsidianArrow",
textTransform(_ctx, src: string | Buffer) {
if (src instanceof Buffer) {
src = src.toString()
}
return src
},
markdownPlugins(_ctx) {
return [
(tree: Root) => {
Expand All @@ -50,5 +57,12 @@ export const ObsidianArrow: QuartzTransformerPlugin<Partial<Options>> = (userOpt
},
] as PluggableList
},
htmlPlugins(_ctx) {
return [] as PluggableList
},
externalResources(_ctx) {
const js = [] as JSResource[]
return { js }
},
}
}
20 changes: 17 additions & 3 deletions quartz/plugins/parsers/obsidian/highlights.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { QuartzTransformerPlugin } from "../../types"
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 { PluggableList } from "unified"

Expand All @@ -13,11 +14,17 @@ const defaultOptions: Options = {

const highlightRegex = new RegExp(/==([^=]+)==/g)

export const ObsidianHighlights: QuartzTransformerPlugin<Partial<Options>> = (userOpts) => {
export const ObsidianHighlights: QuartzParserPlugin<Partial<Options>> = (userOpts) => {
const opts: Options = { ...defaultOptions, ...userOpts }
return {
name: "ObsidianHighlights",
markdownPlugins(ctx) {
textTransform(_ctx, src: string | Buffer) {
if (src instanceof Buffer) {
src = src.toString()
}
return src
},
markdownPlugins(_ctx) {
return [
(tree: Root) => {
if (opts.enabled) {
Expand All @@ -37,5 +44,12 @@ export const ObsidianHighlights: QuartzTransformerPlugin<Partial<Options>> = (us
},
] as PluggableList
},
htmlPlugins(_ctx) {
return [] as PluggableList
},
externalResources(_ctx) {
const js = [] as JSResource[]
return { js }
},
}
}
12 changes: 10 additions & 2 deletions quartz/plugins/parsers/obsidian/wikilinks.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { QuartzTransformerPlugin } from "../../types"
import { QuartzParserPlugin } from "../../types"
import { ReplaceFunction, findAndReplace as mdastFindReplace } from "mdast-util-find-and-replace"
import { FilePath, splitAnchor, slugifyFilePath } from "../../../util/path"
import { JSResource } from "../../../util/resources"
import { Root } from "mdast"
import { PluggableList } from "unified"

Expand Down Expand Up @@ -35,7 +36,7 @@ const wikilinkImageEmbedRegex = new RegExp(
/^(?<alt>(?!^\d*x?\d*$).*?)?(\|?\s*?(?<width>\d+)(x(?<height>\d+))?)?$/,
)

export const ObsidianWikilinks: QuartzTransformerPlugin<Partial<Options>> = (userOpts) => {
export const ObsidianWikilinks: QuartzParserPlugin<Partial<Options>> = (userOpts) => {
const opts: Options = { ...defaultOptions, ...userOpts }
return {
name: "ObsidianWikilinks",
Expand Down Expand Up @@ -160,5 +161,12 @@ export const ObsidianWikilinks: QuartzTransformerPlugin<Partial<Options>> = (use
},
] as PluggableList
},
htmlPlugins(_ctx) {
return [] as PluggableList
},
externalResources(_ctx) {
const js = [] as JSResource[]
return { js }
},
}
}

0 comments on commit 50bbc82

Please sign in to comment.