Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add optional parsing of definition lists #2763

Merged
merged 3 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- Exclude paginated pages in sitemap by default
- Allow treating a missing highlight language as error
- Handle more editors with change detection in `zola serve`
- Add optional parsing of Markdown definition lists


## 0.19.2 (2024-08-15)
Expand Down
3 changes: 3 additions & 0 deletions components/config/src/config/markup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ pub struct Markdown {
pub external_links_no_referrer: bool,
/// Whether smart punctuation is enabled (changing quotes, dashes, dots etc in their typographic form)
pub smart_punctuation: bool,
/// Whether parsing of definition lists is enabled
pub definition_list: bool,
/// Whether footnotes are rendered at the bottom in the style of GitHub.
pub bottom_footnotes: bool,
/// A list of directories to search for additional `.sublime-syntax` and `.tmTheme` files in.
Expand Down Expand Up @@ -227,6 +229,7 @@ impl Default for Markdown {
external_links_no_follow: false,
external_links_no_referrer: false,
smart_punctuation: false,
definition_list: false,
bottom_footnotes: false,
extra_syntaxes_and_themes: vec![],
extra_syntax_set: None,
Expand Down
2 changes: 1 addition & 1 deletion components/libs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ nom-bibtex = "0.5"
num-format = "0.4"
once_cell = "1"
percent-encoding = "2"
pulldown-cmark = { version = "0.11", default-features = false, features = ["html", "simd"] }
pulldown-cmark = { version = "0.12.2", default-features = false, features = ["html", "simd"] }
pulldown-cmark-escape = { version = "0.11", default-features = false }
quickxml_to_serde = "0.6"
rayon = "1"
Expand Down
3 changes: 3 additions & 0 deletions components/markdown/src/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,9 @@ pub fn markdown_to_html(
if context.config.markdown.smart_punctuation {
opts.insert(Options::ENABLE_SMART_PUNCTUATION);
}
if context.config.markdown.definition_list {
opts.insert(Options::ENABLE_DEFINITION_LIST);
}

// we reverse their order so we can pop them easily in order
let mut html_shortcodes: Vec<_> = html_shortcodes.into_iter().rev().collect();
Expand Down
12 changes: 12 additions & 0 deletions components/markdown/tests/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,18 @@ fn can_use_smart_punctuation() {
insta::assert_snapshot!(body);
}

#[test]
fn can_use_definition_list() {
let mut config = Config::default_for_test();
config.markdown.definition_list = true;
let content = r#"
term
: definition
"#;
let body = common::render_with_config(content, config).unwrap().body;
insta::assert_snapshot!(body);
}

#[test]
fn can_use_external_links_class() {
let mut config = Config::default_for_test();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
source: components/markdown/tests/markdown.rs
expression: body
---
<dl>
<dt>term</dt>
<dd>definition</dd>
</dl>
3 changes: 3 additions & 0 deletions docs/content/documentation/getting-started/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ external_links_no_referrer = false
# For example, `...` into `…`, `"quote"` into `“curly”` etc
smart_punctuation = false

# Whether parsing of definition lists is enabled
definition_list = false

# Whether to set decoding="async" and loading="lazy" for all images
# When turned on, the alt text must be plain text.
# For example, `![xx](...)` is ok but `![*x*x](...)` isn’t ok
Expand Down