perlpodspec.html
来自「perl教程」· HTML 代码 · 共 1,304 行 · 第 1/5 页
HTML
1,304 行
<p>Pod parsers should, by default, expand tabs in verbatim paragraphs as
they are processed, before passing them to the formatter or other
processor. Parsers may also allow an option for overriding this.</p>
</li>
<li>
<p>Pod parsers should, by default, remove newlines from the end of
ordinary and verbatim paragraphs before passing them to the
formatter. For example, while the paragraph you're reading now
could be considered, in Pod source, to end with (and contain)
the <code>newline(s)</code> that end it, it should be processed as ending with
(and containing) the period character that ends this sentence.</p>
</li>
<li>
<p>Pod parsers, when reporting errors, should make some effort to report
an approximate line number ("Nested E<>'s in Paragraph #52, near
line 633 of Thing/Foo.pm!"), instead of merely noting the paragraph
number ("Nested E<>'s in Paragraph #52 of Thing/Foo.pm!"). Where
this is problematic, the paragraph number should at least be
accompanied by an excerpt from the paragraph ("Nested E<>'s in
Paragraph #52 of Thing/Foo.pm, which begins 'Read/write accessor for
the C<interest rate> attribute...'").</p>
</li>
<li>
<p>Pod parsers, when processing a series of verbatim paragraphs one
after another, should consider them to be one large verbatim
paragraph that happens to contain blank lines. I.e., these two
lines, which have a blank line between them:</p>
<pre>
<span class="keyword">use</span> <span class="variable">Foo</span><span class="operator">;</span>
</pre>
<pre>
print Foo->VERSION</pre>
<p>should be unified into one paragraph ("\tuse Foo;\n\n\tprint
Foo->VERSION") before being passed to the formatter or other
processor. Parsers may also allow an option for overriding this.</p>
<p>While this might be too cumbersome to implement in event-based Pod
parsers, it is straightforward for parsers that return parse trees.</p>
</li>
<li>
<p>Pod formatters, where feasible, are advised to avoid splitting short
verbatim paragraphs (under twelve lines, say) across pages.</p>
</li>
<li>
<p>Pod parsers must treat a line with only spaces and/or tabs on it as a
"blank line" such as separates paragraphs. (Some older parsers
recognized only two adjacent newlines as a "blank line" but would not
recognize a newline, a space, and a newline, as a blank line. This
is noncompliant behavior.)</p>
</li>
<li>
<p>Authors of Pod formatters/processors should make every effort to
avoid writing their own Pod parser. There are already several in
CPAN, with a wide range of interface styles -- and one of them,
Pod::Parser, comes with modern versions of Perl.</p>
</li>
<li>
<p>Characters in Pod documents may be conveyed either as literals, or by
number in E<n> codes, or by an equivalent mnemonic, as in
E<eacute> which is exactly equivalent to E<233>.</p>
<p>Characters in the range 32-126 refer to those well known US-ASCII
characters (also defined there by Unicode, with the same meaning),
which all Pod formatters must render faithfully. Characters
in the ranges 0-31 and 127-159 should not be used (neither as
literals, nor as E<number> codes), except for the
literal byte-sequences for newline (13, 13 10, or 10), and tab (9).</p>
<p>Characters in the range 160-255 refer to Latin-1 characters (also
defined there by Unicode, with the same meaning). Characters above
255 should be understood to refer to Unicode characters.</p>
</li>
<li>
<p>Be warned
that some formatters cannot reliably render characters outside 32-126;
and many are able to handle 32-126 and 160-255, but nothing above
255.</p>
</li>
<li>
<p>Besides the well-known "E<lt>" and "E<gt>" codes for
less-than and greater-than, Pod parsers must understand "E<sol>"
for "/" (solidus, slash), and "E<verbar>" for "|" (vertical bar,
pipe). Pod parsers should also understand "E<lchevron>" and
"E<rchevron>" as legacy codes for characters 171 and 187, i.e.,
"left-pointing double angle quotation mark" = "left pointing
guillemet" and "right-pointing double angle quotation mark" = "right
pointing guillemet". (These look like little "<<" and ">>", and they
are now preferably expressed with the HTML/XHTML codes "E<laquo>"
and "E<raquo>".)</p>
</li>
<li>
<p>Pod parsers should understand all "E<html>" codes as defined
in the entity declarations in the most recent XHTML specification at
<code>www.W3.org</code>. Pod parsers must understand at least the entities
that define characters in the range 160-255 (Latin-1). Pod parsers,
when faced with some unknown "E<<em>identifier</em>>" code,
shouldn't simply replace it with nullstring (by default, at least),
but may pass it through as a string consisting of the literal characters
E, less-than, <em>identifier</em>, greater-than. Or Pod parsers may offer the
alternative option of processing such unknown
"E<<em>identifier</em>>" codes by firing an event especially
for such codes, or by adding a special node-type to the in-memory
document tree. Such "E<<em>identifier</em>>" may have special meaning
to some processors, or some processors may choose to add them to
a special error report.</p>
</li>
<li>
<p>Pod parsers must also support the XHTML codes "E<quot>" for
character 34 (doublequote, "), "E<amp>" for character 38
(ampersand, &), and "E<apos>" for character 39 (apostrophe, ').</p>
</li>
<li>
<p>Note that in all cases of "E<whatever>", <em>whatever</em> (whether
an htmlname, or a number in any base) must consist only of
alphanumeric characters -- that is, <em>whatever</em> must watch
<a href="../../lib/Pod/perlfunc.html#item_m_"><code>m/\A\w+\z/</code></a>. So "E< 0 1 2 3 >" is invalid, because
it contains spaces, which aren't alphanumeric characters. This
presumably does not <em>need</em> special treatment by a Pod processor;
" 0 1 2 3 " doesn't look like a number in any base, so it would
presumably be looked up in the table of HTML-like names. Since
there isn't (and cannot be) an HTML-like entity called " 0 1 2 3 ",
this will be treated as an error. However, Pod processors may
treat "E< 0 1 2 3 >" or "E<e-acute>" as <em>syntactically</em>
invalid, potentially earning a different error message than the
error message (or warning, or event) generated by a merely unknown
(but theoretically valid) htmlname, as in "E<qacute>"
[sic]. However, Pod parsers are not required to make this
distinction.</p>
</li>
<li>
<p>Note that E<number> <em>must not</em> be interpreted as simply
"codepoint <em>number</em> in the current/native character set". It always
means only "the character represented by codepoint <em>number</em> in
Unicode." (This is identical to the semantics of &#<em>number</em>; in XML.)</p>
<p>This will likely require many formatters to have tables mapping from
treatable Unicode codepoints (such as the "\xE9" for the e-acute
character) to the escape sequences or codes necessary for conveying
such sequences in the target output format. A converter to *roff
would, for example know that "\xE9" (whether conveyed literally, or via
a E<...> sequence) is to be conveyed as "e\\*'".
Similarly, a program rendering Pod in a Mac OS application window, would
presumably need to know that "\xE9" maps to codepoint 142 in MacRoman
encoding that (at time of writing) is native for Mac OS. Such
Unicode2whatever mappings are presumably already widely available for
common output formats. (Such mappings may be incomplete! Implementers
are not expected to bend over backwards in an attempt to render
Cherokee syllabics, Etruscan runes, Byzantine musical symbols, or any
of the other weird things that Unicode can encode.) And
if a Pod document uses a character not found in such a mapping, the
formatter should consider it an unrenderable character.</p>
</li>
<li>
<p>If, surprisingly, the implementor of a Pod formatter can't find a
satisfactory pre-existing table mapping from Unicode characters to
escapes in the target format (e.g., a decent table of Unicode
characters to *roff escapes), it will be necessary to build such a
table. If you are in this circumstance, you should begin with the
characters in the range 0x00A0 - 0x00FF, which is mostly the heavily
used accented characters. Then proceed (as patience permits and
fastidiousness compels) through the characters that the (X)HTML
standards groups judged important enough to merit mnemonics
for. These are declared in the (X)HTML specifications at the
www.W3.org site. At time of writing (September 2001), the most recent
entity declaration files are:</p>
<pre>
<a href="http://www.w3.org/TR/xhtml1/DTD/xhtml-lat1.ent">http://www.w3.org/TR/xhtml1/DTD/xhtml-lat1.ent</a>
<a href="http://www.w3.org/TR/xhtml1/DTD/xhtml-special.ent">http://www.w3.org/TR/xhtml1/DTD/xhtml-special.ent</a>
<a href="http://www.w3.org/TR/xhtml1/DTD/xhtml-symbol.ent">http://www.w3.org/TR/xhtml1/DTD/xhtml-symbol.ent</a></pre>
<p>Then you can progress through any remaining notable Unicode characters
in the range 0x2000-0x204D (consult the character tables at
www.unicode.org), and whatever else strikes your fancy. For example,
in <em>xhtml-symbol.ent</em>, there is the entry:</p>
<pre>
<span class="operator"><!</span><span class="variable">ENTITY</span> <span class="variable">infin</span> <span class="string">"&#8734;"</span><span class="operator">></span> <span class="operator"><!--</span> <span class="variable">infinity</span><span class="operator">,</span> <span class="variable">U</span><span class="operator">+</span><span class="number">221E</span> <span class="variable">ISOtech</span> <span class="operator">--></span>
</pre>
<p>While the mapping "infin" to the character "\x{221E}" will (hopefully)
have been already handled by the Pod parser, the presence of the
character in this file means that it's reasonably important enough to
include in a formatter's table that maps from notable Unicode characters
to the codes necessary for rendering them. So for a Unicode-to-*roff
mapping, for example, this would merit the entry:</p>
<pre>
<span class="string">"\x{221E}"</span> <span class="operator">=></span> <span class="string">'\(in'</span><span class="operator">,</span>
</pre>
<p>It is eagerly hoped that in the future, increasing numbers of formats
(and formatters) will support Unicode characters directly (as (X)HTML
does with <code>&infin;</code>, <code>&#8734;</code>, or <code>&#x221E;</code>), reducing the need
for idiosyncratic mappings of Unicode-to-<em>my_escapes</em>.</p>
</li>
<li>
<p>It is up to individual Pod formatter to display good judgment when
confronted with an unrenderable character (which is distinct from an
unknown E<thing> sequence that the parser couldn't resolve to
anything, renderable or not). It is good practice to map Latin letters
with diacritics (like "E<eacute>"/"E<233>") to the corresponding
unaccented US-ASCII letters (like a simple character 101, "e"), but
clearly this is often not feasible, and an unrenderable character may
be represented as "?", or the like. In attempting a sane fallback
(as from E<233> to "e"), Pod formatters may use the
%Latin1Code_to_fallback table in <a href="../../Pod/Escapes.html">Pod::Escapes</a>, or
<a href="../../Text/Unidecode.html">Text::Unidecode</a>, if available.</p>
<p>For example, this Pod text:</p>
<pre>
magic is enabled if you set C<$Currency> to 'E<euro>'.</pre>
<p>may be rendered as:
"magic is enabled if you set <code>$Currency</code> to '<em>?</em>'" or as
"magic is enabled if you set <code>$Currency</code> to '<strong>[euro]</strong>'", or as
"magic is enabled if you set <code>$Currency</code> to '[x20AC]', etc.</p>
<p>A Pod formatter may also note, in a comment or warning, a list of what
unrenderable characters were encountered.</p>
</li>
<li>
<p>E<...> may freely appear in any formatting code (other than
in another E<...> or in an Z<>). That is, "X<The
E<euro>1,000,000 Solution>" is valid, as is "L<The
E<euro>1,000,000 Solution|Million::Euros>".</p>
</li>
<li>
<p>Some Pod formatters output to formats that implement non-breaking
spaces as an individual character (which I'll call "NBSP"), and
others output to formats that implement non-breaking spaces just as
spaces wrapped in a "don't break this across lines" code. Note that
at the level of Pod, both sorts of codes can occur: Pod can contain a
NBSP character (whether as a literal, or as a "E<160>" or
"E<nbsp>" code); and Pod can contain "S<foo
I<bar> baz>" codes, where "mere spaces" (character 32) in
such codes are taken to represent non-breaking spaces. Pod
parsers should consider supporting the optional parsing of "S<foo
I<bar> baz>" as if it were
"foo<em>NBSP</em>I<bar><em>NBSP</em>baz", and, going the other way, the
optional parsing of groups of words joined by NBSP's as if each group
were in a S<...> code, so that formatters may use the
representation that maps best to what the output format demands.</p>
</li>
<li>
<p>Some processors may find that the <code>S<...></code> code is easiest to
implement by replacing each space in the parse tree under the content
of the S, with an NBSP. But note: the replacement should apply <em>not</em> to
spaces in <em>all</em> text, but <em>only</em> to spaces in <em>printable</em> text. (This
distinction may or may not be evident in the particular tree/event
model implemented by the Pod parser.) For example, consider this
unusual case:</p>
<pre>
S<L</Autoloaded Functions>></pre>
<p>This means that the space in the middle of the visible link text must
not be broken across lines. In other words, it's the same as this:</p>
<pre>
L<"AutoloadedE<160>Functions"/Autoloaded Functions></pre>
<p>However, a misapplied space-to-NBSP replacement could (wrongly)
produce something equivalent to this:</p>
<pre>
L<"AutoloadedE<160>Functions"/AutoloadedE<160>Functions></pre>
<p>...which is almost definitely not going to work as a hyperlink (assuming
this formatter outputs a format supporting hypertext).</p>
<p>Formatters may choose to just not support the S format code,
especially in cases where the output format simply has no NBSP
character/code and no code for "don't break this stuff across lines".</p>
</li>
<li>
<p>Besides the NBSP character discussed above, implementors are reminded
of the existence of the other "special" character in Latin-1, the
"soft hyphen" character, also known as "discretionary hyphen",
i.e. <code>E<173></code> = <code>E<0xAD></code> =
<code>E<shy></code>). This character expresses an optional hyphenation
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?