From e1f7366ee9246fab147ba894fd18272119f18ba7 Mon Sep 17 00:00:00 2001 From: Miguel Pimentel Date: Thu, 20 Jun 2024 17:46:04 +0000 Subject: [PATCH] pnpm run format --- README.md | 12 +- content/2023-06-26-unlock-firefox-sidebar.md | 1 + content/CSS.md | 4 +- content/Data.md | 1 + quartz.config.ts | 2 +- quartz.layout.ts | 10 +- quartz/components/ExplorerNode.tsx | 3 +- quartz/components/pages/404.tsx | 12 +- quartz/i18n/index.ts | 7 +- quartz/i18n/locales/de-DE.ts | 31 ++-- quartz/i18n/locales/fa-IR.ts | 22 +-- quartz/i18n/locales/pl-PL.ts | 26 +-- quartz/plugins/transformers/ofm.ts | 180 +++++++++++++------ 13 files changed, 197 insertions(+), 114 deletions(-) diff --git a/README.md b/README.md index c7b84ef80..128bb0073 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,10 @@ # 🌱 Forgetful Notes -![code size](https://img.shields.io/github/languages/code-size/semanticdata/forgetful-notes) -![repository size](https://img.shields.io/github/repo-size/semanticdata/forgetful-notes) -![commits](https://img.shields.io/github/commit-activity/t/semanticdata/forgetful-notes) -![last commit](https://img.shields.io/github/last-commit/semanticdata/forgetful-notes) -![is website up?](https://img.shields.io/website/https/forgetfulnotes.com.svg) +![code size](https://img.shields.io/github/languages/code-size/semanticdata/forgetful-notes) ![repository size](https://img.shields.io/github/repo-size/semanticdata/forgetful-notes) ![commits](https://img.shields.io/github/commit-activity/t/semanticdata/forgetful-notes) ![last commit](https://img.shields.io/github/last-commit/semanticdata/forgetful-notes) ![is website up?](https://img.shields.io/website/https/forgetfulnotes.com.svg) [Forgetful Notes](https://forgetfulnotes.com) is my _digital garden_ of knowledge. It serves as a platform for my learning and creative endeavours. A space for thinking through, building upon, and coming back to. -[![Github Pages](https://img.shields.io/badge/github%20pages-121013?style=for-the-badge&logo=github&logoColor=white)](https://forgetfulnotes.com/) -[![Vercel](https://img.shields.io/badge/vercel-%23000000.svg?style=for-the-badge&logo=vercel&logoColor=white)](https://forgetful-notes.vercel.app/) +[![Github Pages](https://img.shields.io/badge/github%20pages-121013?style=for-the-badge&logo=github&logoColor=white)](https://forgetfulnotes.com/) [![Vercel](https://img.shields.io/badge/vercel-%23000000.svg?style=for-the-badge&logo=vercel&logoColor=white)](https://forgetful-notes.vercel.app/) ## ✨ Features @@ -65,7 +60,7 @@ npx quartz --help You can add custom CSS code within `/quartz/styles/custom.scss`. You will then need to uncomment line 4 of `/quartz/styles/base.scss` to have it take effect. | Used in: | Font Family | Previous Font | -| --- | :---: | :---: | +| --- | :-: | :-: | | Headers | [Bitter](https://fonts.google.com/specimen/Bitter) | [Schibsted Grotesk](https://fonts.google.com/specimen/Schibsted+Grotesk) | | Body | [Poppins](https://fonts.google.com/specimen/Poppins) | [Source Sans Pro](https://fonts.google.com/specimen/Source+Sans+3) | | Code | [Fira Mono](https://fonts.google.com/specimen/Fira+Mono) | [IBM Plex Mono](https://fonts.google.com/specimen/IBM+Plex+Mono) | @@ -85,7 +80,6 @@ All content for the site is written in _Markdown_ within [Obsidian](https://obsi ### 🔨 Build only - ```yml steps: - uses: actions/checkout@v4 diff --git a/content/2023-06-26-unlock-firefox-sidebar.md b/content/2023-06-26-unlock-firefox-sidebar.md index 7c4d4599b..5978a4e94 100644 --- a/content/2023-06-26-unlock-firefox-sidebar.md +++ b/content/2023-06-26-unlock-firefox-sidebar.md @@ -48,4 +48,5 @@ toolkit.legacyUserProfileCustomizations.stylesheets 2. Restart Firefox and test it out! [^1]: In windows, `%appdata%` is equivalent to `C:\Users\{username}\AppData\Roaming`. + [^2]: After Firefox 107, `#sidebar` was deprecated, and `#sidebar-box` was introduced as a replacement. diff --git a/content/CSS.md b/content/CSS.md index efe39a8b0..d6b9dc103 100644 --- a/content/CSS.md +++ b/content/CSS.md @@ -59,9 +59,9 @@ All _mobile-first-designs_ media queries and 1 _desktop-first-design_ media quer ------------------------------------------------------------------ // USING THE MIXINS // Example - Writing a custom bootstrap-like container from scratch ------------------------------------------------------------------- +--- -.container { +--------------------------------------------------------------- .container { margin: 0 auto; width: 100%; @include screen-min(768px) { diff --git a/content/Data.md b/content/Data.md index 1584dadd5..2aba04ef3 100644 --- a/content/Data.md +++ b/content/Data.md @@ -15,4 +15,5 @@ Relational data uses a structure and language consistent with first-order predic The purpose of the relational model is to provide a declarative method for specifying data and queries: users directly state what information the database contains and what information they want from it, and let the database management system software take care of describing data structures for storing the data and retrieval procedures for answering queries. [^1]: First-order logic—also known as first-order predicate calculus—is a collection of formal systems used in mathematics, philosophy, linguistics, and computer science. + [^2]: In mathematics, a tuple is a finite sequence or ordered list of numbers or, more generally, mathematical objects, which are called the elements of the tuple. diff --git a/quartz.config.ts b/quartz.config.ts index b0023e130..39103331a 100644 --- a/quartz.config.ts +++ b/quartz.config.ts @@ -68,7 +68,7 @@ const config: QuartzConfig = { Plugin.TableOfContents(), Plugin.CrawlLinks({markdownLinkResolution: "shortest"}), Plugin.Description(), - Plugin.Latex({ renderEngine: "katex" }), + Plugin.Latex({renderEngine: "katex"}), ], filters: [Plugin.RemoveDrafts()], emitters: [ diff --git a/quartz.layout.ts b/quartz.layout.ts index 4663cf73f..70ae3eac4 100644 --- a/quartz.layout.ts +++ b/quartz.layout.ts @@ -1,5 +1,5 @@ -import { PageLayout, SharedLayout } from "./quartz/cfg"; -import * as Component from "./quartz/components"; +import {PageLayout, SharedLayout} from "./quartz/cfg" +import * as Component from "./quartz/components" // components shared across all pages export const sharedPageComponents: SharedLayout = { @@ -14,7 +14,7 @@ export const sharedPageComponents: SharedLayout = { GitHub: "https://github.com/semanticdata/forgetful-notes/", }, }), -}; +} // components for pages that display a single page (e.g. a single note) export const defaultContentPageLayout: PageLayout = { @@ -50,7 +50,7 @@ export const defaultContentPageLayout: PageLayout = { // Component.DesktopOnly(Component.TableOfContents()), // Component.Backlinks(), // ], -}; +} // components for pages that display lists of pages (e.g. tags or folders) export const defaultListPageLayout: PageLayout = { @@ -73,4 +73,4 @@ export const defaultListPageLayout: PageLayout = { // Component.DesktopOnly(Component.Explorer()), // ], // right: [], -}; +} diff --git a/quartz/components/ExplorerNode.tsx b/quartz/components/ExplorerNode.tsx index 9cddd36b4..9ae800ee5 100644 --- a/quartz/components/ExplorerNode.tsx +++ b/quartz/components/ExplorerNode.tsx @@ -183,7 +183,8 @@ export function ExplorerNode({ const isDefaultOpen = opts.folderDefaultState === "open" // Calculate current folderPath - const folderPath = node.name !== "" ? joinSegments(fullPath ?? "", node.name) : "" + const folderPath = + node.name !== "" ? joinSegments(fullPath ?? "", node.name) : "" const href = resolveRelative(fileData.slug!, folderPath as SimpleSlug) + "/" return ( diff --git a/quartz/components/pages/404.tsx b/quartz/components/pages/404.tsx index 2076ad7d1..1acd5aa7e 100644 --- a/quartz/components/pages/404.tsx +++ b/quartz/components/pages/404.tsx @@ -1,7 +1,11 @@ -import { i18n } from "../../i18n" -import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "../types" +import {i18n} from "../../i18n" +import { + QuartzComponent, + QuartzComponentConstructor, + QuartzComponentProps, +} from "../types" -const NotFound: QuartzComponent = ({ cfg }: QuartzComponentProps) => { +const NotFound: QuartzComponent = ({cfg}: QuartzComponentProps) => { // If baseUrl contains a pathname after the domain, use this as the home link const url = new URL(`https://${cfg.baseUrl ?? "example.com"}`) const baseDir = url.pathname @@ -15,4 +19,4 @@ const NotFound: QuartzComponent = ({ cfg }: QuartzComponentProps) => { ) } -export default (() => NotFound) satisfies QuartzComponentConstructor \ No newline at end of file +export default (() => NotFound) satisfies QuartzComponentConstructor diff --git a/quartz/i18n/index.ts b/quartz/i18n/index.ts index c2574437a..9719ca0a7 100644 --- a/quartz/i18n/index.ts +++ b/quartz/i18n/index.ts @@ -1,4 +1,4 @@ -import { Translation, CalloutTranslation } from "./locales/definition" +import {Translation, CalloutTranslation} from "./locales/definition" import en from "./locales/en-US" import fr from "./locales/fr-FR" import it from "./locales/it-IT" @@ -61,6 +61,7 @@ export const TRANSLATIONS = { } as const export const defaultTranslation = "en-US" -export const i18n = (locale: ValidLocale): Translation => TRANSLATIONS[locale ?? defaultTranslation] +export const i18n = (locale: ValidLocale): Translation => + TRANSLATIONS[locale ?? defaultTranslation] export type ValidLocale = keyof typeof TRANSLATIONS -export type ValidCallout = keyof CalloutTranslation \ No newline at end of file +export type ValidCallout = keyof CalloutTranslation diff --git a/quartz/i18n/locales/de-DE.ts b/quartz/i18n/locales/de-DE.ts index 3bda7c78c..a0ec85c45 100644 --- a/quartz/i18n/locales/de-DE.ts +++ b/quartz/i18n/locales/de-DE.ts @@ -1,4 +1,4 @@ -import { Translation } from "./definition" +import {Translation} from "./definition" export default { propertyDefaults: { @@ -40,10 +40,10 @@ export default { }, recentNotes: { title: "Zuletzt bearbeitete Seiten", - seeRemainingMore: ({ remaining }) => `${remaining} weitere ansehen →`, + seeRemainingMore: ({remaining}) => `${remaining} weitere ansehen →`, }, transcludes: { - transcludeOf: ({ targetSlug }) => `Transklusion von ${targetSlug}`, + transcludeOf: ({targetSlug}) => `Transklusion von ${targetSlug}`, linkToOriginal: "Link zum Original", }, search: { @@ -54,31 +54,36 @@ export default { title: "Inhaltsverzeichnis", }, contentMeta: { - readingTime: ({ minutes }) => `${minutes} min read`, + readingTime: ({minutes}) => `${minutes} min read`, }, }, pages: { rss: { recentNotes: "Zuletzt bearbeitete Seiten", - lastFewNotes: ({ count }) => `Letzte ${count} Seiten`, + lastFewNotes: ({count}) => `Letzte ${count} Seiten`, }, error: { title: "Nicht gefunden", - notFound: "Diese Seite ist entweder nicht öffentlich oder existiert nicht.", + notFound: + "Diese Seite ist entweder nicht öffentlich oder existiert nicht.", home: "Return to Homepage", }, folderContent: { folder: "Ordner", - itemsUnderFolder: ({ count }) => - count === 1 ? "1 Datei in diesem Ordner." : `${count} Dateien in diesem Ordner.`, + itemsUnderFolder: ({count}) => + count === 1 + ? "1 Datei in diesem Ordner." + : `${count} Dateien in diesem Ordner.`, }, tagContent: { tag: "Tag", tagIndex: "Tag-Übersicht", - itemsUnderTag: ({ count }) => - count === 1 ? "1 Datei mit diesem Tag." : `${count} Dateien mit diesem Tag.`, - showingFirst: ({ count }) => `Die ersten ${count} Tags werden angezeigt.`, - totalTags: ({ count }) => `${count} Tags insgesamt.`, + itemsUnderTag: ({count}) => + count === 1 + ? "1 Datei mit diesem Tag." + : `${count} Dateien mit diesem Tag.`, + showingFirst: ({count}) => `Die ersten ${count} Tags werden angezeigt.`, + totalTags: ({count}) => `${count} Tags insgesamt.`, }, }, -} as const satisfies Translation \ No newline at end of file +} as const satisfies Translation diff --git a/quartz/i18n/locales/fa-IR.ts b/quartz/i18n/locales/fa-IR.ts index 5bfef5aee..5172d2cb8 100644 --- a/quartz/i18n/locales/fa-IR.ts +++ b/quartz/i18n/locales/fa-IR.ts @@ -1,4 +1,4 @@ -import { Translation } from "./definition" +import {Translation} from "./definition" export default { propertyDefaults: { @@ -40,10 +40,10 @@ export default { }, recentNotes: { title: "یادداشت‌های اخیر", - seeRemainingMore: ({ remaining }) => `${remaining} یادداشت دیگر →`, + seeRemainingMore: ({remaining}) => `${remaining} یادداشت دیگر →`, }, transcludes: { - transcludeOf: ({ targetSlug }) => `از ${targetSlug}`, + transcludeOf: ({targetSlug}) => `از ${targetSlug}`, linkToOriginal: "پیوند به اصلی", }, search: { @@ -54,13 +54,13 @@ export default { title: "فهرست", }, contentMeta: { - readingTime: ({ minutes }) => `زمان تقریبی مطالعه: ${minutes} دقیقه`, + readingTime: ({minutes}) => `زمان تقریبی مطالعه: ${minutes} دقیقه`, }, }, pages: { rss: { recentNotes: "یادداشت‌های اخیر", - lastFewNotes: ({ count }) => `${count} یادداشت اخیر`, + lastFewNotes: ({count}) => `${count} یادداشت اخیر`, }, error: { title: "یافت نشد", @@ -69,16 +69,18 @@ export default { }, folderContent: { folder: "پوشه", - itemsUnderFolder: ({ count }) => - count === 1 ? ".یک مطلب در این پوشه است" : `${count} مطلب در این پوشه است.`, + itemsUnderFolder: ({count}) => + count === 1 + ? ".یک مطلب در این پوشه است" + : `${count} مطلب در این پوشه است.`, }, tagContent: { tag: "برچسب", tagIndex: "فهرست برچسب‌ها", - itemsUnderTag: ({ count }) => + itemsUnderTag: ({count}) => count === 1 ? "یک مطلب با این برچسب" : `${count} مطلب با این برچسب.`, - showingFirst: ({ count }) => `در حال نمایش ${count} برچسب.`, - totalTags: ({ count }) => `${count} برچسب یافت شد.`, + showingFirst: ({count}) => `در حال نمایش ${count} برچسب.`, + totalTags: ({count}) => `${count} برچسب یافت شد.`, }, }, } as const satisfies Translation diff --git a/quartz/i18n/locales/pl-PL.ts b/quartz/i18n/locales/pl-PL.ts index 7fa0cd47a..b2b70a68b 100644 --- a/quartz/i18n/locales/pl-PL.ts +++ b/quartz/i18n/locales/pl-PL.ts @@ -1,4 +1,4 @@ -import { Translation } from "./definition" +import {Translation} from "./definition" export default { propertyDefaults: { @@ -40,10 +40,10 @@ export default { }, recentNotes: { title: "Najnowsze notatki", - seeRemainingMore: ({ remaining }) => `Zobacz ${remaining} nastepnych →`, + seeRemainingMore: ({remaining}) => `Zobacz ${remaining} nastepnych →`, }, transcludes: { - transcludeOf: ({ targetSlug }) => `Osadzone ${targetSlug}`, + transcludeOf: ({targetSlug}) => `Osadzone ${targetSlug}`, linkToOriginal: "Łącze do oryginału", }, search: { @@ -54,13 +54,13 @@ export default { title: "Spis treści", }, contentMeta: { - readingTime: ({ minutes }) => `${minutes} min. czytania `, + readingTime: ({minutes}) => `${minutes} min. czytania `, }, }, pages: { rss: { recentNotes: "Najnowsze notatki", - lastFewNotes: ({ count }) => `Ostatnie ${count} notatek`, + lastFewNotes: ({count}) => `Ostatnie ${count} notatek`, }, error: { title: "Nie znaleziono", @@ -69,16 +69,20 @@ export default { }, folderContent: { folder: "Folder", - itemsUnderFolder: ({ count }) => - count === 1 ? "W tym folderze jest 1 element." : `Elementów w folderze: ${count}.`, + itemsUnderFolder: ({count}) => + count === 1 + ? "W tym folderze jest 1 element." + : `Elementów w folderze: ${count}.`, }, tagContent: { tag: "Znacznik", tagIndex: "Spis znaczników", - itemsUnderTag: ({ count }) => - count === 1 ? "Oznaczony 1 element." : `Elementów z tym znacznikiem: ${count}.`, - showingFirst: ({ count }) => `Pokazuje ${count} pierwszych znaczników.`, - totalTags: ({ count }) => `Znalezionych wszystkich znaczników: ${count}.`, + itemsUnderTag: ({count}) => + count === 1 + ? "Oznaczony 1 element." + : `Elementów z tym znacznikiem: ${count}.`, + showingFirst: ({count}) => `Pokazuje ${count} pierwszych znaczników.`, + totalTags: ({count}) => `Znalezionych wszystkich znaczników: ${count}.`, }, }, } as const satisfies Translation diff --git a/quartz/plugins/transformers/ofm.ts b/quartz/plugins/transformers/ofm.ts index 51d2e654f..4eed3d4ad 100644 --- a/quartz/plugins/transformers/ofm.ts +++ b/quartz/plugins/transformers/ofm.ts @@ -1,23 +1,33 @@ -import { QuartzTransformerPlugin } from "../types" -import { Root, Html, BlockContent, DefinitionContent, Paragraph, Code } from "mdast" -import { Element, Literal, Root as HtmlRoot } from "hast" -import { ReplaceFunction, findAndReplace as mdastFindReplace } from "mdast-util-find-and-replace" -import { slug as slugAnchor } from "github-slugger" +import {QuartzTransformerPlugin} from "../types" +import { + Root, + Html, + BlockContent, + DefinitionContent, + Paragraph, + Code, +} from "mdast" +import {Element, Literal, Root as HtmlRoot} from "hast" +import { + ReplaceFunction, + findAndReplace as mdastFindReplace, +} from "mdast-util-find-and-replace" +import {slug as slugAnchor} from "github-slugger" import rehypeRaw from "rehype-raw" -import { SKIP, visit } from "unist-util-visit" +import {SKIP, visit} from "unist-util-visit" import path from "path" -import { splitAnchor } from "../../util/path" -import { JSResource } from "../../util/resources" +import {splitAnchor} from "../../util/path" +import {JSResource} from "../../util/resources" // @ts-ignore import calloutScript from "../../components/scripts/callout.inline.ts" // @ts-ignore import checkboxScript from "../../components/scripts/checkbox.inline.ts" -import { FilePath, pathToRoot, slugTag, slugifyFilePath } from "../../util/path" -import { toHast } from "mdast-util-to-hast" -import { toHtml } from "hast-util-to-html" -import { PhrasingContent } from "mdast-util-find-and-replace/lib" -import { capitalize } from "../../util/lang" -import { PluggableList } from "unified" +import {FilePath, pathToRoot, slugTag, slugifyFilePath} from "../../util/path" +import {toHast} from "mdast-util-to-hast" +import {toHtml} from "hast-util-to-html" +import {PhrasingContent} from "mdast-util-find-and-replace/lib" +import {capitalize} from "../../util/lang" +import {PluggableList} from "unified" export interface Options { comments: boolean @@ -91,7 +101,8 @@ const arrowMapping: Record = { } function canonicalizeCallout(calloutName: string): keyof typeof calloutMapping { - const normalizedCallout = calloutName.toLowerCase() as keyof typeof calloutMapping + const normalizedCallout = + calloutName.toLowerCase() as keyof typeof calloutMapping // if callout is not recognized, make it a custom one return calloutMapping[normalizedCallout] ?? calloutName } @@ -135,21 +146,24 @@ const tagRegex = new RegExp( "gu", ) const blockReferenceRegex = new RegExp(/\^([-_A-Za-z0-9]+)$/, "g") -const ytLinkRegex = /^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=)([^#\&\?]*).*/ +const ytLinkRegex = + /^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=)([^#\&\?]*).*/ const ytPlaylistLinkRegex = /[?&]list=([^#?&]*)/ -const videoExtensionRegex = new RegExp(/\.(mp4|webm|ogg|avi|mov|flv|wmv|mkv|mpg|mpeg|3gp|m4v)$/) +const videoExtensionRegex = new RegExp( + /\.(mp4|webm|ogg|avi|mov|flv|wmv|mkv|mpg|mpeg|3gp|m4v)$/, +) const wikilinkImageEmbedRegex = new RegExp( /^(?(?!^\d*x?\d*$).*?)?(\|?\s*?(?\d+)(x(?\d+))?)?$/, ) -export const ObsidianFlavoredMarkdown: QuartzTransformerPlugin | undefined> = ( - userOpts, -) => { - const opts = { ...defaultOptions, ...userOpts } +export const ObsidianFlavoredMarkdown: QuartzTransformerPlugin< + Partial | undefined +> = (userOpts) => { + const opts = {...defaultOptions, ...userOpts} const mdastToHtml = (ast: PhrasingContent | Paragraph) => { - const hast = toHast(ast, { allowDangerousHtml: true })! - return toHtml(hast, { allowDangerousHtml: true }) + const hast = toHast(ast, {allowDangerousHtml: true})! + return toHtml(hast, {allowDangerousHtml: true}) } return { @@ -202,7 +216,9 @@ export const ObsidianFlavoredMarkdown: QuartzTransformerPlugin const [fp, anchor] = splitAnchor(`${rawFp ?? ""}${rawHeader ?? ""}`) const blockRef = Boolean(anchor?.startsWith("^")) ? "^" : "" - const displayAnchor = anchor ? `#${blockRef}${anchor.trim().replace(/^#+/, "")}` : "" + const displayAnchor = anchor + ? `#${blockRef}${anchor.trim().replace(/^#+/, "")}` + : "" const displayAlias = rawAlias ?? rawHeader?.replace("#", "|") ?? "" const embedDisplay = value.startsWith("!") ? "!" : "" @@ -238,7 +254,17 @@ export const ObsidianFlavoredMarkdown: QuartzTransformerPlugin if (value.startsWith("!")) { const ext: string = path.extname(fp).toLowerCase() const url = slugifyFilePath(fp as FilePath) - if ([".png", ".jpg", ".jpeg", ".gif", ".bmp", ".svg", ".webp"].includes(ext)) { + if ( + [ + ".png", + ".jpg", + ".jpeg", + ".gif", + ".bmp", + ".svg", + ".webp", + ].includes(ext) + ) { const match = wikilinkImageEmbedRegex.exec(alias ?? "") const alt = match?.groups?.alt ?? "" const width = match?.groups?.width ?? "auto" @@ -254,13 +280,23 @@ export const ObsidianFlavoredMarkdown: QuartzTransformerPlugin }, }, } - } else if ([".mp4", ".webm", ".ogv", ".mov", ".mkv"].includes(ext)) { + } else if ( + [".mp4", ".webm", ".ogv", ".mov", ".mkv"].includes(ext) + ) { return { type: "html", value: ``, } } else if ( - [".mp3", ".webm", ".wav", ".m4a", ".ogg", ".3gp", ".flac"].includes(ext) + [ + ".mp3", + ".webm", + ".wav", + ".m4a", + ".ogg", + ".3gp", + ".flac", + ].includes(ext) ) { return { type: "html", @@ -275,7 +311,7 @@ export const ObsidianFlavoredMarkdown: QuartzTransformerPlugin const block = anchor return { type: "html", - data: { hProperties: { transclude: true } }, + data: {hProperties: {transclude: true}}, value: `
Transclude of ${url}${block}
`, @@ -368,18 +404,24 @@ export const ObsidianFlavoredMarkdown: QuartzTransformerPlugin if (typeof replace === "string") { node.value = node.value.replace(regex, replace) } else { - node.value = node.value.replace(regex, (substring: string, ...args) => { - const replaceValue = replace(substring, ...args) - if (typeof replaceValue === "string") { - return replaceValue - } else if (Array.isArray(replaceValue)) { - return replaceValue.map(mdastToHtml).join("") - } else if (typeof replaceValue === "object" && replaceValue !== null) { - return mdastToHtml(replaceValue) - } else { - return substring - } - }) + node.value = node.value.replace( + regex, + (substring: string, ...args) => { + const replaceValue = replace(substring, ...args) + if (typeof replaceValue === "string") { + return replaceValue + } else if (Array.isArray(replaceValue)) { + return replaceValue.map(mdastToHtml).join("") + } else if ( + typeof replaceValue === "object" && + replaceValue !== null + ) { + return mdastToHtml(replaceValue) + } else { + return substring + } + }, + ) } } }) @@ -392,7 +434,11 @@ export const ObsidianFlavoredMarkdown: QuartzTransformerPlugin plugins.push(() => { return (tree: Root, _file) => { visit(tree, "image", (node, index, parent) => { - if (parent && index != undefined && videoExtensionRegex.test(node.url)) { + if ( + parent && + index != undefined && + videoExtensionRegex.test(node.url) + ) { const newNode: Html = { type: "html", value: ``, @@ -416,7 +462,10 @@ export const ObsidianFlavoredMarkdown: QuartzTransformerPlugin // find first line and callout content const [firstChild, ...calloutContent] = node.children - if (firstChild.type !== "paragraph" || firstChild.children[0]?.type !== "text") { + if ( + firstChild.type !== "paragraph" || + firstChild.children[0]?.type !== "text" + ) { return } @@ -427,18 +476,31 @@ export const ObsidianFlavoredMarkdown: QuartzTransformerPlugin const match = firstLine.match(calloutRegex) if (match && match.input) { - const [calloutDirective, typeString, calloutMetaData, collapseChar] = match - const calloutType = canonicalizeCallout(typeString.toLowerCase()) + const [ + calloutDirective, + typeString, + calloutMetaData, + collapseChar, + ] = match + const calloutType = canonicalizeCallout( + typeString.toLowerCase(), + ) const collapse = collapseChar === "+" || collapseChar === "-" - const defaultState = collapseChar === "-" ? "collapsed" : "expanded" - const titleContent = match.input.slice(calloutDirective.length).trim() - const useDefaultTitle = titleContent === "" && restOfTitle.length === 0 + const defaultState = + collapseChar === "-" ? "collapsed" : "expanded" + const titleContent = match.input + .slice(calloutDirective.length) + .trim() + const useDefaultTitle = + titleContent === "" && restOfTitle.length === 0 const titleNode: Paragraph = { type: "paragraph", children: [ { type: "text", - value: useDefaultTitle ? capitalize(typeString) : titleContent + " ", + value: useDefaultTitle + ? capitalize(typeString) + : titleContent + " ", }, ...restOfTitle, ], @@ -458,7 +520,8 @@ export const ObsidianFlavoredMarkdown: QuartzTransformerPlugin `, } - const blockquoteContent: (BlockContent | DefinitionContent)[] = [titleHtml] + const blockquoteContent: (BlockContent | DefinitionContent)[] = + [titleHtml] if (remainingText.length > 0) { blockquoteContent.push({ type: "paragraph", @@ -486,7 +549,7 @@ export const ObsidianFlavoredMarkdown: QuartzTransformerPlugin node.data = { hProperties: { ...(node.data?.hProperties ?? {}), - className: classNames.join(" "), + "className": classNames.join(" "), "data-callout": calloutType, "data-callout-fold": collapse, "data-callout-metadata": calloutMetaData, @@ -614,10 +677,14 @@ export const ObsidianFlavoredMarkdown: QuartzTransformerPlugin plugins.push(() => { return (tree: HtmlRoot) => { visit(tree, "element", (node) => { - if (node.tagName === "img" && typeof node.properties.src === "string") { + if ( + node.tagName === "img" && + typeof node.properties.src === "string" + ) { const match = node.properties.src.match(ytLinkRegex) const videoId = match && match[2].length == 11 ? match[2] : null - const playlistId = node.properties.src.match(ytPlaylistLinkRegex)?.[1] + const playlistId = + node.properties.src.match(ytPlaylistLinkRegex)?.[1] if (videoId) { // YouTube video (with optional playlist) node.tagName = "iframe" @@ -653,7 +720,10 @@ export const ObsidianFlavoredMarkdown: QuartzTransformerPlugin plugins.push(() => { return (tree: HtmlRoot, _file) => { visit(tree, "element", (node) => { - if (node.tagName === "input" && node.properties.type === "checkbox") { + if ( + node.tagName === "input" && + node.properties.type === "checkbox" + ) { const isChecked = node.properties?.checked ?? false node.properties = { type: "checkbox", @@ -715,7 +785,7 @@ export const ObsidianFlavoredMarkdown: QuartzTransformerPlugin }) } - return { js } + return {js} }, } } @@ -725,4 +795,4 @@ declare module "vfile" { blocks: Record htmlAst: HtmlRoot } -} \ No newline at end of file +}