| 1 |
|
|---|
| 2 | =head1 NAME
|
|---|
| 3 |
|
|---|
| 4 | perlpodspec - Plain Old Documentation: format specification and notes
|
|---|
| 5 |
|
|---|
| 6 | =head1 DESCRIPTION
|
|---|
| 7 |
|
|---|
| 8 | This document is detailed notes on the Pod markup language. Most
|
|---|
| 9 | people will only have to read L<perlpod|perlpod> to know how to write
|
|---|
| 10 | in Pod, but this document may answer some incidental questions to do
|
|---|
| 11 | with parsing and rendering Pod.
|
|---|
| 12 |
|
|---|
| 13 | In this document, "must" / "must not", "should" /
|
|---|
| 14 | "should not", and "may" have their conventional (cf. RFC 2119)
|
|---|
| 15 | meanings: "X must do Y" means that if X doesn't do Y, it's against
|
|---|
| 16 | this specification, and should really be fixed. "X should do Y"
|
|---|
| 17 | means that it's recommended, but X may fail to do Y, if there's a
|
|---|
| 18 | good reason. "X may do Y" is merely a note that X can do Y at
|
|---|
| 19 | will (although it is up to the reader to detect any connotation of
|
|---|
| 20 | "and I think it would be I<nice> if X did Y" versus "it wouldn't
|
|---|
| 21 | really I<bother> me if X did Y").
|
|---|
| 22 |
|
|---|
| 23 | Notably, when I say "the parser should do Y", the
|
|---|
| 24 | parser may fail to do Y, if the calling application explicitly
|
|---|
| 25 | requests that the parser I<not> do Y. I often phrase this as
|
|---|
| 26 | "the parser should, by default, do Y." This doesn't I<require>
|
|---|
| 27 | the parser to provide an option for turning off whatever
|
|---|
| 28 | feature Y is (like expanding tabs in verbatim paragraphs), although
|
|---|
| 29 | it implicates that such an option I<may> be provided.
|
|---|
| 30 |
|
|---|
| 31 | =head1 Pod Definitions
|
|---|
| 32 |
|
|---|
| 33 | Pod is embedded in files, typically Perl source files -- although you
|
|---|
| 34 | can write a file that's nothing but Pod.
|
|---|
| 35 |
|
|---|
| 36 | A B<line> in a file consists of zero or more non-newline characters,
|
|---|
| 37 | terminated by either a newline or the end of the file.
|
|---|
| 38 |
|
|---|
| 39 | A B<newline sequence> is usually a platform-dependent concept, but
|
|---|
| 40 | Pod parsers should understand it to mean any of CR (ASCII 13), LF
|
|---|
| 41 | (ASCII 10), or a CRLF (ASCII 13 followed immediately by ASCII 10), in
|
|---|
| 42 | addition to any other system-specific meaning. The first CR/CRLF/LF
|
|---|
| 43 | sequence in the file may be used as the basis for identifying the
|
|---|
| 44 | newline sequence for parsing the rest of the file.
|
|---|
| 45 |
|
|---|
| 46 | A B<blank line> is a line consisting entirely of zero or more spaces
|
|---|
| 47 | (ASCII 32) or tabs (ASCII 9), and terminated by a newline or end-of-file.
|
|---|
| 48 | A B<non-blank line> is a line containing one or more characters other
|
|---|
| 49 | than space or tab (and terminated by a newline or end-of-file).
|
|---|
| 50 |
|
|---|
| 51 | (I<Note:> Many older Pod parsers did not accept a line consisting of
|
|---|
| 52 | spaces/tabs and then a newline as a blank line -- the only lines they
|
|---|
| 53 | considered blank were lines consisting of I<no characters at all>,
|
|---|
| 54 | terminated by a newline.)
|
|---|
| 55 |
|
|---|
| 56 | B<Whitespace> is used in this document as a blanket term for spaces,
|
|---|
| 57 | tabs, and newline sequences. (By itself, this term usually refers
|
|---|
| 58 | to literal whitespace. That is, sequences of whitespace characters
|
|---|
| 59 | in Pod source, as opposed to "EE<lt>32>", which is a formatting
|
|---|
| 60 | code that I<denotes> a whitespace character.)
|
|---|
| 61 |
|
|---|
| 62 | A B<Pod parser> is a module meant for parsing Pod (regardless of
|
|---|
| 63 | whether this involves calling callbacks or building a parse tree or
|
|---|
| 64 | directly formatting it). A B<Pod formatter> (or B<Pod translator>)
|
|---|
| 65 | is a module or program that converts Pod to some other format (HTML,
|
|---|
| 66 | plaintext, TeX, PostScript, RTF). A B<Pod processor> might be a
|
|---|
| 67 | formatter or translator, or might be a program that does something
|
|---|
| 68 | else with the Pod (like wordcounting it, scanning for index points,
|
|---|
| 69 | etc.).
|
|---|
| 70 |
|
|---|
| 71 | Pod content is contained in B<Pod blocks>. A Pod block starts with a
|
|---|
| 72 | line that matches <m/\A=[a-zA-Z]/>, and continues up to the next line
|
|---|
| 73 | that matches C<m/\A=cut/> -- or up to the end of the file, if there is
|
|---|
| 74 | no C<m/\A=cut/> line.
|
|---|
| 75 |
|
|---|
| 76 | =for comment
|
|---|
| 77 | The current perlsyn says:
|
|---|
| 78 | [beginquote]
|
|---|
| 79 | Note that pod translators should look at only paragraphs beginning
|
|---|
| 80 | with a pod directive (it makes parsing easier), whereas the compiler
|
|---|
| 81 | actually knows to look for pod escapes even in the middle of a
|
|---|
| 82 | paragraph. This means that the following secret stuff will be ignored
|
|---|
| 83 | by both the compiler and the translators.
|
|---|
| 84 | $a=3;
|
|---|
| 85 | =secret stuff
|
|---|
| 86 | warn "Neither POD nor CODE!?"
|
|---|
| 87 | =cut back
|
|---|
| 88 | print "got $a\n";
|
|---|
| 89 | You probably shouldn't rely upon the warn() being podded out forever.
|
|---|
| 90 | Not all pod translators are well-behaved in this regard, and perhaps
|
|---|
| 91 | the compiler will become pickier.
|
|---|
| 92 | [endquote]
|
|---|
| 93 | I think that those paragraphs should just be removed; paragraph-based
|
|---|
| 94 | parsing seems to have been largely abandoned, because of the hassle
|
|---|
| 95 | with non-empty blank lines messing up what people meant by "paragraph".
|
|---|
| 96 | Even if the "it makes parsing easier" bit were especially true,
|
|---|
| 97 | it wouldn't be worth the confusion of having perl and pod2whatever
|
|---|
| 98 | actually disagree on what can constitute a Pod block.
|
|---|
| 99 |
|
|---|
| 100 | Within a Pod block, there are B<Pod paragraphs>. A Pod paragraph
|
|---|
| 101 | consists of non-blank lines of text, separated by one or more blank
|
|---|
| 102 | lines.
|
|---|
| 103 |
|
|---|
| 104 | For purposes of Pod processing, there are four types of paragraphs in
|
|---|
| 105 | a Pod block:
|
|---|
| 106 |
|
|---|
| 107 | =over
|
|---|
| 108 |
|
|---|
| 109 | =item *
|
|---|
| 110 |
|
|---|
| 111 | A command paragraph (also called a "directive"). The first line of
|
|---|
| 112 | this paragraph must match C<m/\A=[a-zA-Z]/>. Command paragraphs are
|
|---|
| 113 | typically one line, as in:
|
|---|
| 114 |
|
|---|
| 115 | =head1 NOTES
|
|---|
| 116 |
|
|---|
| 117 | =item *
|
|---|
| 118 |
|
|---|
| 119 | But they may span several (non-blank) lines:
|
|---|
| 120 |
|
|---|
| 121 | =for comment
|
|---|
| 122 | Hm, I wonder what it would look like if
|
|---|
| 123 | you tried to write a BNF for Pod from this.
|
|---|
| 124 |
|
|---|
| 125 | =head3 Dr. Strangelove, or: How I Learned to
|
|---|
| 126 | Stop Worrying and Love the Bomb
|
|---|
| 127 |
|
|---|
| 128 | I<Some> command paragraphs allow formatting codes in their content
|
|---|
| 129 | (i.e., after the part that matches C<m/\A=[a-zA-Z]\S*\s*/>), as in:
|
|---|
| 130 |
|
|---|
| 131 | =head1 Did You Remember to C<use strict;>?
|
|---|
| 132 |
|
|---|
| 133 | In other words, the Pod processing handler for "head1" will apply the
|
|---|
| 134 | same processing to "Did You Remember to CE<lt>use strict;>?" that it
|
|---|
| 135 | would to an ordinary paragraph -- i.e., formatting codes (like
|
|---|
| 136 | "CE<lt>...>") are parsed and presumably formatted appropriately, and
|
|---|
| 137 | whitespace in the form of literal spaces and/or tabs is not
|
|---|
| 138 | significant.
|
|---|
| 139 |
|
|---|
| 140 | =item *
|
|---|
| 141 |
|
|---|
| 142 | A B<verbatim paragraph>. The first line of this paragraph must be a
|
|---|
| 143 | literal space or tab, and this paragraph must not be inside a "=begin
|
|---|
| 144 | I<identifier>", ... "=end I<identifier>" sequence unless
|
|---|
| 145 | "I<identifier>" begins with a colon (":"). That is, if a paragraph
|
|---|
| 146 | starts with a literal space or tab, but I<is> inside a
|
|---|
| 147 | "=begin I<identifier>", ... "=end I<identifier>" region, then it's
|
|---|
| 148 | a data paragraph, unless "I<identifier>" begins with a colon.
|
|---|
| 149 |
|
|---|
| 150 | Whitespace I<is> significant in verbatim paragraphs (although, in
|
|---|
| 151 | processing, tabs are probably expanded).
|
|---|
| 152 |
|
|---|
| 153 | =item *
|
|---|
| 154 |
|
|---|
| 155 | An B<ordinary paragraph>. A paragraph is an ordinary paragraph
|
|---|
| 156 | if its first line matches neither C<m/\A=[a-zA-Z]/> nor
|
|---|
| 157 | C<m/\A[ \t]/>, I<and> if it's not inside a "=begin I<identifier>",
|
|---|
| 158 | ... "=end I<identifier>" sequence unless "I<identifier>" begins with
|
|---|
| 159 | a colon (":").
|
|---|
| 160 |
|
|---|
| 161 | =item *
|
|---|
| 162 |
|
|---|
| 163 | A B<data paragraph>. This is a paragraph that I<is> inside a "=begin
|
|---|
| 164 | I<identifier>" ... "=end I<identifier>" sequence where
|
|---|
| 165 | "I<identifier>" does I<not> begin with a literal colon (":"). In
|
|---|
| 166 | some sense, a data paragraph is not part of Pod at all (i.e.,
|
|---|
| 167 | effectively it's "out-of-band"), since it's not subject to most kinds
|
|---|
| 168 | of Pod parsing; but it is specified here, since Pod
|
|---|
| 169 | parsers need to be able to call an event for it, or store it in some
|
|---|
| 170 | form in a parse tree, or at least just parse I<around> it.
|
|---|
| 171 |
|
|---|
| 172 | =back
|
|---|
| 173 |
|
|---|
| 174 | For example: consider the following paragraphs:
|
|---|
| 175 |
|
|---|
| 176 | # <- that's the 0th column
|
|---|
| 177 |
|
|---|
| 178 | =head1 Foo
|
|---|
| 179 |
|
|---|
| 180 | Stuff
|
|---|
| 181 |
|
|---|
| 182 | $foo->bar
|
|---|
| 183 |
|
|---|
| 184 | =cut
|
|---|
| 185 |
|
|---|
| 186 | Here, "=head1 Foo" and "=cut" are command paragraphs because the first
|
|---|
| 187 | line of each matches C<m/\A=[a-zA-Z]/>. "I<[space][space]>$foo->bar"
|
|---|
| 188 | is a verbatim paragraph, because its first line starts with a literal
|
|---|
| 189 | whitespace character (and there's no "=begin"..."=end" region around).
|
|---|
| 190 |
|
|---|
| 191 | The "=begin I<identifier>" ... "=end I<identifier>" commands stop
|
|---|
| 192 | paragraphs that they surround from being parsed as data or verbatim
|
|---|
| 193 | paragraphs, if I<identifier> doesn't begin with a colon. This
|
|---|
| 194 | is discussed in detail in the section
|
|---|
| 195 | L</About Data Paragraphs and "=beginE<sol>=end" Regions>.
|
|---|
| 196 |
|
|---|
| 197 | =head1 Pod Commands
|
|---|
| 198 |
|
|---|
| 199 | This section is intended to supplement and clarify the discussion in
|
|---|
| 200 | L<perlpod/"Command Paragraph">. These are the currently recognized
|
|---|
| 201 | Pod commands:
|
|---|
| 202 |
|
|---|
| 203 | =over
|
|---|
| 204 |
|
|---|
| 205 | =item "=head1", "=head2", "=head3", "=head4"
|
|---|
| 206 |
|
|---|
| 207 | This command indicates that the text in the remainder of the paragraph
|
|---|
| 208 | is a heading. That text may contain formatting codes. Examples:
|
|---|
| 209 |
|
|---|
| 210 | =head1 Object Attributes
|
|---|
| 211 |
|
|---|
| 212 | =head3 What B<Not> to Do!
|
|---|
| 213 |
|
|---|
| 214 | =item "=pod"
|
|---|
| 215 |
|
|---|
| 216 | This command indicates that this paragraph begins a Pod block. (If we
|
|---|
| 217 | are already in the middle of a Pod block, this command has no effect at
|
|---|
| 218 | all.) If there is any text in this command paragraph after "=pod",
|
|---|
| 219 | it must be ignored. Examples:
|
|---|
| 220 |
|
|---|
| 221 | =pod
|
|---|
| 222 |
|
|---|
| 223 | This is a plain Pod paragraph.
|
|---|
| 224 |
|
|---|
| 225 | =pod This text is ignored.
|
|---|
| 226 |
|
|---|
| 227 | =item "=cut"
|
|---|
| 228 |
|
|---|
| 229 | This command indicates that this line is the end of this previously
|
|---|
| 230 | started Pod block. If there is any text after "=cut" on the line, it must be
|
|---|
| 231 | ignored. Examples:
|
|---|
| 232 |
|
|---|
| 233 | =cut
|
|---|
| 234 |
|
|---|
| 235 | =cut The documentation ends here.
|
|---|
| 236 |
|
|---|
| 237 | =cut
|
|---|
| 238 | # This is the first line of program text.
|
|---|
| 239 | sub foo { # This is the second.
|
|---|
| 240 |
|
|---|
| 241 | It is an error to try to I<start> a Pod block with a "=cut" command. In
|
|---|
| 242 | that case, the Pod processor must halt parsing of the input file, and
|
|---|
| 243 | must by default emit a warning.
|
|---|
| 244 |
|
|---|
| 245 | =item "=over"
|
|---|
| 246 |
|
|---|
| 247 | This command indicates that this is the start of a list/indent
|
|---|
| 248 | region. If there is any text following the "=over", it must consist
|
|---|
| 249 | of only a nonzero positive numeral. The semantics of this numeral is
|
|---|
| 250 | explained in the L</"About =over...=back Regions"> section, further
|
|---|
| 251 | below. Formatting codes are not expanded. Examples:
|
|---|
| 252 |
|
|---|
| 253 | =over 3
|
|---|
| 254 |
|
|---|
| 255 | =over 3.5
|
|---|
| 256 |
|
|---|
| 257 | =over
|
|---|
| 258 |
|
|---|
| 259 | =item "=item"
|
|---|
| 260 |
|
|---|
| 261 | This command indicates that an item in a list begins here. Formatting
|
|---|
| 262 | codes are processed. The semantics of the (optional) text in the
|
|---|
| 263 | remainder of this paragraph are
|
|---|
| 264 | explained in the L</"About =over...=back Regions"> section, further
|
|---|
| 265 | below. Examples:
|
|---|
| 266 |
|
|---|
| 267 | =item
|
|---|
| 268 |
|
|---|
| 269 | =item *
|
|---|
| 270 |
|
|---|
| 271 | =item *
|
|---|
| 272 |
|
|---|
| 273 | =item 14
|
|---|
| 274 |
|
|---|
| 275 | =item 3.
|
|---|
| 276 |
|
|---|
| 277 | =item C<< $thing->stuff(I<dodad>) >>
|
|---|
| 278 |
|
|---|
| 279 | =item For transporting us beyond seas to be tried for pretended
|
|---|
| 280 | offenses
|
|---|
| 281 |
|
|---|
| 282 | =item He is at this time transporting large armies of foreign
|
|---|
| 283 | mercenaries to complete the works of death, desolation and
|
|---|
| 284 | tyranny, already begun with circumstances of cruelty and perfidy
|
|---|
| 285 | scarcely paralleled in the most barbarous ages, and totally
|
|---|
| 286 | unworthy the head of a civilized nation.
|
|---|
| 287 |
|
|---|
| 288 | =item "=back"
|
|---|
| 289 |
|
|---|
| 290 | This command indicates that this is the end of the region begun
|
|---|
| 291 | by the most recent "=over" command. It permits no text after the
|
|---|
| 292 | "=back" command.
|
|---|
| 293 |
|
|---|
| 294 | =item "=begin formatname"
|
|---|
| 295 |
|
|---|
| 296 | This marks the following paragraphs (until the matching "=end
|
|---|
| 297 | formatname") as being for some special kind of processing. Unless
|
|---|
| 298 | "formatname" begins with a colon, the contained non-command
|
|---|
| 299 | paragraphs are data paragraphs. But if "formatname" I<does> begin
|
|---|
| 300 | with a colon, then non-command paragraphs are ordinary paragraphs
|
|---|
| 301 | or data paragraphs. This is discussed in detail in the section
|
|---|
| 302 | L</About Data Paragraphs and "=beginE<sol>=end" Regions>.
|
|---|
| 303 |
|
|---|
| 304 | It is advised that formatnames match the regexp
|
|---|
| 305 | C<m/\A:?[-a-zA-Z0-9_]+\z/>. Implementors should anticipate future
|
|---|
| 306 | expansion in the semantics and syntax of the first parameter
|
|---|
| 307 | to "=begin"/"=end"/"=for".
|
|---|
| 308 |
|
|---|
| 309 | =item "=end formatname"
|
|---|
| 310 |
|
|---|
| 311 | This marks the end of the region opened by the matching
|
|---|
| 312 | "=begin formatname" region. If "formatname" is not the formatname
|
|---|
| 313 | of the most recent open "=begin formatname" region, then this
|
|---|
| 314 | is an error, and must generate an error message. This
|
|---|
| 315 | is discussed in detail in the section
|
|---|
| 316 | L</About Data Paragraphs and "=beginE<sol>=end" Regions>.
|
|---|
| 317 |
|
|---|
| 318 | =item "=for formatname text..."
|
|---|
| 319 |
|
|---|
| 320 | This is synonymous with:
|
|---|
| 321 |
|
|---|
| 322 | =begin formatname
|
|---|
| 323 |
|
|---|
| 324 | text...
|
|---|
| 325 |
|
|---|
| 326 | =end formatname
|
|---|
| 327 |
|
|---|
| 328 | That is, it creates a region consisting of a single paragraph; that
|
|---|
| 329 | paragraph is to be treated as a normal paragraph if "formatname"
|
|---|
| 330 | begins with a ":"; if "formatname" I<doesn't> begin with a colon,
|
|---|
| 331 | then "text..." will constitute a data paragraph. There is no way
|
|---|
| 332 | to use "=for formatname text..." to express "text..." as a verbatim
|
|---|
| 333 | paragraph.
|
|---|
| 334 |
|
|---|
| 335 | =item "=encoding encodingname"
|
|---|
| 336 |
|
|---|
| 337 | This command, which should occur early in the document (at least
|
|---|
| 338 | before any non-US-ASCII data!), declares that this document is
|
|---|
| 339 | encoded in the encoding I<encodingname>, which must be
|
|---|
| 340 | an encoding name that L<Encoding> recognizes. (Encoding's list
|
|---|
| 341 | of supported encodings, in L<Encoding::Supported>, is useful here.)
|
|---|
| 342 | If the Pod parser cannot decode the declared encoding, it
|
|---|
| 343 | should emit a warning and may abort parsing the document
|
|---|
| 344 | altogether.
|
|---|
| 345 |
|
|---|
| 346 | A document having more than one "=encoding" line should be
|
|---|
| 347 | considered an error. Pod processors may silently tolerate this if
|
|---|
| 348 | the not-first "=encoding" lines are just duplicates of the
|
|---|
| 349 | first one (e.g., if there's a "=use utf8" line, and later on
|
|---|
| 350 | another "=use utf8" line). But Pod processors should complain if
|
|---|
| 351 | there are contradictory "=encoding" lines in the same document
|
|---|
| 352 | (e.g., if there is a "=encoding utf8" early in the document and
|
|---|
| 353 | "=encoding big5" later). Pod processors that recognize BOMs
|
|---|
| 354 | may also complain if they see an "=encoding" line
|
|---|
| 355 | that contradicts the BOM (e.g., if a document with a UTF-16LE
|
|---|
| 356 | BOM has an "=encoding shiftjis" line).
|
|---|
| 357 |
|
|---|
| 358 | =back
|
|---|
| 359 |
|
|---|
| 360 | If a Pod processor sees any command other than the ones listed
|
|---|
| 361 | above (like "=head", or "=haed1", or "=stuff", or "=cuttlefish",
|
|---|
| 362 | or "=w123"), that processor must by default treat this as an
|
|---|
| 363 | error. It must not process the paragraph beginning with that
|
|---|
| 364 | command, must by default warn of this as an error, and may
|
|---|
| 365 | abort the parse. A Pod parser may allow a way for particular
|
|---|
| 366 | applications to add to the above list of known commands, and to
|
|---|
| 367 | stipulate, for each additional command, whether formatting
|
|---|
| 368 | codes should be processed.
|
|---|
| 369 |
|
|---|
| 370 | Future versions of this specification may add additional
|
|---|
| 371 | commands.
|
|---|
| 372 |
|
|---|
| 373 |
|
|---|
| 374 |
|
|---|
| 375 | =head1 Pod Formatting Codes
|
|---|
| 376 |
|
|---|
| 377 | (Note that in previous drafts of this document and of perlpod,
|
|---|
| 378 | formatting codes were referred to as "interior sequences", and
|
|---|
| 379 | this term may still be found in the documentation for Pod parsers,
|
|---|
| 380 | and in error messages from Pod processors.)
|
|---|
| 381 |
|
|---|
| 382 | There are two syntaxes for formatting codes:
|
|---|
| 383 |
|
|---|
| 384 | =over
|
|---|
| 385 |
|
|---|
| 386 | =item *
|
|---|
| 387 |
|
|---|
| 388 | A formatting code starts with a capital letter (just US-ASCII [A-Z])
|
|---|
| 389 | followed by a "<", any number of characters, and ending with the first
|
|---|
| 390 | matching ">". Examples:
|
|---|
| 391 |
|
|---|
| 392 | That's what I<you> think!
|
|---|
| 393 |
|
|---|
| 394 | What's C<dump()> for?
|
|---|
| 395 |
|
|---|
| 396 | X<C<chmod> and C<unlink()> Under Different Operating Systems>
|
|---|
| 397 |
|
|---|
| 398 | =item *
|
|---|
| 399 |
|
|---|
| 400 | A formatting code starts with a capital letter (just US-ASCII [A-Z])
|
|---|
| 401 | followed by two or more "<"'s, one or more whitespace characters,
|
|---|
| 402 | any number of characters, one or more whitespace characters,
|
|---|
| 403 | and ending with the first matching sequence of two or more ">"'s, where
|
|---|
| 404 | the number of ">"'s equals the number of "<"'s in the opening of this
|
|---|
| 405 | formatting code. Examples:
|
|---|
| 406 |
|
|---|
| 407 | That's what I<< you >> think!
|
|---|
| 408 |
|
|---|
| 409 | C<<< open(X, ">>thing.dat") || die $! >>>
|
|---|
| 410 |
|
|---|
| 411 | B<< $foo->bar(); >>
|
|---|
| 412 |
|
|---|
| 413 | With this syntax, the whitespace character(s) after the "CE<lt><<"
|
|---|
| 414 | and before the ">>" (or whatever letter) are I<not> renderable -- they
|
|---|
| 415 | do not signify whitespace, are merely part of the formatting codes
|
|---|
| 416 | themselves. That is, these are all synonymous:
|
|---|
| 417 |
|
|---|
| 418 | C<thing>
|
|---|
| 419 | C<< thing >>
|
|---|
| 420 | C<< thing >>
|
|---|
| 421 | C<<< thing >>>
|
|---|
| 422 | C<<<<
|
|---|
| 423 | thing
|
|---|
| 424 | >>>>
|
|---|
| 425 |
|
|---|
| 426 | and so on.
|
|---|
| 427 |
|
|---|
| 428 | =back
|
|---|
| 429 |
|
|---|
| 430 | In parsing Pod, a notably tricky part is the correct parsing of
|
|---|
| 431 | (potentially nested!) formatting codes. Implementors should
|
|---|
| 432 | consult the code in the C<parse_text> routine in Pod::Parser as an
|
|---|
| 433 | example of a correct implementation.
|
|---|
| 434 |
|
|---|
| 435 | =over
|
|---|
| 436 |
|
|---|
| 437 | =item C<IE<lt>textE<gt>> -- italic text
|
|---|
| 438 |
|
|---|
| 439 | See the brief discussion in L<perlpod/"Formatting Codes">.
|
|---|
| 440 |
|
|---|
| 441 | =item C<BE<lt>textE<gt>> -- bold text
|
|---|
| 442 |
|
|---|
| 443 | See the brief discussion in L<perlpod/"Formatting Codes">.
|
|---|
| 444 |
|
|---|
| 445 | =item C<CE<lt>codeE<gt>> -- code text
|
|---|
| 446 |
|
|---|
| 447 | See the brief discussion in L<perlpod/"Formatting Codes">.
|
|---|
| 448 |
|
|---|
| 449 | =item C<FE<lt>filenameE<gt>> -- style for filenames
|
|---|
| 450 |
|
|---|
| 451 | See the brief discussion in L<perlpod/"Formatting Codes">.
|
|---|
| 452 |
|
|---|
| 453 | =item C<XE<lt>topic nameE<gt>> -- an index entry
|
|---|
| 454 |
|
|---|
| 455 | See the brief discussion in L<perlpod/"Formatting Codes">.
|
|---|
| 456 |
|
|---|
| 457 | This code is unusual in that most formatters completely discard
|
|---|
| 458 | this code and its content. Other formatters will render it with
|
|---|
| 459 | invisible codes that can be used in building an index of
|
|---|
| 460 | the current document.
|
|---|
| 461 |
|
|---|
| 462 | =item C<ZE<lt>E<gt>> -- a null (zero-effect) formatting code
|
|---|
| 463 |
|
|---|
| 464 | Discussed briefly in L<perlpod/"Formatting Codes">.
|
|---|
| 465 |
|
|---|
| 466 | This code is unusual is that it should have no content. That is,
|
|---|
| 467 | a processor may complain if it sees C<ZE<lt>potatoesE<gt>>. Whether
|
|---|
| 468 | or not it complains, the I<potatoes> text should ignored.
|
|---|
| 469 |
|
|---|
| 470 | =item C<LE<lt>nameE<gt>> -- a hyperlink
|
|---|
| 471 |
|
|---|
| 472 | The complicated syntaxes of this code are discussed at length in
|
|---|
| 473 | L<perlpod/"Formatting Codes">, and implementation details are
|
|---|
| 474 | discussed below, in L</"About LE<lt>...E<gt> Codes">. Parsing the
|
|---|
| 475 | contents of LE<lt>content> is tricky. Notably, the content has to be
|
|---|
| 476 | checked for whether it looks like a URL, or whether it has to be split
|
|---|
| 477 | on literal "|" and/or "/" (in the right order!), and so on,
|
|---|
| 478 | I<before> EE<lt>...> codes are resolved.
|
|---|
| 479 |
|
|---|
| 480 | =item C<EE<lt>escapeE<gt>> -- a character escape
|
|---|
| 481 |
|
|---|
| 482 | See L<perlpod/"Formatting Codes">, and several points in
|
|---|
| 483 | L</Notes on Implementing Pod Processors>.
|
|---|
| 484 |
|
|---|
| 485 | =item C<SE<lt>textE<gt>> -- text contains non-breaking spaces
|
|---|
| 486 |
|
|---|
| 487 | This formatting code is syntactically simple, but semantically
|
|---|
| 488 | complex. What it means is that each space in the printable
|
|---|
| 489 | content of this code signifies a non-breaking space.
|
|---|
| 490 |
|
|---|
| 491 | Consider:
|
|---|
| 492 |
|
|---|
| 493 | C<$x ? $y : $z>
|
|---|
| 494 |
|
|---|
| 495 | S<C<$x ? $y : $z>>
|
|---|
| 496 |
|
|---|
| 497 | Both signify the monospace (c[ode] style) text consisting of
|
|---|
| 498 | "$x", one space, "?", one space, ":", one space, "$z". The
|
|---|
| 499 | difference is that in the latter, with the S code, those spaces
|
|---|
| 500 | are not "normal" spaces, but instead are non-breaking spaces.
|
|---|
| 501 |
|
|---|
| 502 | =back
|
|---|
| 503 |
|
|---|
| 504 |
|
|---|
| 505 | If a Pod processor sees any formatting code other than the ones
|
|---|
| 506 | listed above (as in "NE<lt>...>", or "QE<lt>...>", etc.), that
|
|---|
| 507 | processor must by default treat this as an error.
|
|---|
| 508 | A Pod parser may allow a way for particular
|
|---|
| 509 | applications to add to the above list of known formatting codes;
|
|---|
| 510 | a Pod parser might even allow a way to stipulate, for each additional
|
|---|
| 511 | command, whether it requires some form of special processing, as
|
|---|
| 512 | LE<lt>...> does.
|
|---|
| 513 |
|
|---|
| 514 | Future versions of this specification may add additional
|
|---|
| 515 | formatting codes.
|
|---|
| 516 |
|
|---|
| 517 | Historical note: A few older Pod processors would not see a ">" as
|
|---|
| 518 | closing a "CE<lt>" code, if the ">" was immediately preceded by
|
|---|
| 519 | a "-". This was so that this:
|
|---|
| 520 |
|
|---|
| 521 | C<$foo->bar>
|
|---|
| 522 |
|
|---|
| 523 | would parse as equivalent to this:
|
|---|
| 524 |
|
|---|
| 525 | C<$foo-E<gt>bar>
|
|---|
| 526 |
|
|---|
| 527 | instead of as equivalent to a "C" formatting code containing
|
|---|
| 528 | only "$foo-", and then a "bar>" outside the "C" formatting code. This
|
|---|
| 529 | problem has since been solved by the addition of syntaxes like this:
|
|---|
| 530 |
|
|---|
| 531 | C<< $foo->bar >>
|
|---|
| 532 |
|
|---|
| 533 | Compliant parsers must not treat "->" as special.
|
|---|
| 534 |
|
|---|
| 535 | Formatting codes absolutely cannot span paragraphs. If a code is
|
|---|
| 536 | opened in one paragraph, and no closing code is found by the end of
|
|---|
| 537 | that paragraph, the Pod parser must close that formatting code,
|
|---|
| 538 | and should complain (as in "Unterminated I code in the paragraph
|
|---|
| 539 | starting at line 123: 'Time objects are not...'"). So these
|
|---|
| 540 | two paragraphs:
|
|---|
| 541 |
|
|---|
| 542 | I<I told you not to do this!
|
|---|
| 543 |
|
|---|
| 544 | Don't make me say it again!>
|
|---|
| 545 |
|
|---|
| 546 | ...must I<not> be parsed as two paragraphs in italics (with the I
|
|---|
| 547 | code starting in one paragraph and starting in another.) Instead,
|
|---|
|
|---|