1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035
|
<?xml version="1.0" encoding="ascii" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ascii" />
<meta name="generator" content="Docutils 0.5: http://docutils.sourceforge.net/" />
<title>The Epytext Markup Language</title>
<link rel="stylesheet" href="custom.css" type="text/css" />
</head>
<body>
<div class="document" id="the-epytext-markup-language">
<h1 class="title">The Epytext Markup Language</h1>
<!-- $Id: manual-epytext.txt 1547 2007-02-21 17:34:54Z dvarrazzo $ -->
<div class="section" id="a-brief-introduction">
<h1>A Brief Introduction</h1>
<p>Epytext is a simple lightweight markup language that lets you add formatting
and structue to docstrings. Epydoc uses that formatting and structure to
produce nicely formatted API documentation. The following example (which has
an unusually high ratio of documentaiton to code) illustrates some of the
basic features of epytext:</p>
<pre class="py-doctest">
<span class="py-keyword">def</span> <span class="py-defname">x_intercept</span>(m, b):
<span class="py-string">"""</span>
<span class="py-string"> Return the x intercept of the line M{y=m*x+b}. The X{x intercept}</span>
<span class="py-string"> of a line is the point at which it crosses the x axis (M{y=0}).</span>
<span class="py-string"> This function can be used in conjuction with L{z_transform} to</span>
<span class="py-string"> find an arbitrary function's zeros.</span>
<span class="py-string"> @type m: number</span>
<span class="py-string"> @param m: The slope of the line.</span>
<span class="py-string"> @type b: number</span>
<span class="py-string"> @param b: The y intercept of the line. The X{y intercept} of a</span>
<span class="py-string"> line is the point at which it crosses the y axis (M{x=0}).</span>
<span class="py-string"> @rtype: number</span>
<span class="py-string"> @return: the x intercept of the line M{y=m*x+b}.</span>
<span class="py-string"> """</span>
return -b/m</pre>
<p>You can compare this function definition with the <a class="reference external" href="http://epydoc.sourceforge.net/examples/epytext_example-module.html#x_intercept">API documentation</a>
generated by epydoc. Note that:</p>
<ul class="simple">
<li>Paragraphs are separated by blank lines.</li>
<li>Inline markup has the form "<em>x</em><tt class="docutils literal"><span class="pre">{</span></tt>...<tt class="docutils literal"><span class="pre">}</span></tt>", where "<em>x</em>" is a
single capital letter. This example uses inline markup to mark mathematical
expressions ("<tt class="docutils literal"><span class="pre">M{...}</span></tt>"); terms that should be indexed ("<tt class="docutils literal"><span class="pre">X{...}</span></tt>");
and links to the documentation of other objects ("<tt class="docutils literal"><span class="pre">L{...}</span></tt>").</li>
<li>Descriptions of parameters, return values, and types are marked with
"<tt class="docutils literal"><span class="pre">@</span></tt><em>field</em><tt class="docutils literal"><span class="pre">:</span></tt>" or "<tt class="docutils literal"><span class="pre">@</span></tt><em>field arg</em><tt class="docutils literal"><span class="pre">:</span></tt>", where "<em>field</em>"
identifies the kind of description, and "<em>arg</em>" specifies what object is
described.</li>
</ul>
<p>Epytext is intentionally very lightweight. If you wish to use a more
expressive markup language, I recommend <a class="reference external" href="manual-othermarkup.html#restructuredtext">reStructuredText</a>.</p>
</div>
<div class="section" id="epytext-language-overview">
<h1>Epytext Language Overview</h1>
<p>Epytext is a lightweight markup language for Python docstrings. The epytext
markup language is used by epydoc to parse docstrings and create structured API
documentation. Epytext markup is broken up into the following categories:</p>
<ul>
<li><p class="first"><strong>Block Structure</strong> divides the docstring into nested blocks of text, such
as <em>paragraphs</em> and <em>lists</em>.</p>
<blockquote>
<p>o <strong>Basic Blocks</strong> are the basic unit of block structure.</p>
<p>o <strong>Hierarchical blocks</strong> represent the nesting structure of the docstring.</p>
</blockquote>
</li>
<li><p class="first"><strong>Inline Markup</strong> marks regions of text within a basic block with properties,
such as italics and hyperlinks.</p>
</li>
</ul>
</div>
<div class="section" id="block-structure">
<h1>Block Structure</h1>
<p>Block structure is encoded using indentation, blank lines, and a handful of
special character sequences.</p>
<ul class="simple">
<li>Indentation is used to encode the nesting structure of hierarchical blocks.
The indentation of a line is defined as the number of leading spaces on that
line; and the indentation of a block is typically the indentation of its
first line.</li>
<li>Blank lines are used to separate blocks. A blank line is a line that only
contains whitespace.</li>
<li>Special character sequences are used to mark the beginnings of some blocks.
For example, '<tt class="docutils literal"><span class="pre">-</span></tt>' is used as a bullet for unordered list items, and
'<tt class="docutils literal"><span class="pre">>>></span></tt>' is used to mark <a class="reference external" href="manual-epytext.html#doctest-blocks">doctest blocks</a>.</li>
</ul>
<p>The following sections describe how to use each type of block structure.</p>
<div class="section" id="paragraphs">
<h2>Paragraphs</h2>
<p>A paragraph is the simplest type of basic block. It consists of one or more
lines of text. Paragraphs must be left justified (i.e., every line must have
the same indentation). The following example illustrates how paragraphs can be
used:</p>
<table border="1" class="docutils">
<colgroup>
<col width="50%" />
<col width="50%" />
</colgroup>
<thead valign="bottom">
<tr><th class="head">Docstring Input</th>
<th class="head">Rendered Output</th>
</tr>
</thead>
<tbody valign="top">
<tr><td><pre class="py-doctest">
<span class="py-keyword">def</span> <span class="py-defname">example</span>():
<span class="py-string">"""</span>
<span class="py-string"> This is a paragraph. Paragraphs can</span>
<span class="py-string"> span multiple lines, and can contain</span>
<span class="py-string"> I{inline markup}.</span>
<span class="py-string"> This is another paragraph. Paragraphs</span>
<span class="py-string"> are separated by blank lines.</span>
<span class="py-string"> """</span>
*[...]*</pre>
</td>
<td><p class="first">This is a paragraph. Paragraphs can span multiple lines,
and contain <em>inline markup</em>.</p>
<p class="last">This is another paragraph. Paragraphs are separated from each
other by blank lines.</p>
</td>
</tr>
</tbody>
</table>
</div>
<div class="section" id="lists">
<h2>Lists</h2>
<p>Epytext supports both ordered and unordered lists. A list consists of one or
more consecutive <em>list items</em> of the same type (ordered or unordered), with the
same indentation. Each list item is marked by a <em>bullet</em>. The bullet for
unordered list items is a single dash character (<tt class="docutils literal"><span class="pre">-</span></tt>). Bullets for ordered
list items consist of a series of numbers followed by periods, such as
<tt class="docutils literal"><span class="pre">12.</span></tt> or <tt class="docutils literal"><span class="pre">1.2.8.</span></tt>.</p>
<p>List items typically consist of a bullet followed by a space and a single
paragraph. The paragraph may be indented more than the list item's bullet;
often, the paragraph is intended two or three characters, so that its left
margin lines up with the right side of the bullet. The following example
illustrates a simple ordered list.</p>
<table border="1" class="docutils">
<colgroup>
<col width="50%" />
<col width="50%" />
</colgroup>
<thead valign="bottom">
<tr><th class="head">Docstring Input</th>
<th class="head">Rendered Output</th>
</tr>
</thead>
<tbody valign="top">
<tr><td><pre class="py-doctest">
<span class="py-keyword">def</span> <span class="py-defname">example</span>():
<span class="py-string">"""</span>
<span class="py-string"> 1. This is an ordered list item.</span>
<span class="py-string"> 2. This is a another ordered list</span>
<span class="py-string"> item.</span>
<span class="py-string"> 3. This is a third list item. Note that</span>
<span class="py-string"> the paragraph may be indented more</span>
<span class="py-string"> than the bullet.</span>
<span class="py-string"> """</span>
*[...]*</pre>
</td>
<td><ol class="first last arabic simple">
<li>This is an ordered list item.</li>
<li>This is another ordered list item.</li>
<li>This is a third list item. Note that the paragraph may be
indented more than the bullet.</li>
</ol>
</td>
</tr>
</tbody>
</table>
<p>List items can contain more than one paragraph; and they can also contain
sublists, <cite>literal blocks</cite>, and <cite>doctest blocks</cite>. All of the blocks contained
by a list item must all have equal indentation, and that indentation must be
greater than or equal to the indentation of the list item's bullet. If the
first contained block is a paragraph, it may appear on the same line as the
bullet, separated from the bullet by one or more spaces, as shown in the
previous example. All other block types must follow on separate lines.</p>
<p>Every list must be separated from surrounding blocks by indentation:</p>
<table border="1" class="docutils">
<colgroup>
<col width="50%" />
<col width="50%" />
</colgroup>
<thead valign="bottom">
<tr><th class="head">Docstring Input</th>
<th class="head">Rendered Output</th>
</tr>
</thead>
<tbody valign="top">
<tr><td><pre class="py-doctest">
<span class="py-keyword">def</span> <span class="py-defname">example</span>():
<span class="py-string">"""</span>
<span class="py-string"> This is a paragraph.</span>
<span class="py-string"> 1. This is a list item.</span>
<span class="py-string"> 2. This a second list</span>
<span class="py-string"> item.</span>
<span class="py-string"> - This is a sublist</span>
<span class="py-string"> """</span>
[...]</pre>
</td>
<td><p class="first">This is a paragraph.</p>
<ol class="last arabic simple">
<li>This is a list item.</li>
<li>This is a second list item.<ul>
<li>This is a sublist.</li>
</ul>
</li>
</ol>
</td>
</tr>
</tbody>
</table>
<p>Note that sublists must be separated from the blocks in their parent list
item by indentation. In particular, the following docstring generates an error,
since the sublist is not separated from the paragraph in its parent list item
by indentation:</p>
<table border="1" class="docutils">
<colgroup>
<col width="50%" />
<col width="50%" />
</colgroup>
<thead valign="bottom">
<tr><th class="head">Docstring Input</th>
<th class="head">Rendered Output</th>
</tr>
</thead>
<tbody valign="top">
<tr><td><pre class="py-doctest">
<span class="py-keyword">def</span> <span class="py-defname">example</span>():
<span class="py-string">"""</span>
<span class="py-string"> 1. This is a list item. Its</span>
<span class="py-string"> paragraph is indented 7 spaces.</span>
<span class="py-string"> - This is a sublist. It is</span>
<span class="py-string"> indented 7 spaces.</span>
<span class="py-string"> """</span>
<span class="py-comment">#[...]</span></pre>
</td>
<td><strong>L5: Error: Lists must be indented.</strong></td>
</tr>
</tbody>
</table>
<p>The following example illustrates how lists can be used:</p>
<table border="1" class="docutils">
<colgroup>
<col width="50%" />
<col width="50%" />
</colgroup>
<thead valign="bottom">
<tr><th class="head">Docstring Input</th>
<th class="head">Rendered Output</th>
</tr>
</thead>
<tbody valign="top">
<tr><td><pre class="py-doctest">
<span class="py-keyword">def</span> <span class="py-defname">example</span>():
<span class="py-string">"""</span>
<span class="py-string"> This is a paragraph.</span>
<span class="py-string"> 1. This is a list item.</span>
<span class="py-string"> - This is a sublist.</span>
<span class="py-string"> - The sublist contains two</span>
<span class="py-string"> items.</span>
<span class="py-string"> - The second item of the</span>
<span class="py-string"> sublist has its own sublist.</span>
<span class="py-string"> 2. This list item contains two</span>
<span class="py-string"> paragraphs and a doctest block.</span>
<span class="py-string"> >>> print 'This is a doctest block'</span>
<span class="py-string"> This is a doctest block</span>
<span class="py-string"> This is the second paragraph.</span>
<span class="py-string"> """</span>
<span class="py-comment">#[...]</span></pre>
</td>
<td><p class="first">This is a paragraph.</p>
<ol class="last arabic">
<li><p class="first">This is a list item.</p>
<ul class="simple">
<li>This is a sublist.</li>
<li>The sublist contains two items.<ul>
<li>The second item of the sublist has its own own sublist.</li>
</ul>
</li>
</ul>
</li>
<li><p class="first">This list item contains two paragraphs and a doctest block.</p>
<pre class="py-doctest">
<span class="py-prompt">>>> </span><span class="py-keyword">print</span> <span class="py-string">'This is a doctest block'</span>
<span class="py-output">This is a doctest block</span></pre>
<p>This is the second paragraph.</p>
</li>
</ol>
</td>
</tr>
</tbody>
</table>
<p>Epytext will treat any line that begins with a bullet as a list item. If you
want to include bullet-like text in a paragraph, then you must either ensure
that it is not at the beginning of the line, or use <a class="reference external" href="manual-epytext.html#escaping">escaping</a> to prevent
epytext from treating it as markup:</p>
<table border="1" class="docutils">
<colgroup>
<col width="50%" />
<col width="50%" />
</colgroup>
<thead valign="bottom">
<tr><th class="head">Docstring Input</th>
<th class="head">Rendered Output</th>
</tr>
</thead>
<tbody valign="top">
<tr><td><pre class="py-doctest">
<span class="py-keyword">def</span> <span class="py-defname">example</span>():
<span class="py-string">"""</span>
<span class="py-string"> This sentence ends with the number</span>
<span class="py-string"> 1. Epytext can't tell if the "1."</span>
<span class="py-string"> is a bullet or part of the paragraph,</span>
<span class="py-string"> so it generates an error.</span>
<span class="py-string"> """</span>
<span class="py-comment">#[...]</span></pre>
</td>
<td><strong>L4: Error: Lists must be indented.</strong></td>
</tr>
<tr><td><pre class="py-doctest">
<span class="py-keyword">def</span> <span class="py-defname">example</span>():
<span class="py-string">"""</span>
<span class="py-string"> This sentence ends with the number 1.</span>
<span class="py-string"> This sentence ends with the number</span>
<span class="py-string"> E{1}.</span>
<span class="py-string"> """</span>
<span class="py-comment">#[...]</span></pre>
</td>
<td><p class="first">This sentence ends with the number 1.</p>
<p class="last">This sentence ends with the number 1.</p>
</td>
</tr>
</tbody>
</table>
</div>
<div class="section" id="sections">
<h2>Sections</h2>
<p>A section consists of a heading followed by one or more child blocks.</p>
<ul class="simple">
<li>The heading is a single underlined line of text. Top-level section headings
are underlined with the '<tt class="docutils literal"><span class="pre">=</span></tt>' character; subsection headings are
underlined with the '<tt class="docutils literal"><span class="pre">-</span></tt>' character; and subsubsection headings are
underlined with the '<tt class="docutils literal"><span class="pre">~</span></tt>' character. The length of the underline must
exactly match the length of the heading.</li>
<li>The child blocks can be paragraphs, lists, literal blocks, doctest blocks,
or sections. Each child must have equal indentation, and that indentation
must be greater than or equal to the heading's indentation.</li>
</ul>
<p>The following example illustrates how sections can be used:</p>
<table border="1" class="docutils">
<colgroup>
<col width="50%" />
<col width="50%" />
</colgroup>
<thead valign="bottom">
<tr><th class="head">Docstring Input</th>
<th class="head">Rendered Output</th>
</tr>
</thead>
<tbody valign="top">
<tr><td><pre class="py-doctest">
<span class="py-keyword">def</span> <span class="py-defname">example</span>():
<span class="py-string">"""</span>
<span class="py-string"> This paragraph is not in any section.</span>
<span class="py-string"> Section 1</span>
<span class="py-string"> =========</span>
<span class="py-string"> This is a paragraph in section 1.</span>
<span class="py-string"> Section 1.1</span>
<span class="py-string"> -----------</span>
<span class="py-string"> This is a paragraph in section 1.1.</span>
<span class="py-string"> Section 2</span>
<span class="py-string"> =========</span>
<span class="py-string"> This is a paragraph in section 2.</span>
<span class="py-string"> """</span>
<span class="py-comment">#[...]</span></pre>
</td>
<td><p class="h1 first">Section 1</p>
<p>This is a paragraph in section 1.</p>
<p class="h2">Section 1.1</p>
<p>This is a paragraph in section 1.1.</p>
<p class="h1">Section 2</p>
<p class="last">This is a paragraph in section 2.</p>
</td>
</tr>
</tbody>
</table>
</div>
<div class="section" id="literal-blocks">
<h2>Literal Blocks</h2>
<p>Literal blocks are used to represent "preformatted" text. Everything within a
literal block should be displayed exactly as it appears in plaintext. In
particular:</p>
<ul class="simple">
<li>Spaces and newlines are preserved.</li>
<li>Text is shown in a monospaced font.</li>
<li>Inline markup is not detected.</li>
</ul>
<p>Literal blocks are introduced by paragraphs ending in the special sequence
"<tt class="docutils literal"><span class="pre">::</span></tt>". Literal blocks end at the first line whose indentation is equal to
or less than that of the paragraph that introduces them. The following example
shows how literal blocks can be used:</p>
<table border="1" class="docutils">
<colgroup>
<col width="50%" />
<col width="50%" />
</colgroup>
<thead valign="bottom">
<tr><th class="head">Docstring Input</th>
<th class="head">Rendered Output</th>
</tr>
</thead>
<tbody valign="top">
<tr><td><pre class="py-doctest">
<span class="py-keyword">def</span> <span class="py-defname">example</span>():
<span class="py-string">"""</span>
<span class="py-string"> The following is a literal block::</span>
<span class="py-string"> Literal /</span>
<span class="py-string"> / Block</span>
<span class="py-string"> This is a paragraph following the</span>
<span class="py-string"> literal block.</span>
<span class="py-string"> """</span>
<span class="py-comment">#[...]</span></pre>
</td>
<td><p class="first">The following is a literal block:</p>
<pre class="literal-block">
Literal /
/ Block
</pre>
<p class="last">This is a paragraph following the literal block.</p>
</td>
</tr>
</tbody>
</table>
<p>Literal blocks are indented relative to the paragraphs that introduce them;
for example, in the previous example, the word "Literal" is displayed with four
leading spaces, not eight. Also, note that the double colon ("<tt class="docutils literal"><span class="pre">::</span></tt>") that
introduces the literal block is rendered as a single colon.</p>
</div>
<div class="section" id="doctest-blocks">
<h2>Doctest Blocks</h2>
<p>Doctest blocks contain examples consisting of Python expressions and their
output. Doctest blocks can be used by the doctest module to test the
documented object. Doctest blocks begin with the special sequence
"<tt class="docutils literal"><span class="pre">>>></span></tt>". Doctest blocks are delimited from surrounding blocks by blank lines.
Doctest blocks may not contain blank lines. The following example shows how
doctest blocks can be used:</p>
<table border="1" class="docutils">
<colgroup>
<col width="50%" />
<col width="50%" />
</colgroup>
<thead valign="bottom">
<tr><th class="head">Docstring Input</th>
<th class="head">Rendered Output</th>
</tr>
</thead>
<tbody valign="top">
<tr><td><pre class="py-doctest">
<span class="py-keyword">def</span> <span class="py-defname">example</span>():
<span class="py-string">"""</span>
<span class="py-string"> The following is a doctest block:</span>
<span class="py-string"> >>> print (1+3,</span>
<span class="py-more"> </span><span class="py-string"> ... 3+5)</span>
<span class="py-string"> (4, 8)</span>
<span class="py-string"> >>> 'a-b-c-d-e'.split('-')</span>
<span class="py-string"> ['a', 'b', 'c', 'd', 'e']</span>
<span class="py-string"> This is a paragraph following the</span>
<span class="py-string"> doctest block.</span>
<span class="py-string"> """</span>
<span class="py-comment">#[...]</span></pre>
</td>
<td><p class="first">The following is a doctest block:</p>
<pre class="py-doctest">
<span class="py-prompt">>>> </span><span class="py-keyword">print</span> (1+3,
<span class="py-more">... </span> 3+5)
<span class="py-output">(4, 8)</span>
<span class="py-output"></span><span class="py-prompt">>>> </span><span class="py-string">'a-b-c-d-e'</span>.split(<span class="py-string">'-'</span>)
<span class="py-output">['a', 'b', 'c', 'd', 'e']</span></pre>
<p class="last">This is a paragraph following the doctest block.</p>
</td>
</tr>
</tbody>
</table>
</div>
<div class="section" id="fields">
<h2>Fields</h2>
<p>Fields are used to describe specific properties of a documented object. For
example, fields can be used to define the parameters and return value of a
function; the instance variables of a class; and the author of a module. Each
field is marked by a <em>field tag</em>, which consist of an at sign ('<tt class="docutils literal"><span class="pre">@</span></tt>')
followed by a <em>field name</em>, optionally followed by a space and a <em>field
argument</em>, followed by a colon ('<tt class="docutils literal"><span class="pre">:</span></tt>'). For example, '<tt class="docutils literal"><span class="pre">@return:</span></tt>' and
'<tt class="docutils literal"><span class="pre">@param</span> <span class="pre">x:</span></tt>' are field tags.</p>
<p>Fields can contain paragraphs, lists, literal blocks, and doctest blocks.
All of the blocks contained by a field must all have equal indentation, and
that indentation must be greater than or equal to the indentation of the
field's tag. If the first contained block is a paragraph, it may appear on the
same line as the field tag, separated from the field tag by one or more spaces.
All other block types must follow on separate lines.</p>
<p>Fields must be placed at the end of the docstring, after the description of
the object. Fields may be included in any order.</p>
<p>Fields do not need to be separated from other blocks by a blank line. Any line
that begins with a field tag followed by a space or newline is considered a
field.</p>
<p>The following example illustrates how fields can be used:</p>
<table border="1" class="docutils">
<colgroup>
<col width="50%" />
<col width="50%" />
</colgroup>
<thead valign="bottom">
<tr><th class="head">Docstring Input</th>
<th class="head">Rendered Output</th>
</tr>
</thead>
<tbody valign="top">
<tr><td><pre class="py-doctest">
<span class="py-keyword">def</span> <span class="py-defname">example</span>():
<span class="py-string">"""</span>
<span class="py-string"> @param x: This is a description of</span>
<span class="py-string"> the parameter x to a function.</span>
<span class="py-string"> Note that the description is</span>
<span class="py-string"> indented four spaces.</span>
<span class="py-string"> @type x: This is a description of</span>
<span class="py-string"> x's type.</span>
<span class="py-string"> @return: This is a description of</span>
<span class="py-string"> the function's return value.</span>
<span class="py-string"> It contains two paragraphs.</span>
<span class="py-string"> """</span>
<span class="py-comment">#[...]</span></pre>
</td>
<td><dl class="first last docutils">
<dt><strong>Parameters:</strong></dt>
<dd><p class="first"><strong>x</strong> - This is a description of the parameter x to a function.
Note that the description is indented four spaces.</p>
<blockquote class="last">
<em>(type=This is a description of x's type.)</em></blockquote>
</dd>
<dt><strong>Returns:</strong></dt>
<dd><p class="first">This is a description of the function's return value.</p>
<p class="last">It contains two paragraphs.</p>
</dd>
</dl>
</td>
</tr>
</tbody>
</table>
<p>For a list of the fields that are supported by epydoc, see the <cite>epydoc fields</cite>
chapter.</p>
</div>
</div>
<div class="section" id="inline-markup">
<h1>Inline Markup</h1>
<p>Inline markup has the form '<tt class="docutils literal"><span class="pre">x{...}</span></tt>', where <tt class="docutils literal"><span class="pre">x</span></tt> is a single capital letter
that specifies how the text between the braces should be rendered. Inline
markup is recognized within paragraphs and section headings. It is <em>not</em>
recognized within literal and doctest blocks. Inline markup can contain
multiple words, and can span multiple lines. Inline markup may be nested.</p>
<p>A matching pair of curly braces is only interpreted as inline markup if the
left brace is immediately preceeded by a capital letter. So in most cases, you
can use curly braces in your text without any form of escaping. However, you do
need to escape curly braces when:</p>
<ol class="arabic simple">
<li>You want to include a single (un-matched) curly brace.</li>
<li>You want to preceed a matched pair of curly braces with a capital letter.</li>
</ol>
<p>Note that there is no valid Python expression where a pair of matched curly
braces is immediately preceeded by a capital letter (except within string
literals). In particular, you never need to escape braces when writing Python
dictionaries. See also <a class="reference external" href="manual-epytext.html#escaping">escaping</a>.</p>
<div class="section" id="basic-inline-markup">
<h2>Basic Inline Markup</h2>
<blockquote>
Epytext defines four types of inline markup that specify how text should be
displayed:</blockquote>
<ul class="simple">
<li><tt class="docutils literal"><span class="pre">I{...}</span></tt>: Italicized text.</li>
<li><tt class="docutils literal"><span class="pre">B{...}</span></tt>: Bold-faced text.</li>
<li><tt class="docutils literal"><span class="pre">C{...}</span></tt>: Source code or a Python identifier.</li>
<li><tt class="docutils literal"><span class="pre">M{...}</span></tt>: A mathematical expression.</li>
</ul>
<p>By default, source code is rendered in a fixed width font; and mathematical
expressions are rendered in italics. But those defaults may be changed by
modifying the CSS stylesheet. The following example illustrates how the four
basic markup types can be used:</p>
<table border="1" class="docutils">
<colgroup>
<col width="50%" />
<col width="50%" />
</colgroup>
<thead valign="bottom">
<tr><th class="head">Docstring Input</th>
<th class="head">Rendered Output</th>
</tr>
</thead>
<tbody valign="top">
<tr><td><pre class="py-doctest">
<span class="py-keyword">def</span> <span class="py-defname">example</span>():
<span class="py-string">"""</span>
<span class="py-string"> I{B{Inline markup} may be nested; and</span>
<span class="py-string"> it may span} multiple lines.</span>
<span class="py-string"> - I{Italicized text}</span>
<span class="py-string"> - B{Bold-faced text}</span>
<span class="py-string"> - C{Source code}</span>
<span class="py-string"> - M{Math}</span>
<span class="py-string"> Without the capital letter, matching</span>
<span class="py-string"> braces are not interpreted as markup:</span>
<span class="py-string"> C{my_dict={1:2, 3:4}}.</span>
<span class="py-string"> """</span>
<span class="py-comment">#[...]</span></pre>
</td>
<td><p class="first"><strong>Inline markup</strong> <em>may be nested</em>; and it may span multiple lines.</p>
<ul class="simple">
<li><em>Italicized text</em></li>
<li><strong>Bold-faced text</strong></li>
<li><tt class="docutils literal"><span class="pre">Source</span> <span class="pre">code</span></tt></li>
<li>Math: <em>m*x+b</em></li>
</ul>
<p class="last">Without the capital letter, matching braces are not interpreted as
markup: <tt class="docutils literal"><span class="pre">my_dict={1:2,</span> <span class="pre">3:4}</span></tt>.</p>
</td>
</tr>
</tbody>
</table>
</div>
<div class="section" id="urls">
<h2>URLs</h2>
<p>The inline markup construct <tt class="docutils literal"><span class="pre">U{</span></tt><em>text<url></em><tt class="docutils literal"><span class="pre">}</span></tt> is used to create links
to external URLs and URIs. '<em>text</em>' is the text that should be displayed for
the link, and '<em>url</em>' is the target of the link. If you wish to use the URL as
the text for the link, you can simply write "<tt class="docutils literal"><span class="pre">U{</span></tt><em>url</em><tt class="docutils literal"><span class="pre">}</span></tt>". Whitespace
within URL targets is ignored. In particular, URL targets may be split over
multiple lines. The following example illustrates how URLs can be used:</p>
<table border="1" class="docutils">
<colgroup>
<col width="50%" />
<col width="50%" />
</colgroup>
<thead valign="bottom">
<tr><th class="head">Docstring Input</th>
<th class="head">Rendered Output</th>
</tr>
</thead>
<tbody valign="top">
<tr><td><pre class="py-doctest">
<span class="py-keyword">def</span> <span class="py-defname">example</span>():
<span class="py-string">"""</span>
<span class="py-string"> - U{www.python.org}</span>
<span class="py-string"> - U{http://www.python.org}</span>
<span class="py-string"> - U{The epydoc homepage<http://</span>
<span class="py-string"> epydoc.sourceforge.net>}</span>
<span class="py-string"> - U{The B{Python} homepage</span>
<span class="py-string"> <www.python.org>}</span>
<span class="py-string"> - U{Edward Loper<mailto:edloper@</span>
<span class="py-string"> gradient.cis.upenn.edu>}</span>
<span class="py-string"> """</span>
<span class="py-comment">#[...]</span></pre>
</td>
<td><ul class="first last simple">
<li><a class="reference external" href="http://www.python.org">www.python.org</a></li>
<li><a class="reference external" href="http://www.python.org">http://www.python.org</a></li>
<li><a class="reference external" href="http://epydoc.sourceforge.net">The epydoc homepage</a></li>
<li><a class="reference external" href="http://www.python.org">The <strong>Python</strong> homepage</a></li>
<li><a class="reference external" href="mailto:edloper@gradient.cis.upenn.edu">Edward Loper</a></li>
</ul>
</td>
</tr>
</tbody>
</table>
</div>
<div class="section" id="documentation-crossreference-links">
<h2>Documentation Crossreference Links</h2>
<p>The inline markup construct '<tt class="docutils literal"><span class="pre">L{</span></tt><em>text<object></em><tt class="docutils literal"><span class="pre">}</span></tt>' is used to create
links to the documentation for other Python objects. '<em>text</em>' is the text that
should be displayed for the link, and '<em>object</em>' is the name of the Python
object that should be linked to. If you wish to use the name of the Python
object as the text for the link, you can simply write <tt class="docutils literal"><span class="pre">L{</span></tt><em>object</em>}``.
Whitespace within object names is ignored. In particular, object names may be
split over multiple lines. The following example illustrates how documentation
crossreference links can be used:</p>
<table border="1" class="docutils">
<colgroup>
<col width="50%" />
<col width="50%" />
</colgroup>
<thead valign="bottom">
<tr><th class="head">Docstring Input</th>
<th class="head">Rendered Output</th>
</tr>
</thead>
<tbody valign="top">
<tr><td><pre class="py-doctest">
<span class="py-keyword">def</span> <span class="py-defname">example</span>():
<span class="py-string">"""</span>
<span class="py-string"> - L{x_transform}</span>
<span class="py-string"> - L{search<re.search>}</span>
<span class="py-string"> - L{The I{x-transform} function</span>
<span class="py-string"> <x_transform>}</span>
<span class="py-string"> """</span>
<span class="py-comment">#[...]</span></pre>
</td>
<td><ul class="first last simple">
<li><a class="reference external" href="http://www.example.com">x_transform</a></li>
<li><a class="reference external" href="http://www.example.com">search</a></li>
<li><a class="reference external" href="http://www.example.com">The x-transform function</a></li>
</ul>
</td>
</tr>
</tbody>
</table>
<p>In order to find the object that corresponds to a given name, epydoc checks the
following locations, in order:</p>
<ol class="arabic simple">
<li>If the link is made from a class or method docstring, then epydoc checks for
a method, instance variable, or class variable with the given name.</li>
<li>Next, epydoc looks for an object with the given name in the current module.</li>
<li>Epydoc then tries to import the given name as a module. If the current
module is contained in a package, then epydoc will also try importing the
given name from all packages containing the current module.</li>
<li>Epydoc then tries to divide the given name into a module name and an
object name, and to import the object from the module. If the current module
is contained in a package, then epydoc will also try importing the module
name from all packages containing the current module.</li>
<li>Finally, epydoc looks for a class name in any module with the given name.
This is only returned if there is a single class with such name.</li>
</ol>
<p>If no object is found that corresponds with the given name, then epydoc
issues a warning.</p>
</div>
<div class="section" id="indexed-terms">
<h2>Indexed Terms</h2>
<p>Epydoc automatically creates an index of term definitions for the API
documentation. The inline markup construct '<tt class="docutils literal"><span class="pre">X{...}</span></tt>' is used to mark terms
for inclusion in the index. The term itself will be italicized; and a link will
be created from the index page to the location of the term in the text. The
following example illustrates how index terms can be used:</p>
<table border="1" class="docutils">
<colgroup>
<col width="50%" />
<col width="50%" />
</colgroup>
<thead valign="bottom">
<tr><th class="head">Docstring Input</th>
<th class="head">Rendered Output</th>
</tr>
</thead>
<tbody valign="top">
<tr><td><pre class="py-doctest">
<span class="py-keyword">def</span> <span class="py-defname">example</span>():
<span class="py-string">"""</span>
<span class="py-string"> An X{index term} is a term that</span>
<span class="py-string"> should be included in the index.</span>
<span class="py-string"> """</span>
<span class="py-comment">#[...]</span></pre>
</td>
<td><p class="first">An <em>index term</em> is a term that should be included in the index.</p>
<blockquote class="last">
<table border="1" class="docutils">
<colgroup>
<col width="46%" />
<col width="54%" />
</colgroup>
<thead valign="bottom">
<tr><th class="head" colspan="2">Index</th>
</tr>
</thead>
<tbody valign="top">
<tr><td>index term</td>
<td><em>example</em></td>
</tr>
<tr><td>x intercept</td>
<td><em>x_intercept</em></td>
</tr>
<tr><td>y intercept</td>
<td><em>x_intercept</em></td>
</tr>
</tbody>
</table>
</blockquote>
</td>
</tr>
</tbody>
</table>
</div>
<div class="section" id="symbols">
<h2>Symbols</h2>
<p>Symbols are used to insert special characters in your documentation. A symbol
has the form '<tt class="docutils literal"><span class="pre">S{code}</span></tt>', where code is a symbol code that specifies what
character should be produced. The following example illustrates how symbols can
be used to generate special characters:</p>
<!-- This data file has been placed in the public domain. -->
<!-- Derived from the Unicode character mappings available from
<http://www.w3.org/2003/entities/xml/>.
Processed by unicode2rstsubs.py, part of Docutils:
<http://docutils.sourceforge.net>. -->
<table border="1" class="docutils">
<colgroup>
<col width="50%" />
<col width="50%" />
</colgroup>
<thead valign="bottom">
<tr><th class="head">Docstring Input</th>
<th class="head">Rendered Output</th>
</tr>
</thead>
<tbody valign="top">
<tr><td><pre class="py-doctest">
<span class="py-keyword">def</span> <span class="py-defname">example</span>():
<span class="py-string">"""</span>
<span class="py-string"> Symbols can be used in equations:</span>
<span class="py-string"> - S{sum}S{alpha}/x S{<=} S{beta}</span>
<span class="py-string"> S{<-} and S{larr} both give left</span>
<span class="py-string"> arrows. Some other arrows are</span>
<span class="py-string"> S{rarr}, S{uarr}, and S{darr}.</span>
<span class="py-string"> """</span>
<span class="py-comment">#[...]</span></pre>
</td>
<td><p class="first">Symbols can be used in equations:</p>
<ul class="simple">
<li>∑ α/<em>x</em> ≤ β</li>
</ul>
<p class="last">← and ← both give left
arrows. Some other arrows are
→, ↑, and ↓.</p>
</td>
</tr>
</tbody>
</table>
<p>Although symbols can be quite useful, you should keep in mind that they can
make it harder to read your docstring in plaintext. In general, symbols should
be used sparingly. For a complete list of the symbols that are currently
supported, see the reference documentation for <a class="reference external" href="http://epydoc.sourceforge.net/api/epydoc.markup.epytext-module.html#SYMBOLS"><tt class="docutils literal"><span class="pre">epytext.SYMBOLS</span></tt></a>.</p>
</div>
<div class="section" id="escaping">
<h2>Escaping</h2>
<p>Escaping is used to write text that would otherwise be interpreted as epytext
markup. Epytext was carefully constructed to minimize the need for this type
of escaping; but sometimes, it is unavoidable. Escaped text has the form
'<tt class="docutils literal"><span class="pre">E{</span></tt><em>code</em><tt class="docutils literal"><span class="pre">}</span></tt>', where code is an escape code that specifies what
character should be produced. If the escape code is a single character (other
than '<tt class="docutils literal"><span class="pre">{</span></tt>' or '<tt class="docutils literal"><span class="pre">}</span></tt>'), then that character is produced. For example, to
begin a paragraph with a dash (which would normally signal a list item), write
'<tt class="docutils literal"><span class="pre">E{-}</span></tt>'. In addition, two special escape codes are defined: '<tt class="docutils literal"><span class="pre">E{lb}</span></tt>'
produces a left curly brace ('<tt class="docutils literal"><span class="pre">{</span></tt>'); and '<tt class="docutils literal"><span class="pre">E{rb}</span></tt>' produces a right curly
brace ('<tt class="docutils literal"><span class="pre">}</span></tt>'). The following example illustrates how escaping can be used:</p>
<table border="1" class="docutils">
<colgroup>
<col width="50%" />
<col width="50%" />
</colgroup>
<thead valign="bottom">
<tr><th class="head">Docstring Input</th>
<th class="head">Rendered Output</th>
</tr>
</thead>
<tbody valign="top">
<tr><td><pre class="py-doctest">
<span class="py-keyword">def</span> <span class="py-defname">example</span>():
<span class="py-string">"""</span>
<span class="py-string"> This paragraph ends with two</span>
<span class="py-string"> colons, but does not introduce</span>
<span class="py-string"> a literal blockE{:}E{:}</span>
<span class="py-string"> E{-} This is not a list item.</span>
<span class="py-string"> Escapes can be used to write</span>
<span class="py-string"> unmatched curly braces:</span>
<span class="py-string"> E{rb}E{lb}</span>
<span class="py-string"> """</span>
<span class="py-comment">#[...]</span></pre>
</td>
<td><p class="first">This paragraph ends with two colons, but does not introduce a literal
block::</p>
<p>- This is not a list item.</p>
<p class="last">Escapes can be used to write unmatched curly braces: }{</p>
</td>
</tr>
</tbody>
</table>
</div>
<div class="section" id="graphs">
<h2>Graphs</h2>
<p>The inline markup construct '<tt class="docutils literal"><span class="pre">G{</span></tt><em>graphtype args...</em><tt class="docutils literal"><span class="pre">}</span></tt>' is used to
insert automatically generated graphs. The following graphs generation
constructions are currently defines:</p>
<table border="1" class="docutils">
<colgroup>
<col width="50%" />
<col width="50%" />
</colgroup>
<thead valign="bottom">
<tr><th class="head">Markup</th>
<th class="head">Description</th>
</tr>
</thead>
<tbody valign="top">
<tr><td><tt class="docutils literal"><span class="pre">G{classtree</span></tt> <em>classes...</em><tt class="docutils literal"><span class="pre">}</span></tt></td>
<td>Display a class hierarchy for the given
class or classes (including all
superclasses & subclasses). If no class
is specified, and the directive is used
in a class's docstring, then that
class's class hierarchy will be
displayed.</td>
</tr>
<tr><td><tt class="docutils literal"><span class="pre">G{packagetree</span></tt> <em>modules...</em><tt class="docutils literal"><span class="pre">}</span></tt></td>
<td>Display a package hierarchy for the
given module or modules (including all
subpackages and submodules). If no
module is specified, and the directive
is used in a module's docstring, then
that module's package hierarchy will be
displayed.</td>
</tr>
<tr><td><tt class="docutils literal"><span class="pre">G{importgraph</span></tt> <em>modules...</em><tt class="docutils literal"><span class="pre">}</span></tt></td>
<td>Display an import graph for the given
module or modules. If no module is
specified, and the directive is used in
a module's docstring, then that
module's import graph will be
displayed.</td>
</tr>
<tr><td><tt class="docutils literal"><span class="pre">G{callgraph</span></tt> <em>functions...</em><tt class="docutils literal"><span class="pre">}</span></tt></td>
<td>Display a call graph for the given
function or functions. If no function
is specified, and the directive is used
in a function's docstring, then that
function's call graph will be
displayed.</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="section" id="characters">
<h1>Characters</h1>
<div class="section" id="valid-characters">
<h2>Valid Characters</h2>
<p>Valid characters for an epytext docstring are space (<tt class="docutils literal"><span class="pre">\040</span></tt>); newline
(<tt class="docutils literal"><span class="pre">\012</span></tt>); and any letter, digit, or punctuation, as defined by the current
locale. Control characters (<tt class="docutils literal"><span class="pre">\000</span></tt>-<tt class="docutils literal"><span class="pre">\010`</span> <span class="pre">and</span> <span class="pre">``\013</span></tt>-<tt class="docutils literal"><span class="pre">\037</span></tt>) are not
valid content characters. Tabs (<tt class="docutils literal"><span class="pre">\011</span></tt>) are expanded to spaces, using the
same algorithm used by the Python parser. Carridge-return/newline pairs
(<tt class="docutils literal"><span class="pre">\015\012</span></tt>) are converted to newlines.</p>
</div>
<div class="section" id="content-characters">
<h2>Content Characters</h2>
<p>Characters in a docstring that are not involved in markup are called <em>content characters</em>. Content characters are always displayed as-is. In particular, HTML
codes are not passed through. For example, consider the following example:</p>
<table border="1" class="docutils">
<colgroup>
<col width="50%" />
<col width="50%" />
</colgroup>
<thead valign="bottom">
<tr><th class="head">Docstring Input</th>
<th class="head">Rendered Output</th>
</tr>
</thead>
<tbody valign="top">
<tr><td><pre class="py-doctest">
<span class="py-keyword">def</span> <span class="py-defname">example</span>():
<span class="py-string">"""</span>
<span class="py-string"> <B>test</B></span>
<span class="py-string"> """</span>
<span class="py-comment">#[...]</span></pre>
</td>
<td><B>test</B></td>
</tr>
</tbody>
</table>
<p>The docstring is rendered as <tt class="docutils literal"><span class="pre"><B>test</B></span></tt>, and not as the word "test" in
bold face.</p>
</div>
<div class="section" id="spaces-and-newlines">
<h2>Spaces and Newlines</h2>
<p>In general, spaces and newlines within docstrings are treated as soft spaces.
In other words, sequences of spaces and newlines (that do not contain a blank
line) are rendered as a single space, and words may wrapped at spaces. However,
within literal blocks and doctest blocks, spaces and newlines are preserved,
and no word-wrapping occurs; and within URL targets and documentation link
targets, whitespace is ignored.</p>
</div>
</div>
</div>
<table width="100%" class="navbox" cellpadding="1" cellspacing="0">
<tr>
<a class="nav" href="index.html">
<td align="center" width="20%" class="nav">
<a class="nav" href="index.html">
Home</a></td></a>
<a class="nav" href="installing.html">
<td align="center" width="20%" class="nav">
<a class="nav" href="installing.html">
Installing Epydoc</a></td></a>
<a class="nav" href="using.html">
<td align="center" width="20%" class="nav">
<a class="nav" href="using.html">
Using Epydoc</a></td></a>
<a class="nav" href="epytext.html">
<td align="center" width="20%" class="nav">
<a class="nav" href="epytext.html">
Epytext</a></td></a>
<td align="center" width="20%" class="nav">
<A href="http://sourceforge.net/projects/epydoc">
<IMG src="sflogo.png"
width="88" height="26" border="0" alt="SourceForge"
align="top"/></A></td>
</tr>
</table>
</body>
</html>
|