Merge 7e04bb4e6e42d4d7ac8c021b3a63c37e322a7300 into dd6bd498db25344b2cccf56abfb656576a496d38

This commit is contained in:
SafEight 2025-02-23 23:03:08 +00:00 committed by GitHub
commit 36eee3b139
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 34 additions and 0 deletions

View File

@ -23,6 +23,7 @@ This plugin accepts the following configuration options:
- `enableYouTubeEmbed`: If `true` (default), enables the embedding of YouTube videos and playlists using external image Markdown syntax.
- `enableVideoEmbed`: If `true` (default), enables the embedding of video files.
- `enableCheckbox`: If `true`, adds support for interactive checkboxes in content. Defaults to `false`.
- `inlineFootnotes`: If `true` (default), enables parsing of inline footnotes.
> [!warning]
> Don't remove this plugin if you're using [[Obsidian compatibility|Obsidian]] to author the content!

View File

@ -38,6 +38,7 @@ export interface Options {
enableYouTubeEmbed: boolean
enableVideoEmbed: boolean
enableCheckbox: boolean
inlineFootnotes: boolean
}
const defaultOptions: Options = {
@ -53,6 +54,7 @@ const defaultOptions: Options = {
enableYouTubeEmbed: true,
enableVideoEmbed: true,
enableCheckbox: false,
inlineFootnotes: true,
}
const calloutMapping = {
@ -143,6 +145,8 @@ const wikilinkImageEmbedRegex = new RegExp(
/^(?<alt>(?!^\d*x?\d*$).*?)?(\|?\s*?(?<width>\d+)(x(?<height>\d+))?)?$/,
)
const inlineFootnoteRegex = /\^\[((?:[^\[\]]|\[(?:[^\[\]]|\[[^\[\]]*\])*\])*)\]/g
export const ObsidianFlavoredMarkdown: QuartzTransformerPlugin<Partial<Options>> = (userOpts) => {
const opts = { ...defaultOptions, ...userOpts }
@ -213,6 +217,35 @@ export const ObsidianFlavoredMarkdown: QuartzTransformerPlugin<Partial<Options>>
})
}
if (opts.inlineFootnotes) {
// Replaces ^[inline] footnotes with regular footnotes [^1]:
const footnotes: Record<string, string> = {}
// Replace inline footnotes with references and collect definitions
const result = (src as string).replace(
inlineFootnoteRegex,
(_match: string, content: string) => {
const id = `inline-${Object.keys(footnotes).length + 1}`
footnotes[id] = content.trim()
return `[^${id}]`
},
)
// Append footnote definitions if any are found
if (Object.keys(footnotes).length > 0) {
return (
result +
"\n\n" +
Object.entries(footnotes)
.map(([id, content]) => `[^${id}]: ${content}`)
.join("\n") +
"\n"
)
}
return result
}
return src
},
markdownPlugins(_ctx) {