Skip to content

Commit

Permalink
feat: Enabled markdown extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
rochacbruno committed Oct 21, 2024
1 parent 6f832aa commit 27e77ed
Show file tree
Hide file tree
Showing 4 changed files with 198 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
175 changes: 170 additions & 5 deletions example/content/first-blog-post.md
Original file line number Diff line number Diff line change
Expand Up @@ -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! <ul><li>Item one.</li><li>Item two.</li></ul> |


### Autolink

https://github.com/rochacbruno/marmite
[A link with a tooltip](https://pudim.com.br "A picture of a pudim")
<https://www.markdownguide.org>
<[email protected]>

### 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
Expand All @@ -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]: <https://en.wikipedia.org/wiki/Hobbit#Lifestyle> "Hobbit lifestyles"
9 changes: 9 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
check:
cargo fmt -- --check
cargo clippy -- -W clippy::pedantic

fmt:
cargo fmt

fix:
cargo clippy --fix -- -W clippy::pedantic
18 changes: 18 additions & 0 deletions src/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 27e77ed

Please sign in to comment.