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

Frontmatter parse tweak #203

Merged
merged 4 commits into from
Nov 21, 2022
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
5 changes: 4 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,8 @@ jobs:
cargo-cache: true
cache-version: v1

- name: Compile comrak
run: bundle exec rake compile

- name: Run Ruby tests
run: bundle exec rake compile test
run: bundle exec rake test
17 changes: 11 additions & 6 deletions ext/commonmarker/src/comrak_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ fn iterate_parse_options(comrak_options: &mut ComrakOptions, options_hash: RHash
comrak_options.parse.smart = value.try_convert::<bool>()?;
}
Ok(Cow::Borrowed(PARSE_DEFAULT_INFO_STRING)) => {
comrak_options.parse.default_info_string =
Some(value.try_convert::<String>().unwrap());
comrak_options.parse.default_info_string = try_convert_string(value);
}
_ => {}
}
Expand Down Expand Up @@ -91,8 +90,7 @@ fn iterate_extension_options(comrak_options: &mut ComrakOptions, options_hash: R
comrak_options.extension.superscript = value.try_convert::<bool>()?;
}
Ok(Cow::Borrowed(EXTENSION_HEADER_IDS)) => {
comrak_options.extension.header_ids =
Some(value.try_convert::<String>().unwrap());
comrak_options.extension.header_ids = try_convert_string(value);
}
Ok(Cow::Borrowed(EXTENSION_FOOTNOTES)) => {
comrak_options.extension.footnotes = value.try_convert::<bool>()?;
Expand All @@ -101,8 +99,7 @@ fn iterate_extension_options(comrak_options: &mut ComrakOptions, options_hash: R
comrak_options.extension.description_lists = value.try_convert::<bool>()?;
}
Ok(Cow::Borrowed(EXTENSION_FRONT_MATTER_DELIMITER)) => {
comrak_options.extension.front_matter_delimiter =
Some(value.try_convert::<String>().unwrap());
comrak_options.extension.front_matter_delimiter = try_convert_string(value);
}
_ => {}
}
Expand All @@ -129,3 +126,11 @@ pub fn iterate_options_hash(
}
Ok(ForEach::Continue)
}

fn try_convert_string(value: Value) -> Option<String> {
if value.is_kind_of(class::string()) {
Some(value.try_convert::<String>().unwrap())
} else {
None
}
}
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: "",
front_matter_delimiter: nil,
},
format: [:html].freeze,
}.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.pre"
VERSION = "1.0.0.pre.2"
end
Empty file removed test/test_format_commonmark.rb
Empty file.
17 changes: 17 additions & 0 deletions test/test_frontmatter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# frozen_string_literal: true

require "test_helper"

class TestFrontmatter < Minitest::Test
def test_frontmatter_does_not_interfere_with_codeblock
md = "\n```\n\nx\n\n```\n"
expected = <<~HTML
<pre><code>
x

</code></pre>
HTML

assert_equal(expected, Commonmarker.to_html(md))
end
end