Skip to content

Commit c40bac8

Browse files
[DOC] Enhances text about escapes (#917)
1 parent 5506d4d commit c40bac8

File tree

1 file changed

+87
-31
lines changed

1 file changed

+87
-31
lines changed

doc/rdoc/markup_reference.rb

+87-31
Original file line numberDiff line numberDiff line change
@@ -820,37 +820,6 @@
820820
#
821821
# ====== +Monofont+ in a Heading
822822
#
823-
# ==== Escaping Text Markup
824-
#
825-
# Text markup can be escaped with a backslash, as in \<tt>, which was obtained
826-
# with <tt>\\<tt></tt>. Except in verbatim sections and between \<tt> tags,
827-
# to produce a backslash you have to double it unless it is followed by a
828-
# space, tab or newline. Otherwise, the HTML formatter will discard it, as it
829-
# is used to escape potential links:
830-
#
831-
# * The \ must be doubled if not followed by white space: \\.
832-
# * But not in \<tt> tags: in a Regexp, <tt>\S</tt> matches non-space.
833-
# * This is a link to {ruby-lang}[https://www.ruby-lang.org].
834-
# * This is not a link, however: \{ruby-lang.org}[https://www.ruby-lang.org].
835-
# * This will not be linked to \RDoc::RDoc#document
836-
#
837-
# generates:
838-
#
839-
# * The \ must be doubled if not followed by white space: \\.
840-
# * But not in \<tt> tags: in a Regexp, <tt>\S</tt> matches non-space.
841-
# * This is a link to {ruby-lang}[https://www.ruby-lang.org]
842-
# * This is not a link, however: \{ruby-lang.org}[https://www.ruby-lang.org]
843-
# * This will not be linked to \RDoc::RDoc#document
844-
#
845-
# Inside \<tt> tags, more precisely, leading backslashes are removed only if
846-
# followed by a markup character (<tt><*_+</tt>), a backslash, or a known link
847-
# reference (a known class or method). So in the example above, the backslash
848-
# of <tt>\S</tt> would be removed if there was a class or module named +S+ in
849-
# the current context.
850-
#
851-
# This behavior is inherited from RDoc version 1, and has been kept for
852-
# compatibility with existing RDoc documentation.
853-
#
854823
# ==== Character Conversions
855824
#
856825
# Certain combinations of characters may be converted to special characters;
@@ -1074,6 +1043,93 @@
10741043
#
10751044
# {rdoc-image:https://www.ruby-lang.org/images/[email protected]}[./Alias.html]
10761045
#
1046+
# === Escaping Text
1047+
#
1048+
# Text that would otherwise be interpreted as markup
1049+
# can be "escaped," so that it is not interpreted as markup;
1050+
# the escape character is the backslash (<tt>'\\'</tt>).
1051+
#
1052+
# In a verbatim text block or a code block,
1053+
# the escape character is always preserved:
1054+
#
1055+
# Example input:
1056+
#
1057+
# This is not verbatim text.
1058+
#
1059+
# This is verbatim text, with an escape character \.
1060+
#
1061+
# This is not a code block.
1062+
#
1063+
# def foo
1064+
# 'String with an escape character.'
1065+
# end
1066+
#
1067+
# Rendered HTML:
1068+
#
1069+
# >>>
1070+
# This is not verbatim text.
1071+
#
1072+
# This is verbatim text, with an escape character \.
1073+
#
1074+
# This is not a code block.
1075+
#
1076+
# def foo
1077+
# 'This is a code block with an escape character \.'
1078+
# end
1079+
#
1080+
# In typeface markup (italic, bold, or monofont),
1081+
# an escape character is preserved unless it is immediately
1082+
# followed by nested typeface markup.
1083+
#
1084+
# Example input:
1085+
#
1086+
# This list is about escapes; it contains:
1087+
#
1088+
# - <tt>Monofont text with unescaped nested _italic_</tt>.
1089+
# - <tt>Monofont text with escaped nested \_italic_</tt>.
1090+
# - <tt>Monofont text with an escape character \</tt>.
1091+
#
1092+
# Rendered HTML:
1093+
#
1094+
# >>>
1095+
# This list is about escapes; it contains:
1096+
#
1097+
# - <tt>Monofont text with unescaped nested _italic_</tt>.
1098+
# - <tt>Monofont text with escaped nested \_italic_</tt>.
1099+
# - <tt>Monofont text with an escape character \ </tt>.
1100+
#
1101+
# In other text-bearing blocks
1102+
# (paragraphs, block quotes, list items, headings):
1103+
#
1104+
# - A single escape character immediately followed by markup
1105+
# escapes the markup.
1106+
# - A single escape character followed by whitespace is preserved.
1107+
# - A single escape character anywhere else is ignored.
1108+
# - A double escape character is rendered as a single backslash.
1109+
#
1110+
# Example input:
1111+
#
1112+
# This list is about escapes; it contains:
1113+
#
1114+
# - An unescaped class name, RDoc, that will become a link.
1115+
# - An escaped class name, \RDoc, that will not become a link.
1116+
# - An escape character followed by whitespace \ .
1117+
# - An escape character \that is ignored.
1118+
# - A double escape character \\ that is rendered
1119+
# as a single backslash.
1120+
#
1121+
# Rendered HTML:
1122+
#
1123+
# >>>
1124+
# This list is about escapes; it contains:
1125+
#
1126+
# - An unescaped class name, RDoc, that will become a link.
1127+
# - An escaped class name, \RDoc, that will not become a link.
1128+
# - An escape character followed by whitespace \ .
1129+
# - An escape character \that is ignored.
1130+
# - A double escape character \\ that is rendered
1131+
# as a single backslash.
1132+
#
10771133
# == Documentation Derived from Ruby Code
10781134
#
10791135
# [Class]

0 commit comments

Comments
 (0)