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

fix front_matter_delimiter type #257

Merged
merged 6 commits into from
Oct 12, 2023
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
7 changes: 5 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,11 @@ build/

# for a library or gem, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .ruby-version
# .ruby-gemset
# as rbenv
.ruby-version
.ruby-gemset
# or ASDF-VM
.tool-versions

# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
.rvmrc
Expand Down
6 changes: 5 additions & 1 deletion ext/commonmarker/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,11 @@ fn iterate_extension_options(comrak_options: &mut ComrakOptions, options_hash: R
comrak_options.extension.description_lists = TryConvert::try_convert(value)?;
}
Ok(Cow::Borrowed(EXTENSION_FRONT_MATTER_DELIMITER)) => {
comrak_options.extension.front_matter_delimiter = try_convert_string(value);
if let Some(option) = try_convert_string(value) {
if !option.is_empty() {
comrak_options.extension.front_matter_delimiter = Some(option);
}
}
}
Ok(Cow::Borrowed(EXTENSION_SHORTCODES)) => {
comrak_options.extension.shortcodes = TryConvert::try_convert(value)?;
Expand Down
2 changes: 1 addition & 1 deletion lib/commonmarker/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ module Config
header_ids: "",
footnotes: false,
description_lists: false,
front_matter_delimiter: nil,
front_matter_delimiter: "",
shortcodes: true,
},
format: [:html].freeze,
Expand Down
2 changes: 1 addition & 1 deletion lib/commonmarker/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Commonmarker
VERSION = "1.0.0.pre10"
VERSION = "1.0.0.pre11"
end
9 changes: 9 additions & 0 deletions test/frontmatter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,13 @@ def test_frontmatter_does_not_interfere_with_codeblock

assert_equal(expected, Commonmarker.to_html(md, plugins: nil))
end

def test_frontmatter_custom_delimiter
md = "---\nyaml: true\nage: 42\n---\n# Title 1"
expected = <<~HTML
<h1>Title 1</h1>
HTML

assert_equal(expected, Commonmarker.to_html(md, options: { extension: { front_matter_delimiter: "---" } }))
end
end