| | |
| | | import { Root, Html, BlockContent, DefinitionContent, Paragraph, Code } from "mdast" |
| | | import { Element, Literal, Root as HtmlRoot } from "hast" |
| | | import { ReplaceFunction, findAndReplace as mdastFindReplace } from "mdast-util-find-and-replace" |
| | | import { slug as slugAnchor } from "github-slugger" |
| | | import rehypeRaw from "rehype-raw" |
| | | import { SKIP, visit } from "unist-util-visit" |
| | | import path from "path" |
| | |
| | | /^(?<alt>(?!^\d*x?\d*$).*?)?(\|?\s*?(?<width>\d+)(x(?<height>\d+))?)?$/, |
| | | ) |
| | | |
| | | export const ObsidianFlavoredMarkdown: QuartzTransformerPlugin<Partial<Options> | undefined> = ( |
| | | userOpts, |
| | | ) => { |
| | | export const ObsidianFlavoredMarkdown: QuartzTransformerPlugin<Partial<Options>> = (userOpts) => { |
| | | const opts = { ...defaultOptions, ...userOpts } |
| | | |
| | | const mdastToHtml = (ast: PhrasingContent | Paragraph) => { |
| | |
| | | const [rawFp, rawHeader, rawAlias]: (string | undefined)[] = capture |
| | | |
| | | const [fp, anchor] = splitAnchor(`${rawFp ?? ""}${rawHeader ?? ""}`) |
| | | const blockRef = Boolean(anchor?.startsWith("^")) ? "^" : "" |
| | | const blockRef = Boolean(rawHeader?.match(/^#?\^/)) ? "^" : "" |
| | | const displayAnchor = anchor ? `#${blockRef}${anchor.trim().replace(/^#+/, "")}` : "" |
| | | const displayAlias = rawAlias ?? rawHeader?.replace("#", "|") ?? "" |
| | | const embedDisplay = value.startsWith("!") ? "!" : "" |
| | |
| | | } else if ([".pdf"].includes(ext)) { |
| | | return { |
| | | type: "html", |
| | | value: `<iframe src="${url}"></iframe>`, |
| | | value: `<iframe src="${url}" class="pdf"></iframe>`, |
| | | } |
| | | } else { |
| | | const block = anchor |
| | | return { |
| | | type: "html", |
| | | data: { hProperties: { transclude: true } }, |
| | | value: `<blockquote class="transclude" data-url="${url}" data-block="${block}"><a href="${ |
| | | value: `<blockquote class="transclude" data-url="${url}" data-block="${block}" data-embed-alias="${alias}"><a href="${ |
| | | url + anchor |
| | | }" class="transclude-inner">Transclude of ${url}${block}</a></blockquote>`, |
| | | } |
| | |
| | | // YouTube video (with optional playlist) |
| | | node.tagName = "iframe" |
| | | node.properties = { |
| | | class: "external-embed", |
| | | class: "external-embed youtube", |
| | | allow: "fullscreen", |
| | | frameborder: 0, |
| | | width: "600px", |
| | | height: "350px", |
| | | src: playlistId |
| | | ? `https://www.youtube.com/embed/${videoId}?list=${playlistId}` |
| | | : `https://www.youtube.com/embed/${videoId}`, |
| | |
| | | // YouTube playlist only. |
| | | node.tagName = "iframe" |
| | | node.properties = { |
| | | class: "external-embed", |
| | | class: "external-embed youtube", |
| | | allow: "fullscreen", |
| | | frameborder: 0, |
| | | width: "600px", |
| | | height: "350px", |
| | | src: `https://www.youtube.com/embed/videoseries?list=${playlistId}`, |
| | | } |
| | | } |