Skip to content

Commit

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

### Render options

| Name | Description | Default |
| ----------------- | ------------------------------------------------------------------------------------------------------ | ------- |
| `hardbreaks` | [Soft line breaks](http://spec.commonmark.org/0.27/#soft-line-breaks) translate into hard line breaks. | `true` |
| `github_pre_lang` | GitHub-style `<pre lang="xyz">` is used for fenced code blocks with info tags. | `true` |
| `width` | The wrap column when outputting CommonMark. | `80` |
| `unsafe` | Allow rendering of raw HTML and potentially dangerous links. | `false` |
| `escape` | Escape raw HTML instead of clobbering it. | `false` |
| `sourcepos` | Include source position attribute in HTML and XML output. | `false` |
| Name | Description | Default |
| -------------------- | ------------------------------------------------------------------------------------------------------ | ------- |
| `hardbreaks` | [Soft line breaks](http://spec.commonmark.org/0.27/#soft-line-breaks) translate into hard line breaks. | `true` |
| `github_pre_lang` | GitHub-style `<pre lang="xyz">` is used for fenced code blocks with info tags. | `true` |
| `width` | The wrap column when outputting CommonMark. | `80` |
| `unsafe` | Allow rendering of raw HTML and potentially dangerous links. | `false` |
| `escape` | Escape raw HTML instead of clobbering it. | `false` |
| `sourcepos` | Include source position attribute in HTML and XML output. | `false` |
| `escaped_char_spans` | Wrap escaped characters in span tags | `true` |

As well, there are several extensions which you can toggle in the same manner:

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 @@ -34,6 +34,7 @@ const RENDER_WIDTH: &str = "width";
const RENDER_UNSAFE: &str = "unsafe";
const RENDER_ESCAPE: &str = "escape";
const RENDER_SOURCEPOS: &str = "sourcepos";
const RENDER_ESCAPED_CHAR_SPANS: &str = "escaped_char_spans";

fn iterate_render_options(comrak_options: &mut ComrakOptions, options_hash: RHash) {
options_hash
Expand All @@ -57,6 +58,9 @@ fn iterate_render_options(comrak_options: &mut ComrakOptions, options_hash: RHas
Ok(Cow::Borrowed(RENDER_SOURCEPOS)) => {
comrak_options.render.sourcepos = TryConvert::try_convert(value)?;
}
Ok(Cow::Borrowed(RENDER_ESCAPED_CHAR_SPANS)) => {
comrak_options.render.escaped_char_spans = 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 @@ -16,6 +16,7 @@ module Config
unsafe: false,
escape: false,
sourcepos: false,
escaped_char_spans: true,
}.freeze,
extension: {
strikethrough: true,
Expand Down
19 changes: 19 additions & 0 deletions test/escaped_char_spans_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# frozen_string_literal: true

require "test_helper"

class EscapeCharSpansTest < Minitest::Test
def test_to_html
md = <<~MARKDOWN
Hello \\@user
Hey, @user!
MARKDOWN
expected = <<~HTML
<p>Hello <span data-escaped-char>@</span>user</p>
<p>Hey, @user!</p>
HTML

assert_equal(expected, Commonmarker.to_html(md, options: { render: { escaped_char_spans: true } }))
end
end
33 changes: 0 additions & 33 deletions test/node/creation_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,36 +66,3 @@ def test_errors_reported
end
end
end

# ComrakNodeValue::List(..) => Symbol::new("list"),
# ComrakNodeValue::DescriptionList => Symbol::new("description_list"),
# ComrakNodeValue::DescriptionItem(_) => Symbol::new("description_item"),
# ComrakNodeValue::DescriptionTerm => Symbol::new("description_term"),
# ComrakNodeValue::DescriptionDetails => Symbol::new("description_details"),
# ComrakNodeValue::Item(..) => Symbol::new("item"),
# ComrakNodeValue::CodeBlock(..) => Symbol::new("code_block"),
# ComrakNodeValue::HtmlBlock(..) => Symbol::new("html_block"),
# ComrakNodeValue::Paragraph => Symbol::new("paragraph"),
# ComrakNodeValue::Heading(..) => Symbol::new("heading"),
# ComrakNodeValue::ThematicBreak => Symbol::new("thematic_break"),
# ComrakNodeValue::Table(..) => Symbol::new("table"),
# ComrakNodeValue::TableRow(..) => Symbol::new("table_row"),
# ComrakNodeValue::TableCell => Symbol::new("table_cell"),
# ComrakNodeValue::Text(..) => Symbol::new("text"),
# ComrakNodeValue::SoftBreak => Symbol::new("softbreak"),
# ComrakNodeValue::LineBreak => Symbol::new("linebreak"),
# ComrakNodeValue::Image(..) => Symbol::new("image"),
# ComrakNodeValue::Link(..) => Symbol::new("link"),
# ComrakNodeValue::Emph => Symbol::new("emph"),
# ComrakNodeValue::Strong => Symbol::new("strong"),
# ComrakNodeValue::Code(..) => Symbol::new("code"),
# ComrakNodeValue::HtmlInline(..) => Symbol::new("html_inline"),
# ComrakNodeValue::Strikethrough => Symbol::new("strikethrough"),
# ComrakNodeValue::FrontMatter(_) => Symbol::new("frontmatter"),
# ComrakNodeValue::TaskItem { .. } => Symbol::new("taskitem"),
# ComrakNodeValue::Superscript => Symbol::new("superscript"),
# ComrakNodeValue::FootnoteReference(..) => Symbol::new("footnote_reference"),
# ComrakNodeValue::ShortCode(_) => Symbol::new("shortcode"),
# ComrakNodeValue::MultilineBlockQuote(_) => Symbol::new("multiline_block_quote"),
# ComrakNodeValue::Escaped => Symbol::new("escaped"),
# ComrakNodeValue::Math(..) => Symbol::new("math"),

0 comments on commit 4ef4951

Please sign in to comment.