Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion doc/markup_reference/rdoc.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -756,17 +756,32 @@ Rendered HTML:
<tt>Monofont passage containing _italics_ and *bold*.</tt>

A single word may be made monofont by a shorthand:
prefixed and suffixed plus-signs.
prefixed and suffixed plus-signs or backticks.

Example input:

+Monofont+ in a paragraph.

`Monofont` in a paragraph.

Rendered HTML:

>>>
+Monofont+ in a paragraph.

`Monofont` in a paragraph.

Note: The shorthand (<tt>+...+</tt> and <tt>`...`</tt>) only works for simple content
containing word characters, colons, periods, slashes, brackets, and hyphens.
Content containing HTML tags or other markup delimiters will not be matched.
For complex content, use the HTML tags <tt><tt></tt> or <tt><code></tt> instead:

<tt>+literal_plus+</tt> shows: +literal_plus+

<tt>`literal_backtick`</tt> shows: `literal_backtick`

<tt><code>content</code></tt> shows: <code>content</code>

==== Strikethrough

Text may be marked as strikethrough via HTML tag <tt><del></tt> or <tt><s></tt>.
Expand Down
3 changes: 2 additions & 1 deletion lib/rdoc/markup/attribute_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ def initialize
add_word_pair "*", "*", :BOLD, true
add_word_pair "_", "_", :EM, true
add_word_pair "+", "+", :TT, true
add_word_pair "`", "`", :TT, true

add_html "em", :EM, true
add_html "i", :EM, true
Expand All @@ -100,7 +101,7 @@ def initialize

@word_pair_chars = @matching_word_pairs.keys.join

# Matches a word pair delimiter (*, _, +) that is NOT already protected.
# Matches a word pair delimiter (*, _, +, `) that is NOT already protected.
# Used by #protect_code_markup to escape delimiters inside <code>/<tt> tags.
@unprotected_word_pair_regexp = /([#{@word_pair_chars}])(?!#{PROTECT_ATTR})/
end
Expand Down
27 changes: 26 additions & 1 deletion test/rdoc/markup/attribute_manager_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,31 @@ def test_convert_attrs_ignores_tt_inside_tt
assert_equal 'foo <CODE>+tt+</CODE> bar', output('foo <tt>+tt+</tt> bar')
end

def test_backtick_basic
assert_equal(["cat ", @tt_on, "and", @tt_off, " dog"],
@am.flow("cat `and` dog"))

assert_equal(["cat ", @tt_on, "X::Y", @tt_off, " dog"],
@am.flow("cat `X::Y` dog"))
end

def test_backtick_output
assert_equal 'cat <CODE>and</CODE> dog', output('cat `and` dog')
assert_equal 'cat <CODE>X::Y</CODE> dog', output('cat `X::Y` dog')
end

def test_convert_attrs_ignores_backtick_inside_code
assert_equal 'foo <CODE>`text`</CODE> bar', output('foo <code>`text`</code> bar')
end

def test_convert_attrs_ignores_backtick_inside_tt
assert_equal 'foo <CODE>`text`</CODE> bar', output('foo <tt>`text`</tt> bar')
end

def test_backtick_escaped
assert_equal ['`text`'], @am.flow('\`text`')
end

def test_convert_attrs_ignores_del_inside_code
assert_equal 'foo <CODE><del>strike</del></CODE> bar', output('foo <code><del>strike</del></code> bar')
end
Expand Down Expand Up @@ -367,7 +392,7 @@ def test_initial_html
def test_initial_word_pairs
word_pairs = @am.matching_word_pairs
assert word_pairs.is_a?(Hash)
assert_equal(3, word_pairs.size)
assert_equal(4, word_pairs.size)
end

def test_mask_protected_sequence
Expand Down
Loading