Odaimoko
2023-11-28 660aae62e09ea1f5ec957149b78bfd01a85bd79f
quartz/plugins/transformers/ofm.ts
@@ -110,7 +110,10 @@
// ([^\[\]\|\#]+)   -> one or more non-special characters ([,],|, or #) (name)
// (#[^\[\]\|\#]+)? -> # then one or more non-special characters (heading link)
// (|[^\[\]\|\#]+)? -> | then one or more non-special characters (alias)
const wikilinkRegex = new RegExp(/!?\[\[([^\[\]\|\#]+)?(#[^\[\]\|\#]+)?(\|[^\[\]\|\#]+)?\]\]/, "g")
export const wikilinkRegex = new RegExp(
  /!?\[\[([^\[\]\|\#]+)?(#+[^\[\]\|\#]+)?(\|[^\[\]\|\#]+)?\]\]/,
  "g",
)
const highlightRegex = new RegExp(/==([^=]+)==/, "g")
const commentRegex = new RegExp(/%%(.+)%%/, "g")
// from https://github.com/escwxyz/remark-obsidian-callout/blob/main/src/index.ts
@@ -178,7 +181,7 @@
        src = src.replaceAll(wikilinkRegex, (value, ...capture) => {
          const [rawFp, rawHeader, rawAlias] = capture
          const fp = rawFp ?? ""
          const anchor = rawHeader?.trim().slice(1)
          const anchor = rawHeader?.trim().replace(/^#+/, "")
          const displayAnchor = anchor ? `#${slugAnchor(anchor)}` : ""
          const displayAlias = rawAlias ?? rawHeader?.replace("#", "|") ?? ""
          const embedDisplay = value.startsWith("!") ? "!" : ""
@@ -436,7 +439,6 @@
          const blockTagTypes = new Set(["blockquote"])
          return (tree, file) => {
            file.data.blocks = {}
            file.data.htmlAst = tree
            visit(tree, "element", (node, index, parent) => {
              if (blockTagTypes.has(node.tagName)) {
@@ -478,6 +480,8 @@
                }
              }
            })
            file.data.htmlAst = tree
          }
        })
      }