Skip to content

Commit f331c3b

Browse files
authored
Merge pull request #203 from gjtorikian/frontmatter-parse-tweak
Frontmatter parse tweak
2 parents a718941 + b5ea1ea commit f331c3b

6 files changed

Lines changed: 34 additions & 9 deletions

File tree

.github/workflows/test.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,8 @@ jobs:
2626
cargo-cache: true
2727
cache-version: v1
2828

29+
- name: Compile comrak
30+
run: bundle exec rake compile
31+
2932
- name: Run Ruby tests
30-
run: bundle exec rake compile test
33+
run: bundle exec rake test

ext/commonmarker/src/comrak_options.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ fn iterate_parse_options(comrak_options: &mut ComrakOptions, options_hash: RHash
1515
comrak_options.parse.smart = value.try_convert::<bool>()?;
1616
}
1717
Ok(Cow::Borrowed(PARSE_DEFAULT_INFO_STRING)) => {
18-
comrak_options.parse.default_info_string =
19-
Some(value.try_convert::<String>().unwrap());
18+
comrak_options.parse.default_info_string = try_convert_string(value);
2019
}
2120
_ => {}
2221
}
@@ -91,8 +90,7 @@ fn iterate_extension_options(comrak_options: &mut ComrakOptions, options_hash: R
9190
comrak_options.extension.superscript = value.try_convert::<bool>()?;
9291
}
9392
Ok(Cow::Borrowed(EXTENSION_HEADER_IDS)) => {
94-
comrak_options.extension.header_ids =
95-
Some(value.try_convert::<String>().unwrap());
93+
comrak_options.extension.header_ids = try_convert_string(value);
9694
}
9795
Ok(Cow::Borrowed(EXTENSION_FOOTNOTES)) => {
9896
comrak_options.extension.footnotes = value.try_convert::<bool>()?;
@@ -101,8 +99,7 @@ fn iterate_extension_options(comrak_options: &mut ComrakOptions, options_hash: R
10199
comrak_options.extension.description_lists = value.try_convert::<bool>()?;
102100
}
103101
Ok(Cow::Borrowed(EXTENSION_FRONT_MATTER_DELIMITER)) => {
104-
comrak_options.extension.front_matter_delimiter =
105-
Some(value.try_convert::<String>().unwrap());
102+
comrak_options.extension.front_matter_delimiter = try_convert_string(value);
106103
}
107104
_ => {}
108105
}
@@ -129,3 +126,11 @@ pub fn iterate_options_hash(
129126
}
130127
Ok(ForEach::Continue)
131128
}
129+
130+
fn try_convert_string(value: Value) -> Option<String> {
131+
if value.is_kind_of(class::string()) {
132+
Some(value.try_convert::<String>().unwrap())
133+
} else {
134+
None
135+
}
136+
}

lib/commonmarker/config.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ module Config
2626
header_ids: "",
2727
footnotes: false,
2828
description_lists: false,
29-
front_matter_delimiter: "",
29+
front_matter_delimiter: nil,
3030
},
3131
format: [:html].freeze,
3232
}.freeze

lib/commonmarker/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

33
module Commonmarker
4-
VERSION = "1.0.0.pre"
4+
VERSION = "1.0.0.pre.2"
55
end

test/test_format_commonmark.rb

Whitespace-only changes.

test/test_frontmatter.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# frozen_string_literal: true
2+
3+
require "test_helper"
4+
5+
class TestFrontmatter < Minitest::Test
6+
def test_frontmatter_does_not_interfere_with_codeblock
7+
md = "\n```\n\nx\n\n```\n"
8+
expected = <<~HTML
9+
<pre><code>
10+
x
11+
12+
</code></pre>
13+
HTML
14+
15+
assert_equal(expected, Commonmarker.to_html(md))
16+
end
17+
end

0 commit comments

Comments
 (0)