The Trans Directory
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix: more robust ofm comment handling

+11 -10
+11 -10
quartz/plugins/transformers/ofm.ts
··· 1 1 import { QuartzTransformerPlugin } from "../types" 2 - import { Root, Html, Image, BlockContent, DefinitionContent, Paragraph, Code } from "mdast" 2 + import { Root, Html, BlockContent, DefinitionContent, Paragraph, Code } from "mdast" 3 3 import { Element, Literal, Root as HtmlRoot } from "hast" 4 4 import { ReplaceFunction, findAndReplace as mdastFindReplace } from "mdast-util-find-and-replace" 5 5 import { slug as slugAnchor } from "github-slugger" ··· 125 125 "g", 126 126 ) 127 127 const highlightRegex = new RegExp(/==([^=]+)==/, "g") 128 - const commentRegex = new RegExp(/%%(.+)%%/, "g") 128 + const commentRegex = new RegExp(/%%[\s\S]*?%%/, "g") 129 129 // from https://github.com/escwxyz/remark-obsidian-callout/blob/main/src/index.ts 130 130 const calloutRegex = new RegExp(/^\[\!(\w+)\]([+-]?)/) 131 131 const calloutLineRegex = new RegExp(/^> *\[\!\w+\][+-]?.*$/, "gm") ··· 151 151 return { 152 152 name: "ObsidianFlavoredMarkdown", 153 153 textTransform(_ctx, src) { 154 + // do comments at text level 155 + if (opts.comments) { 156 + if (src instanceof Buffer) { 157 + src = src.toString() 158 + } 159 + 160 + src = src.replace(commentRegex, "") 161 + } 162 + 154 163 // pre-transform blockquotes 155 164 if (opts.callouts) { 156 165 if (src instanceof Buffer) { ··· 161 170 // force newline after title of callout 162 171 return value + "\n> " 163 172 }) 164 - } 165 - 166 - // do comments at text level 167 - if (opts.comments) { 168 - if (src instanceof Buffer) { 169 - src = src.toString() 170 - } 171 - src.replace(commentRegex, "") 172 173 } 173 174 174 175 // pre-transform wikilinks (fix anchors to things that may contain illegal syntax e.g. codeblocks, latex)