From 27e77ed06dd80c75b74430d2008a03edee230a64 Mon Sep 17 00:00:00 2001 From: Bruno Rocha Date: Mon, 21 Oct 2024 17:47:02 +0100 Subject: [PATCH] feat: Enabled markdown extensions --- Cargo.toml | 2 +- example/content/first-blog-post.md | 175 ++++++++++++++++++++++++++++- justfile | 9 ++ src/markdown.rs | 18 +++ 4 files changed, 198 insertions(+), 6 deletions(-) create mode 100644 justfile diff --git a/Cargo.toml b/Cargo.toml index 79567ce..687968c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,7 +13,7 @@ keywords = ["web", "blog", "static", "site", "html"] serde = { version = "1.0", features = ["derive"] } serde_yaml = "0.9" tera = "1.20" -comrak = "0.29" +comrak = {version = "*", features = ["shortcodes"]} walkdir = "2.5" chrono = { version = "0.4", features = ["serde"] } frontmatter-gen = "0.0.2" diff --git a/example/content/first-blog-post.md b/example/content/first-blog-post.md index 11524d6..0dcddd6 100644 --- a/example/content/first-blog-post.md +++ b/example/content/first-blog-post.md @@ -2,23 +2,184 @@ date: 2024-01-01 12:00:01 slug: blog-post title: Markdown Powered Blog Post (with code blocks) -tags: markdown, python, rust, another tag +tags: markdown, python, rust, Common Mark --- # This is the post content -The content here accepts any valid `CommonMark` or **Github** _Flavoured_ markdown. +The content here accepts any valid `CommonMark` or **Github** _Flavoured_ markdown +and some `micromark` extensions. -You can add: +Simple paragraph and usual formatting like **bold**,__underline__,*italic* +and also all sorts of formatting elements. + +### lists - lists + - sub item - images + * other - tables - Formatting -## Subtitles +Numbered + +1. First item +1. Second item + - Indented unordered item + - Indented unordered item +1. Third item + 1. Indented ordered item + 1. Indented ordered item +1. Fourth item + +Starting lists with numbers requires a `number\` + +- 1983\. A great year! +- I think 1984 was second best. + +### Images + + +Photo +![Photo](./media/marmite.jpg) + +Same but containing a tooltip if you hover the mouse on +![Photo](./media/marmite.jpg "A jar of Marmite") + + +### Symbols + + + Copyright (©) — © + Registered trademark (®) — ® + Trademark (™) — ™ + Euro (€) — € + Left arrow (←) — ← + Up arrow (↑) — ↑ + Right arrow (→) — → + Down arrow (↓) — ↓ + Degree (°) — ° + Pi (π) — π + +This is a ©left material. + +### Strike + +The folling is now ~~not valid~~ anymore. + +### Table + + +| String | g | 颪 | 🦀 | +|---------|----------|----------------------------|-------------------------------------| +| Unicode | 103 | 39082 | 129408 | +| Binary | 01100111 | 11101001 10100010 10101010 | 11110000 10011111 10100110 10000000 | + +Lists Within Table Cells + +You can add a list within a table cell by using HTML tags. + +| Syntax | Description | +| ----------- | ----------- | +| Header | Title | +| List | Here's a list! | + + +### Autolink + +https://github.com/rochacbruno/marmite +[A link with a tooltip](https://pudim.com.br "A picture of a pudim") + + + +### Task + +- [x] Task 1 +- [ ] Task 2 + +## Superscript + +80^2^ + +## Footnotes + +Here is a simple footnote[^1]. With some additional text after it. + +A reference[1] can also be hidden from footnotes. + +## Description lists -And also basic coding formatting. +First term + +: Details for the **first term** + +Second term + +: Details for the **second term** + + More details in second paragraph. + +## Block quote + +>No Quote +> quote +> > > Nested quote + +Multiline quote + +>>> +"Marmite is the easiest SSG" created by +Bruno Rocha with the contribution of various people. +>>> + +Multi paragraph quote + +> Dorothy followed her through many of the beautiful rooms in her castle. +> +> The Witch bade her clean the pots and kettles and sweep the floor and keep the fire fed with + +Rich quotes + +> #### The quarterly results look great! +> +> - Revenue was off the chart. +> - Profits were higher than ever. +> +> *Everything* is going according to **plan**. + + +## Emojis + +:smile: - :crab: - :snake: +``` +:smile: - :crab: - :snake: +``` + + +## Math + +Inline math $1 + 2$ and display math $$x + y$$ + +$$ +x^2 +$$ + +Inline math $`1 + 2`$ + +```math +x^2 +``` + +## Underline + +__dunder__ + +## Spoiler + +This is ||secret|| + +## Code ```python import antigravity @@ -38,3 +199,7 @@ fn main() { This post specifies `FrontMatter` on its header, so `title`, `slug`, `date` and tags are taken from there. Bye! + + +[^1]: My reference. +[1]: "Hobbit lifestyles" diff --git a/justfile b/justfile new file mode 100644 index 0000000..d71490b --- /dev/null +++ b/justfile @@ -0,0 +1,9 @@ +check: + cargo fmt -- --check + cargo clippy -- -W clippy::pedantic + +fmt: + cargo fmt + +fix: + cargo clippy --fix -- -W clippy::pedantic diff --git a/src/markdown.rs b/src/markdown.rs index 322ef1b..648405f 100644 --- a/src/markdown.rs +++ b/src/markdown.rs @@ -10,7 +10,25 @@ pub fn process_file(path: &Path, site_data: &mut Data) -> Result<(), String> { let (frontmatter, markdown) = parse_front_matter(&file_content)?; let mut options = ComrakOptions::default(); + + // TODO: Make the following options configurable? options.render.unsafe_ = true; // Allow raw html + options.extension.tagfilter = false; + options.extension.strikethrough = true; // ~~text~~ + options.extension.table = true; + options.extension.autolink = true; + options.extension.tasklist = true; // - [ ] item + options.extension.superscript = true; // 3^2^ + options.extension.footnotes = true; // note[^1] + options.extension.description_lists = true; + options.extension.multiline_block_quotes = true; // >>>\ntext\n>>> + options.extension.math_dollars = true; // depends on css + options.extension.math_code = true; // depends on css + options.extension.underline = true; // __under__ + options.extension.spoiler = true; // this is ||secret|| (depends on css) + options.extension.greentext = true; // >not a quote + options.extension.shortcodes = true; // >not a quote + let html = markdown_to_html(markdown, &options); let title = get_title(&frontmatter, markdown);