From 22f957b98ae1f083b32277b6a2a9495914e62fda Mon Sep 17 00:00:00 2001 From: "Garen J. Torikian" Date: Sat, 14 Mar 2026 00:26:17 -0400 Subject: [PATCH] Add `insert` extension for rendering `++text++` as `text` --- README.md | 1 + ext/commonmarker/src/options.rs | 4 ++++ lib/commonmarker/config.rb | 1 + test/extensions_test.rb | 14 ++++++++++++++ 4 files changed, 20 insertions(+) diff --git a/README.md b/README.md index ac9abcdc..9715c7ef 100644 --- a/README.md +++ b/README.md @@ -219,6 +219,7 @@ Commonmarker.to_html('"Hi *there*"', options: { | `alerts` | Enables the alerts extension. | `false` | | `cjk_friendly_emphasis` | Enables the [CJK friendly emphasis](https://github.com/tats-u/markdown-cjk-friendly) extension. | `false` | | `highlight` | Enables highlighting via `==` | `false` | +| `insert` | Enables the insert extension, rendering `++text++` as `text`. | `false` | For more information on these options, see [the comrak documentation](https://github.com/kivikakk/comrak#usage). diff --git a/ext/commonmarker/src/options.rs b/ext/commonmarker/src/options.rs index ad03181d..3a0f4715 100644 --- a/ext/commonmarker/src/options.rs +++ b/ext/commonmarker/src/options.rs @@ -126,6 +126,7 @@ const EXTENSION_SUBTEXT: &str = "subtext"; const EXTENSION_ALERTS: &str = "alerts"; const EXTENSION_CJK_FRIENDLY_EMPHASIS: &str = "cjk_friendly_emphasis"; const EXTENSION_HIGHLIGHT: &str = "highlight"; +const EXTENSION_INSERT: &str = "insert"; pub fn iterate_extension_options( comrak_options: &mut comrak::options::Extension, @@ -213,6 +214,9 @@ pub fn iterate_extension_options( Cow::Borrowed(EXTENSION_HIGHLIGHT) => { comrak_options.highlight = TryConvert::try_convert(value)?; } + Cow::Borrowed(EXTENSION_INSERT) => { + comrak_options.insert = TryConvert::try_convert(value)?; + } _ => {} } Ok(ForEach::Continue) diff --git a/lib/commonmarker/config.rb b/lib/commonmarker/config.rb index 9b222d45..cd53832d 100644 --- a/lib/commonmarker/config.rb +++ b/lib/commonmarker/config.rb @@ -53,6 +53,7 @@ module Config alerts: false, cjk_friendly_emphasis: false, highlight: false, + insert: false, }.freeze, format: [:html].freeze, }.freeze diff --git a/test/extensions_test.rb b/test/extensions_test.rb index c00f9725..e78e2880 100644 --- a/test/extensions_test.rb +++ b/test/extensions_test.rb @@ -127,4 +127,18 @@ def test_highlight_extension Commonmarker.to_html("This is ==important!==.", options: options), ) end + + def test_insert_extension + assert_equal( + "

This is ++important!++.

\n", + Commonmarker.to_html("This is ++important!++."), + ) + + options = { extension: { insert: true } } + + assert_equal( + "

This is important!.

\n", + Commonmarker.to_html("This is ++important!++.", options: options), + ) + end end