plugins: add float image syntax

This commit is contained in:
2026-03-29 02:06:53 +00:00
parent be63b52265
commit 30c8ec7438
3 changed files with 38 additions and 0 deletions
+1
View File
@@ -57,6 +57,7 @@ const config: QuartzConfig = {
},
plugins: {
transformers: [
Plugin.FloatImages(),
Plugin.FrontMatter(),
Plugin.CreatedModifiedDate({
priority: ["frontmatter", "git", "filesystem"],
@@ -0,0 +1,36 @@
/*
my own custom syntax to do floating inline images
*/
import { QuartzTransformerPlugin } from "../types"
export const FloatImages: QuartzTransformerPlugin = () => {
return {
name: "float-images",
textTransform: (_, src) => {
/*
my syntax is based on the wiki style
![[https://example.com/image.png]]{float-left}
![[https://example.com/image.png]]{float-right 40%}
percentage is optional, default is 40%
*/
const regex = /!\[\[([^\]]+)\]\]\{(float-left|float-right)(?:\s+(\d+)%?)?\}/g
return src.replace(regex, (_, src, float, width) => {
width = width || "40" // default
const direction = float === "float-left" ? "left" : "right"
const margin = float === "float-left" ? "0 2rem 0 0" : "0 0 0 2rem"
// TODO YOU CAN MAKE THIS BETTER BY USING AND NOT INLINE STYLES
// do NOT try to tab align the following code, otherwise it renders as code instead of html parse
return `
<div class="floating-image" style="float: ${direction}; margin: ${margin}; max-width: ${width}%;">
<img style="margin: 0;" src=${src}>
<img style="margin: 0;" src=${src}>
</div>
`
})
},
}
}
+1
View File
@@ -11,3 +11,4 @@ export { SyntaxHighlighting } from "./syntax"
export { TableOfContents } from "./toc"
export { HardLineBreaks } from "./linebreaks"
export { RoamFlavoredMarkdown } from "./roam"
export { FloatImages } from "./float-images"