diff --git a/README.md b/README.md
index 71b894cd9e..510f12b5b2 100644
--- a/README.md
+++ b/README.md
@@ -136,7 +136,7 @@ rdoc --markup markdown
| Cross-references | Automatic | Automatic |
| Directives (`:nodoc:`, etc.) | Supported | Supported |
| Tables | Not supported | Supported |
-| Strikethrough | Not supported | Supported |
+| Strikethrough | `text` | `~~text~~` |
| Footnotes | Not supported | Supported |
For complete syntax documentation, see:
diff --git a/doc/markup_reference/markdown.md b/doc/markup_reference/markdown.md
index 49f87ada0f..7550cefe09 100644
--- a/doc/markup_reference/markdown.md
+++ b/doc/markup_reference/markdown.md
@@ -540,7 +540,7 @@ See [rdoc.rdoc](rdoc.rdoc) for complete directive documentation.
| Code blocks | Indent beyond margin | Indent 4 spaces or fence |
| Block quotes | `>>>` | `>` |
| Tables | Not supported | Supported |
-| Strikethrough | Not supported | `~~text~~` |
+| Strikethrough | `text` | `~~text~~` |
| Footnotes | Not supported | `[^1]` |
## Notes and Limitations
diff --git a/doc/markup_reference/rdoc.rdoc b/doc/markup_reference/rdoc.rdoc
index 8a4025af62..cbb48fdbaf 100644
--- a/doc/markup_reference/rdoc.rdoc
+++ b/doc/markup_reference/rdoc.rdoc
@@ -664,7 +664,7 @@ For C code, the directive may appear in a stand-alone comment.
Text markup is metatext that affects HTML rendering:
-- {Typeface}[rdoc-ref:rdoc@Typeface+Markup]: italic, bold, monofont.
+- {Typeface}[rdoc-ref:rdoc@Typeface+Markup]: italic, bold, monofont, strikethrough.
- {Character conversions}[rdoc-ref:rdoc@Character+Conversions]: copyright, trademark, certain punctuation.
- {Links}[rdoc-ref:rdoc@Links].
- {Escapes}[rdoc-ref:rdoc@Escaping+Text]: marking text as "not markup."
@@ -672,12 +672,13 @@ Text markup is metatext that affects HTML rendering:
=== Typeface Markup
Typeface markup can specify that text is to be rendered
-as italic, bold, or monofont.
+as italic, bold, monofont, or strikethrough.
Typeface markup may contain only one type of nested block:
- More typeface markup:
- {italic}[rdoc-ref:rdoc@Italic], {bold}[rdoc-ref:rdoc@Bold], {monofont}[rdoc-ref:rdoc@Monofont].
+ {italic}[rdoc-ref:rdoc@Italic], {bold}[rdoc-ref:rdoc@Bold], {monofont}[rdoc-ref:rdoc@Monofont],
+ {strikethrough}[rdoc-ref:rdoc@Strikethrough].
==== Italic
@@ -766,6 +767,23 @@ Rendered HTML:
>>>
+Monofont+ in a paragraph.
+==== Strikethrough
+
+Text may be marked as strikethrough via HTML tag or .
+
+Example input:
+
+ Strikethrough words in a paragraph.
+
+ Deleted passage containing _italics_ and *bold*.
+
+Rendered HTML:
+
+>>>
+ Strikethrough words in a paragraph.
+
+ Deleted passage containing _italics_ and *bold*.
+
=== Character Conversions
Certain combinations of characters may be converted to special characters;
diff --git a/lib/rdoc/markdown.kpeg b/lib/rdoc/markdown.kpeg
index 46c8f07f41..91d05c57a9 100644
--- a/lib/rdoc/markdown.kpeg
+++ b/lib/rdoc/markdown.kpeg
@@ -490,11 +490,7 @@
# Wraps `text` in strike markup for rdoc inline formatting
def strike text
- if text =~ /\A[a-z\d.\/-]+\z/i then
- "~#{text}~"
- else
- "#{text}"
- end
+ "#{text}"
end
##
diff --git a/lib/rdoc/markdown.rb b/lib/rdoc/markdown.rb
index e9cb35c244..811c065ec1 100644
--- a/lib/rdoc/markdown.rb
+++ b/lib/rdoc/markdown.rb
@@ -875,11 +875,7 @@ def strong text
# Wraps `text` in strike markup for rdoc inline formatting
def strike text
- if text =~ /\A[a-z\d.\/-]+\z/i then
- "~#{text}~"
- else
- "#{text}"
- end
+ "#{text}"
end
##
diff --git a/lib/rdoc/markup/attribute_manager.rb b/lib/rdoc/markup/attribute_manager.rb
index 8de2050670..259d2a7712 100644
--- a/lib/rdoc/markup/attribute_manager.rb
+++ b/lib/rdoc/markup/attribute_manager.rb
@@ -89,7 +89,6 @@ def initialize
add_word_pair "*", "*", :BOLD, true
add_word_pair "_", "_", :EM, true
add_word_pair "+", "+", :TT, true
- add_word_pair "~", "~", :STRIKE, true
add_html "em", :EM, true
add_html "i", :EM, true
@@ -263,7 +262,10 @@ def protect_code_markup
@str.gsub!(/<(code|tt)>(.*?)<\/\1>/im) do
tag = $1
content = $2
+ # Protect word pair delimiters (*, _, +) from being processed
escaped = content.gsub(@unprotected_word_pair_regexp, "\\1#{PROTECT_ATTR}")
+ # Protect HTML-like tags from being processed (e.g., inside code)
+ escaped = escaped.gsub(/<(?!#{PROTECT_ATTR})/, "<#{PROTECT_ATTR}")
"<#{tag}>#{escaped}#{tag}>"
end
end
diff --git a/test/rdoc/markup/attribute_manager_test.rb b/test/rdoc/markup/attribute_manager_test.rb
index a82d500d9d..c48954c8ea 100644
--- a/test/rdoc/markup/attribute_manager_test.rb
+++ b/test/rdoc/markup/attribute_manager_test.rb
@@ -167,17 +167,6 @@ def test_bold_html_escaped
assert_equal ['cat dog'], @am.flow('cat \dog')
end
- def test_strike
- assert_equal [@strike_on, 'strike', @strike_off],
- @am.flow("~strike~")
-
- assert_equal [@strike_on, 'Strike:', @strike_off],
- @am.flow("~Strike:~")
-
- assert_equal ["cat ", @strike_on, "and", @strike_off, " dog"],
- @am.flow("cat ~and~ dog")
- end
-
def test_strike_html_escaped
assert_equal ['cat dog'], @am.flow('cat \dog')
assert_equal ['cat dog'], @am.flow('cat \dog')
@@ -193,14 +182,6 @@ def test_html_like_strike_del
@am.flow("cat dog")
end
- def test_convert_attrs_ignores_strike_inside_code
- assert_equal 'foo ~strike~ bar', output('foo ~strike~ bar')
- end
-
- def test_convert_attrs_ignores_strike_inside_tt
- assert_equal 'foo ~strike~ bar', output('foo ~strike~ bar')
- end
-
def test_combined
assert_equal(["cat ", @em_on, "and", @em_off, " ", @bold_on, "dog", @bold_off],
@am.flow("cat _and_ *dog*"))
@@ -263,6 +244,18 @@ def test_convert_attrs_ignores_tt_inside_tt
assert_equal 'foo +tt+ bar', output('foo +tt+ bar')
end
+ def test_convert_attrs_ignores_del_inside_code
+ assert_equal 'foo strike bar', output('foo strike bar')
+ end
+
+ def test_convert_attrs_ignores_del_inside_tt
+ assert_equal 'foo strike bar', output('foo strike bar')
+ end
+
+ def test_convert_attrs_ignores_s_inside_code
+ assert_equal 'foo strike bar', output('foo strike bar')
+ end
+
def test_convert_attrs_ignores_tt
assert_equal 'foo __send__ bar', output('foo __send__ bar')
end
@@ -374,7 +367,7 @@ def test_initial_html
def test_initial_word_pairs
word_pairs = @am.matching_word_pairs
assert word_pairs.is_a?(Hash)
- assert_equal(4, word_pairs.size)
+ assert_equal(3, word_pairs.size)
end
def test_mask_protected_sequence
diff --git a/test/rdoc/rdoc_markdown_test.rb b/test/rdoc/rdoc_markdown_test.rb
index 6fe07425a5..e851466f72 100644
--- a/test/rdoc/rdoc_markdown_test.rb
+++ b/test/rdoc/rdoc_markdown_test.rb
@@ -1089,7 +1089,7 @@ def test_parse_strike_tilde
doc = parse "it ~~works~~\n"
expected = @RM::Document.new(
- @RM::Paragraph.new("it ~works~"))
+ @RM::Paragraph.new("it works"))
assert_equal expected, doc
end
@@ -1098,7 +1098,7 @@ def test_parse_strike_words_tilde
doc = parse "it ~~works fine~~\n"
expected = @RM::Document.new(
- @RM::Paragraph.new("it works fine"))
+ @RM::Paragraph.new("it works fine"))
assert_equal expected, doc
end