Skip to content

Commit

Permalink
Add relaxed_autolinks
Browse files Browse the repository at this point in the history
  • Loading branch information
gjtorikian committed Apr 30, 2024
1 parent b64998d commit 9a8b57d
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 4 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,11 @@ Note that there is a distinction in comrak for "parse" options and "render" opti

### Parse options

| Name | Description | Default |
| --------------------- | ------------------------------------------------------------------------------------ | ------- |
| `smart` | Punctuation (quotes, full-stops and hyphens) are converted into 'smart' punctuation. | `false` |
| `default_info_string` | The default info string for fenced code blocks. | `""` |
| Name | Description | Default |
| --------------------- | ------------------------------------------------------------------------------------------------------------------------------------------ | ------- |
| `smart` | Punctuation (quotes, full-stops and hyphens) are converted into 'smart' punctuation. | `false` |
| `default_info_string` | The default info string for fenced code blocks. | `""` |
| `relaxed_autolinks` | Enable relaxing of the autolink extension parsing, allowing links to be recognized when in brackets, as well as permitting any url scheme. | `false` |

### Render options

Expand Down
4 changes: 4 additions & 0 deletions ext/commonmarker/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use crate::utils::try_convert_string;

const PARSE_SMART: &str = "smart";
const PARSE_DEFAULT_INFO_STRING: &str = "default_info_string";
const PARSE_RELAXED_AUTOLINKS: &str = "relaxed_autolinks";

fn iterate_parse_options(comrak_options: &mut ComrakOptions, options_hash: RHash) {
options_hash
Expand All @@ -21,6 +22,9 @@ fn iterate_parse_options(comrak_options: &mut ComrakOptions, options_hash: RHash
Ok(Cow::Borrowed(PARSE_DEFAULT_INFO_STRING)) => {
comrak_options.parse.default_info_string = try_convert_string(value);
}
Ok(Cow::Borrowed(PARSE_RELAXED_AUTOLINKS)) => {
comrak_options.parse.relaxed_autolinks = TryConvert::try_convert(value)?;
}
_ => {}
}
Ok(ForEach::Continue)
Expand Down
1 change: 1 addition & 0 deletions lib/commonmarker/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module Config
parse: {
smart: false,
default_info_string: "",
relaxed_autolinks: false,
}.freeze,
render: {
hardbreaks: true,
Expand Down
23 changes: 23 additions & 0 deletions test/relaxed_autolinks_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# frozen_string_literal: true

require "test_helper"

class RelaxedAutolinksTest < Minitest::Test
def test_to_html
md = <<~MARKDOWN
[https://foo.com]
smb:///Volumes/shared/foo.pdf
rdar://localhost.com/blah
MARKDOWN

expected = <<~HTML
<p>[<a href="https://foo.com">https://foo.com</a>]</p>
<p><a href="smb:///Volumes/shared/foo.pdf">smb:///Volumes/shared/foo.pdf</a></p>
<p><a href="rdar://localhost.com/blah">rdar://localhost.com/blah</a></p>
HTML

assert_equal(expected, Commonmarker.to_html(md, options: { parse: { relaxed_autolinks: true } }))
end
end

0 comments on commit 9a8b57d

Please sign in to comment.