Skip to content

Commit 1aae619

Browse files
committed
Align strikethrough support with GitHub Markdown
1. GitHub doesn't support `~word~` syntax for strikethrough, so we shouldn't either. 2. It's hard to make RDoc markup support `~~word~~` without supporting `~word~` as well due to the way attribute manager works. So instead we rollback the support added in #1541. Users can still use `<del>text</del>` syntax for strikethrough. 3. Fix `<code><del>text</del></code>` not rendering as `<del>text</del>` in HTML output. 4. Update documentation to reflect the new support.
1 parent 35de259 commit 1aae619

File tree

8 files changed

+43
-38
lines changed

8 files changed

+43
-38
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ rdoc --markup markdown
136136
| Cross-references | Automatic | Automatic |
137137
| Directives (`:nodoc:`, etc.) | Supported | Supported |
138138
| Tables | Not supported | Supported |
139-
| Strikethrough | Not supported | Supported |
139+
| Strikethrough | `<del>text</del>` | `~~text~~` |
140140
| Footnotes | Not supported | Supported |
141141

142142
For complete syntax documentation, see:

doc/markup_reference/markdown.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ See [rdoc.rdoc](rdoc.rdoc) for complete directive documentation.
540540
| Code blocks | Indent beyond margin | Indent 4 spaces or fence |
541541
| Block quotes | `>>>` | `>` |
542542
| Tables | Not supported | Supported |
543-
| Strikethrough | Not supported | `~~text~~` |
543+
| Strikethrough | `<del>text</del>` | `~~text~~` |
544544
| Footnotes | Not supported | `[^1]` |
545545

546546
## Notes and Limitations

doc/markup_reference/rdoc.rdoc

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -664,20 +664,21 @@ For C code, the directive may appear in a stand-alone comment.
664664

665665
Text markup is metatext that affects HTML rendering:
666666

667-
- {Typeface}[rdoc-ref:rdoc@Typeface+Markup]: italic, bold, monofont.
667+
- {Typeface}[rdoc-ref:rdoc@Typeface+Markup]: italic, bold, monofont, strikethrough.
668668
- {Character conversions}[rdoc-ref:rdoc@Character+Conversions]: copyright, trademark, certain punctuation.
669669
- {Links}[rdoc-ref:rdoc@Links].
670670
- {Escapes}[rdoc-ref:rdoc@Escaping+Text]: marking text as "not markup."
671671

672672
=== Typeface Markup
673673

674674
Typeface markup can specify that text is to be rendered
675-
as italic, bold, or monofont.
675+
as italic, bold, monofont, or strikethrough.
676676

677677
Typeface markup may contain only one type of nested block:
678678

679679
- More typeface markup:
680-
{italic}[rdoc-ref:rdoc@Italic], {bold}[rdoc-ref:rdoc@Bold], {monofont}[rdoc-ref:rdoc@Monofont].
680+
{italic}[rdoc-ref:rdoc@Italic], {bold}[rdoc-ref:rdoc@Bold], {monofont}[rdoc-ref:rdoc@Monofont],
681+
{strikethrough}[rdoc-ref:rdoc@Strikethrough].
681682

682683
==== Italic
683684

@@ -766,6 +767,23 @@ Rendered HTML:
766767
>>>
767768
+Monofont+ in a paragraph.
768769

770+
==== Strikethrough
771+
772+
Text may be marked as strikethrough via HTML tag <tt><del></tt> or <tt><s></tt>.
773+
774+
Example input:
775+
776+
<del>Strikethrough words</del> in a paragraph.
777+
778+
<del>Deleted passage containing _italics_ and *bold*.</del>
779+
780+
Rendered HTML:
781+
782+
>>>
783+
<del>Strikethrough words</del> in a paragraph.
784+
785+
<del>Deleted passage containing _italics_ and *bold*.</del>
786+
769787
=== Character Conversions
770788

771789
Certain combinations of characters may be converted to special characters;

lib/rdoc/markdown.kpeg

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -490,11 +490,7 @@
490490
# Wraps `text` in strike markup for rdoc inline formatting
491491

492492
def strike text
493-
if text =~ /\A[a-z\d.\/-]+\z/i then
494-
"~#{text}~"
495-
else
496-
"<s>#{text}</s>"
497-
end
493+
"<del>#{text}</del>"
498494
end
499495

500496
##

lib/rdoc/markdown.rb

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -875,11 +875,7 @@ def strong text
875875
# Wraps `text` in strike markup for rdoc inline formatting
876876

877877
def strike text
878-
if text =~ /\A[a-z\d.\/-]+\z/i then
879-
"~#{text}~"
880-
else
881-
"<s>#{text}</s>"
882-
end
878+
"<del>#{text}</del>"
883879
end
884880

885881
##

lib/rdoc/markup/attribute_manager.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ def initialize
8989
add_word_pair "*", "*", :BOLD, true
9090
add_word_pair "_", "_", :EM, true
9191
add_word_pair "+", "+", :TT, true
92-
add_word_pair "~", "~", :STRIKE, true
9392

9493
add_html "em", :EM, true
9594
add_html "i", :EM, true
@@ -263,7 +262,10 @@ def protect_code_markup
263262
@str.gsub!(/<(code|tt)>(.*?)<\/\1>/im) do
264263
tag = $1
265264
content = $2
265+
# Protect word pair delimiters (*, _, +) from being processed
266266
escaped = content.gsub(@unprotected_word_pair_regexp, "\\1#{PROTECT_ATTR}")
267+
# Protect HTML-like tags from being processed (e.g., <del> inside code)
268+
escaped = escaped.gsub(/<(?!#{PROTECT_ATTR})/, "<#{PROTECT_ATTR}")
267269
"<#{tag}>#{escaped}</#{tag}>"
268270
end
269271
end

test/rdoc/markup/attribute_manager_test.rb

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -167,17 +167,6 @@ def test_bold_html_escaped
167167
assert_equal ['cat <b>dog</b>'], @am.flow('cat \<b>dog</b>')
168168
end
169169

170-
def test_strike
171-
assert_equal [@strike_on, 'strike', @strike_off],
172-
@am.flow("~strike~")
173-
174-
assert_equal [@strike_on, 'Strike:', @strike_off],
175-
@am.flow("~Strike:~")
176-
177-
assert_equal ["cat ", @strike_on, "and", @strike_off, " dog"],
178-
@am.flow("cat ~and~ dog")
179-
end
180-
181170
def test_strike_html_escaped
182171
assert_equal ['cat <s>dog</s>'], @am.flow('cat \<s>dog</s>')
183172
assert_equal ['cat <del>dog</del>'], @am.flow('cat \<del>dog</del>')
@@ -193,14 +182,6 @@ def test_html_like_strike_del
193182
@am.flow("cat <del>dog</del>")
194183
end
195184

196-
def test_convert_attrs_ignores_strike_inside_code
197-
assert_equal 'foo <CODE>~strike~</CODE> bar', output('foo <code>~strike~</code> bar')
198-
end
199-
200-
def test_convert_attrs_ignores_strike_inside_tt
201-
assert_equal 'foo <CODE>~strike~</CODE> bar', output('foo <tt>~strike~</tt> bar')
202-
end
203-
204185
def test_combined
205186
assert_equal(["cat ", @em_on, "and", @em_off, " ", @bold_on, "dog", @bold_off],
206187
@am.flow("cat _and_ *dog*"))
@@ -263,6 +244,18 @@ def test_convert_attrs_ignores_tt_inside_tt
263244
assert_equal 'foo <CODE>+tt+</CODE> bar', output('foo <tt>+tt+</tt> bar')
264245
end
265246

247+
def test_convert_attrs_ignores_del_inside_code
248+
assert_equal 'foo <CODE><del>strike</del></CODE> bar', output('foo <code><del>strike</del></code> bar')
249+
end
250+
251+
def test_convert_attrs_ignores_del_inside_tt
252+
assert_equal 'foo <CODE><del>strike</del></CODE> bar', output('foo <tt><del>strike</del></tt> bar')
253+
end
254+
255+
def test_convert_attrs_ignores_s_inside_code
256+
assert_equal 'foo <CODE><s>strike</s></CODE> bar', output('foo <code><s>strike</s></code> bar')
257+
end
258+
266259
def test_convert_attrs_ignores_tt
267260
assert_equal 'foo <CODE>__send__</CODE> bar', output('foo <tt>__send__</tt> bar')
268261
end
@@ -374,7 +367,7 @@ def test_initial_html
374367
def test_initial_word_pairs
375368
word_pairs = @am.matching_word_pairs
376369
assert word_pairs.is_a?(Hash)
377-
assert_equal(4, word_pairs.size)
370+
assert_equal(3, word_pairs.size)
378371
end
379372

380373
def test_mask_protected_sequence

test/rdoc/rdoc_markdown_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,7 +1089,7 @@ def test_parse_strike_tilde
10891089
doc = parse "it ~~works~~\n"
10901090

10911091
expected = @RM::Document.new(
1092-
@RM::Paragraph.new("it ~works~"))
1092+
@RM::Paragraph.new("it <del>works</del>"))
10931093

10941094
assert_equal expected, doc
10951095
end
@@ -1098,7 +1098,7 @@ def test_parse_strike_words_tilde
10981098
doc = parse "it ~~works fine~~\n"
10991099

11001100
expected = @RM::Document.new(
1101-
@RM::Paragraph.new("it <s>works fine</s>"))
1101+
@RM::Paragraph.new("it <del>works fine</del>"))
11021102

11031103
assert_equal expected, doc
11041104
end

0 commit comments

Comments
 (0)