mirror of
https://github.com/alrayyes/wiki.git
synced 2024-11-25 21:16:21 +00:00
feat: support transcluding codeblocks and blockquotes (closes #940)
This commit is contained in:
parent
566f3cf9f8
commit
2a7e61ae2a
1 changed files with 29 additions and 7 deletions
|
@ -1,5 +1,5 @@
|
||||||
import { QuartzTransformerPlugin } from "../types"
|
import { QuartzTransformerPlugin } from "../types"
|
||||||
import { Blockquote, Root, Html, BlockContent, DefinitionContent, Paragraph, Code } from "mdast"
|
import { Root, Html, BlockContent, DefinitionContent, Paragraph, Code } from "mdast"
|
||||||
import { Element, Literal, Root as HtmlRoot } from "hast"
|
import { Element, Literal, Root as HtmlRoot } from "hast"
|
||||||
import { ReplaceFunction, findAndReplace as mdastFindReplace } from "mdast-util-find-and-replace"
|
import { ReplaceFunction, findAndReplace as mdastFindReplace } from "mdast-util-find-and-replace"
|
||||||
import { slug as slugAnchor } from "github-slugger"
|
import { slug as slugAnchor } from "github-slugger"
|
||||||
|
@ -17,7 +17,6 @@ import { toHtml } from "hast-util-to-html"
|
||||||
import { PhrasingContent } from "mdast-util-find-and-replace/lib"
|
import { PhrasingContent } from "mdast-util-find-and-replace/lib"
|
||||||
import { capitalize } from "../../util/lang"
|
import { capitalize } from "../../util/lang"
|
||||||
import { PluggableList } from "unified"
|
import { PluggableList } from "unified"
|
||||||
import { ValidCallout, i18n } from "../../i18n"
|
|
||||||
|
|
||||||
export interface Options {
|
export interface Options {
|
||||||
comments: boolean
|
comments: boolean
|
||||||
|
@ -528,12 +527,35 @@ export const ObsidianFlavoredMarkdown: QuartzTransformerPlugin<Partial<Options>
|
||||||
last.value = last.value.slice(0, -matches[0].length)
|
last.value = last.value.slice(0, -matches[0].length)
|
||||||
const block = matches[0].slice(1)
|
const block = matches[0].slice(1)
|
||||||
|
|
||||||
if (!Object.keys(file.data.blocks!).includes(block)) {
|
if (last.value === "") {
|
||||||
node.properties = {
|
// this is an inline block ref but the actual block
|
||||||
...node.properties,
|
// is the previous element above it
|
||||||
id: block,
|
let idx = (index ?? 1) - 1
|
||||||
|
while (idx >= 0) {
|
||||||
|
const element = parent?.children.at(idx)
|
||||||
|
if (!element) break
|
||||||
|
if (element.type !== "element") {
|
||||||
|
idx -= 1
|
||||||
|
} else {
|
||||||
|
if (!Object.keys(file.data.blocks!).includes(block)) {
|
||||||
|
element.properties = {
|
||||||
|
...element.properties,
|
||||||
|
id: block,
|
||||||
|
}
|
||||||
|
file.data.blocks![block] = element
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// normal paragraph transclude
|
||||||
|
if (!Object.keys(file.data.blocks!).includes(block)) {
|
||||||
|
node.properties = {
|
||||||
|
...node.properties,
|
||||||
|
id: block,
|
||||||
|
}
|
||||||
|
file.data.blocks![block] = node
|
||||||
}
|
}
|
||||||
file.data.blocks![block] = node
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue