fix more types

This commit is contained in:
Jacky Zhao 2025-03-05 16:43:00 -08:00
parent fa97c7161a
commit ee6eb1a1cb
4 changed files with 7 additions and 19 deletions

View File

@ -37,7 +37,7 @@ Transformers **map** over content, taking a Markdown file and outputting modifie
```ts ```ts
export type QuartzTransformerPluginInstance = { export type QuartzTransformerPluginInstance = {
name: string name: string
textTransform?: (ctx: BuildCtx, src: string | Buffer) => string | Buffer textTransform?: (ctx: BuildCtx, src: string) => string
markdownPlugins?: (ctx: BuildCtx) => PluggableList markdownPlugins?: (ctx: BuildCtx) => PluggableList
htmlPlugins?: (ctx: BuildCtx) => PluggableList htmlPlugins?: (ctx: BuildCtx) => PluggableList
externalResources?: (ctx: BuildCtx) => Partial<StaticResources> externalResources?: (ctx: BuildCtx) => Partial<StaticResources>

View File

@ -156,20 +156,12 @@ export const ObsidianFlavoredMarkdown: QuartzTransformerPlugin<Partial<Options>>
textTransform(_ctx, src) { textTransform(_ctx, src) {
// do comments at text level // do comments at text level
if (opts.comments) { if (opts.comments) {
if (src instanceof Buffer) { src = src.replace(commentRegex, "")
src = src.toString()
}
src = (src as string).replace(commentRegex, "")
} }
// pre-transform blockquotes // pre-transform blockquotes
if (opts.callouts) { if (opts.callouts) {
if (src instanceof Buffer) { src = src.replace(calloutLineRegex, (value) => {
src = src.toString()
}
src = (src as string).replace(calloutLineRegex, (value) => {
// force newline after title of callout // force newline after title of callout
return value + "\n> " return value + "\n> "
}) })
@ -177,12 +169,8 @@ export const ObsidianFlavoredMarkdown: QuartzTransformerPlugin<Partial<Options>>
// pre-transform wikilinks (fix anchors to things that may contain illegal syntax e.g. codeblocks, latex) // pre-transform wikilinks (fix anchors to things that may contain illegal syntax e.g. codeblocks, latex)
if (opts.wikilinks) { if (opts.wikilinks) {
if (src instanceof Buffer) {
src = src.toString()
}
// replace all wikilinks inside a table first // replace all wikilinks inside a table first
src = (src as string).replace(tableRegex, (value) => { src = src.replace(tableRegex, (value) => {
// escape all aliases and headers in wikilinks inside a table // escape all aliases and headers in wikilinks inside a table
return value.replace(tableWikilinkRegex, (_value, raw) => { return value.replace(tableWikilinkRegex, (_value, raw) => {
// const [raw]: (string | undefined)[] = capture // const [raw]: (string | undefined)[] = capture
@ -196,7 +184,7 @@ export const ObsidianFlavoredMarkdown: QuartzTransformerPlugin<Partial<Options>>
}) })
// replace all other wikilinks // replace all other wikilinks
src = (src as string).replace(wikilinkRegex, (value, ...capture) => { src = src.replace(wikilinkRegex, (value, ...capture) => {
const [rawFp, rawHeader, rawAlias]: (string | undefined)[] = capture const [rawFp, rawHeader, rawAlias]: (string | undefined)[] = capture
const [fp, anchor] = splitAnchor(`${rawFp ?? ""}${rawHeader ?? ""}`) const [fp, anchor] = splitAnchor(`${rawFp ?? ""}${rawHeader ?? ""}`)

View File

@ -18,7 +18,7 @@ export type QuartzTransformerPlugin<Options extends OptionType = undefined> = (
) => QuartzTransformerPluginInstance ) => QuartzTransformerPluginInstance
export type QuartzTransformerPluginInstance = { export type QuartzTransformerPluginInstance = {
name: string name: string
textTransform?: (ctx: BuildCtx, src: string | Buffer) => string | Buffer textTransform?: (ctx: BuildCtx, src: string) => string
markdownPlugins?: (ctx: BuildCtx) => PluggableList markdownPlugins?: (ctx: BuildCtx) => PluggableList
htmlPlugins?: (ctx: BuildCtx) => PluggableList htmlPlugins?: (ctx: BuildCtx) => PluggableList
externalResources?: (ctx: BuildCtx) => Partial<StaticResources> externalResources?: (ctx: BuildCtx) => Partial<StaticResources>

View File

@ -95,7 +95,7 @@ export function createFileParser(ctx: BuildCtx, fps: FilePath[]) {
// Text -> Text transforms // Text -> Text transforms
for (const plugin of cfg.plugins.transformers.filter((p) => p.textTransform)) { for (const plugin of cfg.plugins.transformers.filter((p) => p.textTransform)) {
file.value = plugin.textTransform!(ctx, Buffer.from(file.value as Uint8Array)) file.value = plugin.textTransform!(ctx, file.value.toString())
} }
// base data properties that plugins may use // base data properties that plugins may use