Skip to content

Commit

Permalink
Keep header_ids option as nil
Browse files Browse the repository at this point in the history
  • Loading branch information
ppworks committed Nov 27, 2024
1 parent c0be788 commit 9290562
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/commonmarker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def parse(text, options: Commonmarker::Config::OPTIONS)
raise TypeError, "text must be UTF-8 encoded; got #{text.encoding}!" unless text.encoding.name == "UTF-8"
raise TypeError, "options must be a Hash; got a #{options.class}!" unless options.is_a?(Hash)

opts = Config.process_options(options)
opts = Config.process_options(options.deep_dup)

commonmark_parse(text, options: opts)
end
Expand All @@ -38,7 +38,7 @@ def to_html(text, options: Commonmarker::Config::OPTIONS, plugins: Commonmarker:
raise TypeError, "text must be UTF-8 encoded; got #{text.encoding}!" unless text.encoding.name == "UTF-8"
raise TypeError, "options must be a Hash; got a #{options.class}!" unless options.is_a?(Hash)

opts = Config.process_options(options)
opts = Config.process_options(options.deep_dup)
plugins = Config.process_plugins(plugins)

commonmark_to_html(text, options: opts, plugins: plugins)
Expand Down
4 changes: 2 additions & 2 deletions lib/commonmarker/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def each
def to_html(options: Commonmarker::Config::OPTIONS, plugins: Commonmarker::Config::PLUGINS)
raise TypeError, "options must be a Hash; got a #{options.class}!" unless options.is_a?(Hash)

opts = Config.process_options(options)
opts = Config.process_options(options.deep_dup)
plugins = Config.process_plugins(plugins)

node_to_html(options: opts, plugins: plugins).force_encoding("utf-8")
Expand All @@ -56,7 +56,7 @@ def to_html(options: Commonmarker::Config::OPTIONS, plugins: Commonmarker::Confi
def to_commonmark(options: Commonmarker::Config::OPTIONS, plugins: Commonmarker::Config::PLUGINS)
raise TypeError, "options must be a Hash; got a #{options.class}!" unless options.is_a?(Hash)

opts = Config.process_options(options)
opts = Config.process_options(options.deep_dup)
plugins = Config.process_plugins(plugins)

node_to_commonmark(options: opts, plugins: plugins).force_encoding("utf-8")
Expand Down
35 changes: 35 additions & 0 deletions test/config_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,39 @@ def test_config_merges_directly
# hardbreaks still work
assert_equal("<p>aaaa<br />\nbbbb</p>\n", Commonmarker.to_html("aaaa\nbbbb", options: { render: { unsafe: false } }))
end

def test_same_config_again
user_config = {
extension: {
header_ids: nil,
},
}

text = "# Heading-1"
expected = "<h1>Heading-1</h1>\n"

assert_equal(expected, Commonmarker.to_html(text, options: user_config))

# expect same result
assert_equal(expected, Commonmarker.to_html(text, options: user_config))
end

def test_render_and_to_html_with_same_config
user_config = {
extension: {
header_ids: nil,
},
}

text = "# Heading-1"
expected = "<h1>Heading-1</h1>\n"

doc = Commonmarker.parse(text, options: user_config)
# doc.walk do |node|
# # do something
# end
doc.to_html(options: user_config)

assert_equal(expected, Commonmarker.to_html(text, options: user_config))
end
end

0 comments on commit 9290562

Please sign in to comment.