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

Default options are not fully merged #314

Open
monkeyWzr opened this issue Sep 11, 2024 · 0 comments · May be fixed by #315
Open

Default options are not fully merged #314

monkeyWzr opened this issue Sep 11, 2024 · 0 comments · May be fixed by #315

Comments

@monkeyWzr
Copy link

monkeyWzr commented Sep 11, 2024

Hi there!

Recently I faced with some unexpected behaviors when setting render options (v1.1.5).

For example, by default \n will be rendered to <br> (hardbreaks), but when I set any other options to render, hardbreaks will also be disabled.

# hardbreas works, the `\n` in between is rendered
Commonmarker.to_html("aaaa\nbbbb")
# => "<p>aaaa<br />\nbbbb</p>\n"

# hardbreaks does not work!
Commonmarker.to_html("aaaa\nbbbb", options: { render: { unsafe: false }})
# => "<p>aaaa\nbbbb</p>\n"

The same also happens for extention:

# autolink works by default
Commonmarker.to_html("### h3")
# => "<h3><a href=\"#h3\" aria-hidden=\"true\" class=\"anchor\" id=\"h3\"></a>h3</h3>\n"

# autolink is gone!?
Commonmarker.to_html("### h3", options: { extension: { footnotes: false }})
# => "<h3>h3</h3>\n"

Looking into the ruby code, I'm confused with how the default is handled.

# all there
Commonmarker::Config.process_options({})
# => {:parse=>{:smart=>false, :default_info_string=>"", :relaxed_tasklist_matching=>false, :relaxed_autolinks=>false}, :render=>{:hardbreaks=>true, :github_pre_lang=>true, :full_info_string=>false, :width=>80, :unsafe=>false, :escape=>false, :sourcepos=>false, :escaped_char_spans=>true, :ignore_setext=>false, :ignore_empty_links=>false, :gfm_quirks=>false, :prefer_fenced=>false}, :extension=>{:strikethrough=>true, :tagfilter=>true, :table=>true, :autolink=>true, :tasklist=>true, :superscript=>false, :header_ids=>"", :footnotes=>false, :description_lists=>false, :front_matter_delimiter=>"", :multiline_block_quotes=>false, :math_dollars=>false, :math_code=>false, :shortcodes=>true, :wikilinks_title_before_pipe=>false, :wikilinks_title_after_pipe=>false, :underline=>false, :spoiler=>false, :greentext=>false}}

# those options enabled by default are all gone
Commonmarker::Config.process_options({parse: { smart: false }, render: { unsafe: false }, extension: { footnotes: false }})
# => {:parse=>{:smart=>false}, :render=>{:unsafe=>false}, :extension=>{:footnotes=>false}}

I feel like this is a bug, but all the tests are based on this behavior, so maybe this is intended? To be honest it seems counterintuitive. What do you think?


I open a PR #315 to keep the current behavior by default and add an option to merge the default options for convenience.

@monkeyWzr monkeyWzr linked a pull request Sep 11, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant