Skip to content

Commit

Permalink
feat: enable rendering of definition list
Browse files Browse the repository at this point in the history
pulldown-cmark markdown parser added support for definition lists in
https://github.com/pulldown-cmark/pulldown-cmark/releases/tag/v0.12.0

Parsing of definition lists using zola is optional and can be enabled
using configuration variable `definition_list = true` (default is
false).

Closes #2718
  • Loading branch information
matthiasschaub committed Jan 5, 2025
1 parent 4e392f2 commit a119420
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 0 deletions.
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 definition list 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
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

0 comments on commit a119420

Please sign in to comment.