Striven
2 days ago c538c151c7462ad0395ff2c15c5e11e89e362aa8
quartz/plugins/transformers/oxhugofm.ts
@@ -1,4 +1,6 @@
import { QuartzTransformerPlugin } from "../types"
import rehypeRaw from "rehype-raw"
import { PluggableList } from "unified"
export interface Options {
  /** Replace {{ relref }} with quartz wikilinks []() */
@@ -54,7 +56,7 @@
    textTransform(_ctx, src) {
      if (opts.wikilinks) {
        src = src.toString()
        src = src.replaceAll(relrefRegex, (value, ...capture) => {
        src = src.replaceAll(relrefRegex, (_value, ...capture) => {
          const [text, link] = capture
          return `[${text}](${link})`
        })
@@ -62,7 +64,7 @@
      if (opts.removePredefinedAnchor) {
        src = src.toString()
        src = src.replaceAll(predefinedHeadingIdRegex, (value, ...capture) => {
        src = src.replaceAll(predefinedHeadingIdRegex, (_value, ...capture) => {
          const [headingText] = capture
          return headingText
        })
@@ -70,7 +72,7 @@
      if (opts.removeHugoShortcode) {
        src = src.toString()
        src = src.replaceAll(hugoShortcodeRegex, (value, ...capture) => {
        src = src.replaceAll(hugoShortcodeRegex, (_value, ...capture) => {
          const [scContent] = capture
          return scContent
        })
@@ -78,7 +80,7 @@
      if (opts.replaceFigureWithMdImg) {
        src = src.toString()
        src = src.replaceAll(figureTagRegex, (value, ...capture) => {
        src = src.replaceAll(figureTagRegex, (_value, ...capture) => {
          const [src] = capture
          return `![](${src})`
        })
@@ -86,11 +88,11 @@
      if (opts.replaceOrgLatex) {
        src = src.toString()
        src = src.replaceAll(inlineLatexRegex, (value, ...capture) => {
        src = src.replaceAll(inlineLatexRegex, (_value, ...capture) => {
          const [eqn] = capture
          return `$${eqn}$`
        })
        src = src.replaceAll(blockLatexRegex, (value, ...capture) => {
        src = src.replaceAll(blockLatexRegex, (_value, ...capture) => {
          const [eqn] = capture
          return `$$${eqn}$$`
        })
@@ -102,5 +104,9 @@
      }
      return src
    },
    htmlPlugins() {
      const plugins: PluggableList = [rehypeRaw]
      return plugins
    },
  }
}