mirror of
https://github.com/jackyzha0/quartz.git
synced 2025-12-27 23:04:05 -06:00
Obsidian Parser (EmbedVideo)
This commit is contained in:
parent
4e830a5931
commit
7a50b5eae7
@ -13,12 +13,10 @@ import { mdastToHtml } from "../../transformers/markdown"
|
||||
|
||||
interface Options {
|
||||
enabled: Boolean
|
||||
inHtml: Boolean
|
||||
}
|
||||
|
||||
const defaultOptions: Options = {
|
||||
enabled: true,
|
||||
inHtml: false,
|
||||
}
|
||||
|
||||
// from https://github.com/escwxyz/remark-obsidian-callout/blob/main/src/index.ts
|
||||
|
||||
@ -6,3 +6,4 @@ export { ObsidianHighlights } from "./highlights"
|
||||
export { ObsidianMermaid } from "./mermaid"
|
||||
export { ObsidianTags } from "./tags"
|
||||
export { ObsidianWikilinks } from "./wikilinks"
|
||||
export { ObsidianVideo } from "./video"
|
||||
|
||||
@ -6,12 +6,10 @@ import { Pluggable } from "unified"
|
||||
|
||||
interface Options {
|
||||
enabled: Boolean
|
||||
inHtml: Boolean
|
||||
}
|
||||
|
||||
const defaultOptions: Options = {
|
||||
enabled: true,
|
||||
inHtml: false,
|
||||
}
|
||||
|
||||
export const ObsidianMermaid: QuartzParser<Partial<Options>> = (userOpts) => {
|
||||
|
||||
54
quartz/plugins/parsers/obsidian/video.ts
Normal file
54
quartz/plugins/parsers/obsidian/video.ts
Normal file
@ -0,0 +1,54 @@
|
||||
import { QuartzParser } from "../../types"
|
||||
import { JSResource } from "../../../util/resources"
|
||||
import { Root, Html } from "mdast"
|
||||
import { Pluggable } from "unified"
|
||||
import { SKIP, visit } from "unist-util-visit"
|
||||
|
||||
interface Options {
|
||||
enabled: Boolean
|
||||
}
|
||||
|
||||
const defaultOptions: Options = {
|
||||
enabled: true,
|
||||
}
|
||||
|
||||
const videoExtensionRegex = new RegExp(/\.(mp4|webm|ogg|avi|mov|flv|wmv|mkv|mpg|mpeg|3gp|m4v)$/)
|
||||
|
||||
export const ObsidianVideo: QuartzParser<Partial<Options>> = (userOpts) => {
|
||||
const opts: Options = { ...defaultOptions, ...userOpts }
|
||||
return {
|
||||
name: "ObsidianVideo",
|
||||
textTransform(_ctx, src: string | Buffer) {
|
||||
if (src instanceof Buffer) {
|
||||
src = src.toString()
|
||||
}
|
||||
return src
|
||||
},
|
||||
markdownPlugins(_ctx) {
|
||||
const plug: Pluggable = (tree: Root, _file) => {
|
||||
if (opts.enabled) {
|
||||
visit(tree, "image", (node, index, parent) => {
|
||||
if (parent && index != undefined && videoExtensionRegex.test(node.url)) {
|
||||
const newNode: Html = {
|
||||
type: "html",
|
||||
value: `<video controls src="${node.url}"></video>`,
|
||||
}
|
||||
|
||||
parent.children.splice(index, 1, newNode)
|
||||
return SKIP
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
return plug
|
||||
},
|
||||
htmlPlugins() {
|
||||
const plug: Pluggable = () => {}
|
||||
return plug
|
||||
},
|
||||
externalResources() {
|
||||
const js = {} as JSResource
|
||||
return js
|
||||
},
|
||||
}
|
||||
}
|
||||
@ -45,6 +45,7 @@ import {
|
||||
ObsidianHighlights,
|
||||
ObsidianMermaid,
|
||||
ObsidianTags,
|
||||
ObsidianVideo,
|
||||
ObsidianWikilinks,
|
||||
} from "../parsers/obsidian"
|
||||
|
||||
@ -312,10 +313,9 @@ export const ObsidianFlavoredMarkdown: QuartzTransformerPlugin<Partial<ObsidianO
|
||||
ObsidianArrow({ enabled: opts.parseArrows, inHtml: inHtml }).markdownPlugins(ctx),
|
||||
)
|
||||
plugins.push(ObsidianTags({ enabled: opts.parseTags, inHtml: inHtml }).markdownPlugins(ctx))
|
||||
plugins.push(
|
||||
ObsidianCallouts({ enabled: opts.callouts, inHtml: inHtml }).markdownPlugins(ctx),
|
||||
)
|
||||
plugins.push(ObsidianMermaid({ enabled: opts.mermaid, inHtml: inHtml }).markdownPlugins(ctx))
|
||||
plugins.push(ObsidianVideo({ enabled: opts.enableVideoEmbed }).markdownPlugins(ctx))
|
||||
plugins.push(ObsidianCallouts({ enabled: opts.callouts }).markdownPlugins(ctx))
|
||||
plugins.push(ObsidianMermaid({ enabled: opts.mermaid }).markdownPlugins(ctx))
|
||||
|
||||
return plugins
|
||||
},
|
||||
|
||||
Loading…
Reference in New Issue
Block a user