From 01e5f71058d9cfd5a467f1fded96b3c050d4ce11 Mon Sep 17 00:00:00 2001 From: Marvin Hagemeister Date: Fri, 6 Oct 2023 22:56:11 +0200 Subject: [PATCH] docs: improve admonition styles (#1880) --- docs/canary/examples/modifying-the-head.md | 3 +- docs/latest/concepts/ahead-of-time-builds.md | 6 +-- docs/latest/concepts/routing.md | 5 +- docs/latest/getting-started/create-a-route.md | 2 +- www/routes/gfm.css.ts | 54 +++++++++++++++++++ www/static/icons.svg | 26 +++++++++ www/utils/markdown.ts | 21 ++++++++ 7 files changed, 110 insertions(+), 7 deletions(-) create mode 100644 www/static/icons.svg diff --git a/docs/canary/examples/modifying-the-head.md b/docs/canary/examples/modifying-the-head.md index c73ca71f..ba1d2d04 100644 --- a/docs/canary/examples/modifying-the-head.md +++ b/docs/canary/examples/modifying-the-head.md @@ -75,4 +75,5 @@ rendered. The rendered page will only include the ``-tag with `"Other title"`. -> ℹ️ The ``-tag is automatically deduplicated, even without a `key` prop. +> [info]: The `<title>`-tag is automatically deduplicated, even without a `key` +> prop. diff --git a/docs/latest/concepts/ahead-of-time-builds.md b/docs/latest/concepts/ahead-of-time-builds.md index e569f067..5ee4436c 100644 --- a/docs/latest/concepts/ahead-of-time-builds.md +++ b/docs/latest/concepts/ahead-of-time-builds.md @@ -30,9 +30,9 @@ This will create a `_fresh` folder in the project directory. That folder contains the optimized assets and a `snapshot.json` file which includes some metadata for Fresh. -> ℹ️ The `_fresh` folder should not be committed to the repository. Add an entry -> in the `.gitignore` file to ensure that it is not committed. Create that file -> at the root of your git repository if not present. +> [info]: The `_fresh` folder should not be committed to the repository. Add an +> entry in the `.gitignore` file to ensure that it is not committed. Create that +> file at the root of your git repository if not present. > > ```gitignore .gitignore > # Ignore fresh build directory diff --git a/docs/latest/concepts/routing.md b/docs/latest/concepts/routing.md index 0e9f832d..7aa73fe5 100644 --- a/docs/latest/concepts/routing.md +++ b/docs/latest/concepts/routing.md @@ -97,8 +97,9 @@ a folder and use a different `_layout` file for each group.    └── contact.tsx ``` -> ℹ️ Be careful about routes in different groups which match to the same URL. -> Such scenarios will lead to ambiguity as to which route file should be picked. +> [warn]: Be careful about routes in different groups which match to the same +> URL. Such scenarios will lead to ambiguity as to which route file should be +> picked. > > ```txt Project structure > └── routes diff --git a/docs/latest/getting-started/create-a-route.md b/docs/latest/getting-started/create-a-route.md index b5f6dec4..0356f5ff 100644 --- a/docs/latest/getting-started/create-a-route.md +++ b/docs/latest/getting-started/create-a-route.md @@ -29,7 +29,7 @@ this, one needs to create a new `routes/about.tsx` file. In this file, we can declare a component that should be rendered every time a user visits the page. This is done with JSX. -> ℹ️ To learn more about JSX, you can read [this article][jsx] in the React +> [info]: To learn more about JSX, you can read [this article][jsx] in the React > documentation. Beware that Fresh does not use React, but rather > [Preact][preact], a lighter weight virtual dom library that works similar to > React. diff --git a/www/routes/gfm.css.ts b/www/routes/gfm.css.ts index 9f55c884..e35e4a65 100644 --- a/www/routes/gfm.css.ts +++ b/www/routes/gfm.css.ts @@ -37,6 +37,60 @@ const CSS = css`${gfm.CSS} margin-left: 0 } +.markdown-body .admonition { + padding: 1rem; +} +.markdown-body .admonition-header { + font-weight: bold; + display: flex; + align-items: center; + font-size: 1rem; + padding-bottom: .5rem; +} +.markdown-body .admonition .icon { + display: inline-flex; + margin-right: .25rem; + width: 1.2em; + height: 1.2em; +} +.markdown-body blockquote.warn { + border-color: #ff9100; + background: #F0900525; +} + +.markdown-body .admonition .fenced-code { + margin-left: 0; + margin-right: 0; + border: 1px solid #d9d2d2; + border-radius: .5rem .5rem .25rem .25rem; +} + +.markdown-body .admonition .highlight { + margin-bottom: 0; +} + +.markdown-body .admonition.tip .admonition-header { + color: rgb(0, 148, 0); +} +.markdown-body .admonition.tip { + background-color: rgb(230, 246, 230); + border-color: rgb(0, 148, 0); +} +.markdown-body .admonition.info .admonition-header { + color: rgb(25 146 184); +} +.markdown-body .admonition.info { + background-color: rgb(238, 249, 253); + border-color: rgb(25 146 184); +} +.markdown-body .admonition.warn .admonition-header { + color: #dd6f04; +} +.markdown-body .admonition.warn { + background-color: #F0900525; + border-color: #ff9100; +} + @media screen and (min-width: 768px) { .markdown-body .fenced-code, .markdown-body table { diff --git a/www/static/icons.svg b/www/static/icons.svg new file mode 100644 index 00000000..18a2e474 --- /dev/null +++ b/www/static/icons.svg @@ -0,0 +1,26 @@ +<svg xmlns="http://www.w3.org/2000/svg"> + <symbol id="tip" viewBox="0 0 24 24"> + <g stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"> + <path stroke="none" d="M0 0h24v24H0z" fill="none"/> + <path d="M3 12h1m8 -9v1m8 8h1m-15.4 -6.4l.7 .7m12.1 -.7l-.7 .7" /> + <path d="M9 16a5 5 0 1 1 6 0a3.5 3.5 0 0 0 -1 3a2 2 0 0 1 -4 0a3.5 3.5 0 0 0 -1 -3" /> + <path d="M9.7 17l4.6 0" /> + </g> + </symbol> + + <symbol id="info" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"> + <path stroke="none" d="M0 0h24v24H0z" fill="none"/> + <path d="M3 12a9 9 0 1 0 18 0a9 9 0 0 0 -18 0" /> + <path d="M12 9h.01" /> + <path d="M11 12h1v4h1" /> + </symbol> + + <symbol id="warn" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"> + <path stroke="none" d="M0 0h24v24H0z" fill="none"/> + <path d="M12 9v4" /> + <path d="M10.363 3.591l-8.106 13.534a1.914 1.914 0 0 0 1.636 2.871h16.214a1.914 1.914 0 0 0 1.636 -2.87l-8.106 -13.536a1.914 1.914 0 0 0 -3.274 0z" /> + <path d="M12 16h.01" /> + </symbol> +</svg> + + diff --git a/www/utils/markdown.ts b/www/utils/markdown.ts index 06e14c00..a1a3ec98 100644 --- a/www/utils/markdown.ts +++ b/www/utils/markdown.ts @@ -16,6 +16,8 @@ import { mangle } from "$marked-mangle"; Marked.marked.use(mangle()); +const ADMISSION_REG = /^<p>\[(info|warn|tip)\]:\s/; + class DefaultRenderer extends Marked.Renderer { text(text: string): string { // Smartypants typography enhancement @@ -97,6 +99,25 @@ class DefaultRenderer extends Marked.Renderer { out += `</div>`; return out; } + + blockquote(quote: string): string { + const match = quote.match(ADMISSION_REG); + console.log(match, quote); + if (match) { + const label: Record<string, string> = { + tip: "Tip", + warn: "Warning", + info: "Info", + }; + const type = match[1]; + quote = quote.slice(match[0].length); + const icon = `<svg class="icon"><use href="/icons.svg#${type}" /></svg>`; + return `<blockquote class="admonition ${type}">\n<span class="admonition-header">${icon}${ + label[type] + }</span>${quote}</blockquote>\n`; + } + return `<blockquote>\n${quote}</blockquote>\n`; + } } export interface MarkdownOptions {