diff --git a/quartz.config.ts b/quartz.config.ts index 4d53906..9b7760a 100644 --- a/quartz.config.ts +++ b/quartz.config.ts @@ -57,6 +57,7 @@ const config: QuartzConfig = { }, plugins: { transformers: [ + Plugin.FloatImages(), Plugin.FrontMatter(), Plugin.CreatedModifiedDate({ priority: ["frontmatter", "git", "filesystem"], diff --git a/quartz/plugins/transformers/float-images.ts b/quartz/plugins/transformers/float-images.ts new file mode 100644 index 0000000..23d8449 --- /dev/null +++ b/quartz/plugins/transformers/float-images.ts @@ -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 ` +
+ + +
+ ` + }) + }, + } +} diff --git a/quartz/plugins/transformers/index.ts b/quartz/plugins/transformers/index.ts index 8e2cd84..c7696c8 100644 --- a/quartz/plugins/transformers/index.ts +++ b/quartz/plugins/transformers/index.ts @@ -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"