[Epydoc-commits] SF.net SVN: epydoc: [1571] branches/exp-text_node/epydoc/src/epydoc
Brought to you by:
edloper
|
From: <dva...@us...> - 2007-03-06 19:24:15
|
Revision: 1571
http://svn.sourceforge.net/epydoc/?rev=1571&view=rev
Author: dvarrazzo
Date: 2007-03-06 11:24:12 -0800 (Tue, 06 Mar 2007)
Log Message:
-----------
- Actually, it is not really required to add a new token: PARA and TEXT are
almost always treated the same way. Using an attribute is enough.
Modified Paths:
--------------
branches/exp-text_node/epydoc/src/epydoc/docstringparser.py
branches/exp-text_node/epydoc/src/epydoc/markup/epytext.py
branches/exp-text_node/epydoc/src/epydoc/test/epytext.doctest
Modified: branches/exp-text_node/epydoc/src/epydoc/docstringparser.py
===================================================================
--- branches/exp-text_node/epydoc/src/epydoc/docstringparser.py 2007-03-05 02:18:17 UTC (rev 1570)
+++ branches/exp-text_node/epydoc/src/epydoc/docstringparser.py 2007-03-06 19:24:12 UTC (rev 1571)
@@ -507,7 +507,7 @@
"""A ParsedDocstring containing the text 'Returns'. This is used to
construct summary descriptions for routines that have empty C{descr},
but non-empty C{return_descr}."""
-RETURN_PDS._tree.children[0].tag = "text"
+RETURN_PDS._tree.children[0].attribs['inline'] = True
######################################################################
#{ Field Processing Error Messages
Modified: branches/exp-text_node/epydoc/src/epydoc/markup/epytext.py
===================================================================
--- branches/exp-text_node/epydoc/src/epydoc/markup/epytext.py 2007-03-05 02:18:17 UTC (rev 1570)
+++ branches/exp-text_node/epydoc/src/epydoc/markup/epytext.py 2007-03-06 19:24:12 UTC (rev 1571)
@@ -286,7 +286,7 @@
_pop_completed_blocks(token, stack, indent_stack)
# If Token has type PARA, colorize and add the new paragraph
- if token.tag in (Token.PARA, Token.TEXT):
+ if token.tag == Token.PARA:
_add_para(doc, token, stack, indent_stack, errors)
# If Token has type HEADING, add the new section
@@ -366,7 +366,9 @@
indent_stack[-1] = para_token.indent
if para_token.indent == indent_stack[-1]:
# Colorize the paragraph and add it.
- para = _colorize(doc, para_token, errors, tagName=para_token.tag)
+ para = _colorize(doc, para_token, errors)
+ if para_token.inline:
+ para.attribs['inline'] = True
stack[-1].children.append(para)
else:
estr = "Improper paragraph indentation."
@@ -511,10 +513,9 @@
"""
C{Token}s are an intermediate data structure used while
constructing the structuring DOM tree for a formatted docstring.
- There are six types of C{Token}:
+ There are five types of C{Token}:
- Paragraphs
- - Text
- Literal blocks
- Doctest blocks
- Headings
@@ -534,9 +535,8 @@
@type tag: C{string}
@ivar tag: This C{Token}'s type. Possible values are C{Token.PARA}
- (paragraph), C{Token.TEXT} (text node), C{Token.LBLOCK}
- (literal block), C{Token.DTBLOCK} (doctest block), C{Token.HEADINGC},
- and C{Token.BULLETC}.
+ (paragraph), C{Token.LBLOCK} (literal block), C{Token.DTBLOCK}
+ (doctest block), C{Token.HEADINGC}, and C{Token.BULLETC}.
@type startline: C{int}
@ivar startline: The line on which this C{Token} begins. This
@@ -556,10 +556,13 @@
heading; C{None}, otherwise. Valid heading levels are 0, 1,
and 2.
+ @type inline: C{bool}
+ @ivar inline: If True, the element is an inline level element, comparable
+ to an HTML C{<span>} tag. Else, it is a block level element, comparable
+ to an HTML C{<div>}.
+
@type PARA: C{string}
@cvar PARA: The C{tag} value for paragraph C{Token}s.
- @type TEXT: C{string}
- @cvar TEXT: The C{tag} value for text parts inside other items.
@type LBLOCK: C{string}
@cvar LBLOCK: The C{tag} value for literal C{Token}s.
@type DTBLOCK: C{string}
@@ -577,9 +580,9 @@
DTBLOCK = "doctestblock"
HEADING = "heading"
BULLET = "bullet"
- TEXT = "text"
- def __init__(self, tag, startline, contents, indent, level=None):
+ def __init__(self, tag, startline, contents, indent, level=None,
+ inline=False):
"""
Create a new C{Token}.
@@ -596,12 +599,15 @@
@param level: The heading-level of this C{Token} if it is a
heading; C{None}, otherwise.
@type level: C{int} or C{None}
+ @param inline: Is this C{Token} inline as a C{<span>}?.
+ @type inline: C{bool}
"""
self.tag = tag
self.startline = startline
self.contents = contents
self.indent = indent
self.level = level
+ self.inline = inline
def __repr__(self):
"""
@@ -799,14 +805,16 @@
linenum += 1
# Add the bullet token.
- tokens.append(Token(Token.BULLET, start, bcontents, bullet_indent))
+ tokens.append(Token(Token.BULLET, start, bcontents, bullet_indent,
+ inline=True))
# Add the paragraph token.
pcontents = ([lines[start][para_start:].strip()] +
[line.strip() for line in lines[start+1:linenum]])
pcontents = ' '.join(pcontents).strip()
if pcontents:
- tokens.append(Token(Token.TEXT, start, pcontents, para_indent))
+ tokens.append(Token(Token.PARA, start, pcontents, para_indent,
+ inline=True))
# Return the linenum after the paragraph token ends.
return linenum
@@ -945,7 +953,7 @@
linenum = _tokenize_para(lines, linenum, indent, tokens, errors)
# Paragraph tokens ending in '::' initiate literal blocks.
- if (tokens[-1].tag in (Token.PARA, Token.TEXT) and
+ if (tokens[-1].tag == Token.PARA and
tokens[-1].contents[-2:] == '::'):
tokens[-1].contents = tokens[-1].contents[:-1]
linenum = _tokenize_literal(lines, linenum, indent, tokens, errors)
@@ -1230,7 +1238,7 @@
# Clean up for literal blocks (add the double "::" back)
childstr = re.sub(':(\s*)\2', '::\\1', childstr)
- if tree.tag in ('para', 'text'):
+ if tree.tag == 'para':
str = wordwrap(childstr, indent)+'\n'
str = re.sub(r'((^|\n)\s*\d+)\.', r'\1E{.}', str)
str = re.sub(r'((^|\n)\s*)-', r'\1E{-}', str)
@@ -1317,7 +1325,7 @@
variables = [to_plaintext(c, cindent, seclevel) for c in tree.children]
childstr = ''.join(variables)
- if tree.tag in ('para', 'text'):
+ if tree.tag == 'para':
return wordwrap(childstr, indent)+'\n'
elif tree.tag == 'li':
# We should be able to use getAttribute here; but there's no
@@ -1397,7 +1405,7 @@
# Clean up for literal blocks (add the double "::" back)
childstr = re.sub(':( *\n \|\n)\2', '::\\1', childstr)
- if tree.tag in ('para', 'text'):
+ if tree.tag == 'para':
str = wordwrap(childstr, indent-6, 69)+'\n'
str = re.sub(r'((^|\n)\s*\d+)\.', r'\1E{.}', str)
str = re.sub(r'((^|\n)\s*)-', r'\1E{-}', str)
@@ -1778,9 +1786,9 @@
# Perform the approriate action for the DOM tree type.
if tree.tag == 'para':
- return wordwrap('<p>%s</p>' % childstr, indent)
- if tree.tag == 'text':
- return wordwrap('%s' % childstr, indent)
+ return wordwrap(
+ (tree.attribs.get('inline') and '%s' or '<p>%s</p>') % childstr,
+ indent)
elif tree.tag == 'code':
style = tree.attribs.get('style')
if style:
@@ -1898,7 +1906,7 @@
for c in tree.children]
childstr = ''.join(variables)
- if tree.tag in ('para', 'text'):
+ if tree.tag == 'para':
return wordwrap(childstr, indent)+'\n'
elif tree.tag == 'code':
return '\\texttt{%s}' % childstr
@@ -1968,7 +1976,7 @@
# Find the first paragraph.
variables = tree.children
- while (len(variables) > 0) and (variables[0].tag not in ('para', 'text')):
+ while (len(variables) > 0) and (variables[0].tag != 'para'):
if variables[0].tag in ('section', 'ulist', 'olist', 'li'):
variables = variables[0].children
else:
@@ -1996,7 +2004,7 @@
# Extract the first sentence.
parachildren = variables[0].children
- para = Element('text')
+ para = Element('para', inline=True)
doc.children.append(para)
for parachild in parachildren:
if isinstance(parachild, basestring):
Modified: branches/exp-text_node/epydoc/src/epydoc/test/epytext.doctest
===================================================================
--- branches/exp-text_node/epydoc/src/epydoc/test/epytext.doctest 2007-03-05 02:18:17 UTC (rev 1570)
+++ branches/exp-text_node/epydoc/src/epydoc/test/epytext.doctest 2007-03-06 19:24:12 UTC (rev 1571)
@@ -45,14 +45,14 @@
... @foo: This is a field.""")
<para>This is a paragraph.</para>
<fieldlist><field><tag>foo</tag>
- <text>This is a field.</text></field></fieldlist>
+ <para inline=True>This is a field.</para></field></fieldlist>
>>> print testparse("""
... This is a paragraph.
... @foo: This is a field.""")
<para>This is a paragraph.</para>
<fieldlist><field><tag>foo</tag>
- <text>This is a field.</text></field></fieldlist>
+ <para inline=True>This is a field.</para></field></fieldlist>
>>> print testparse("""
... This is a paragraph.
@@ -60,23 +60,23 @@
... Hello.""")
<para>This is a paragraph.</para>
<fieldlist><field><tag>foo</tag>
- <text>This is a field. Hello.</text></field></fieldlist>
-
+ <para inline=True>This is a field. Hello.</para></field>
+ </fieldlist>
>>> print testparse("""Paragraph\n@foo: field""")
<para>Paragraph</para>
<fieldlist><field><tag>foo</tag>
- <text>field</text></field></fieldlist>
+ <para inline=True>field</para></field></fieldlist>
>>> print testparse("""Paragraph\n\n@foo: field""")
<para>Paragraph</para>
<fieldlist><field><tag>foo</tag>
- <text>field</text></field></fieldlist>
+ <para inline=True>field</para></field></fieldlist>
>>> print testparse("""\nParagraph\n@foo: field""")
<para>Paragraph</para>
<fieldlist><field><tag>foo</tag>
- <text>field</text></field></fieldlist>
+ <para inline=True>field</para></field></fieldlist>
Make sure thta unindented lists are not allowed:
@@ -122,20 +122,22 @@
>>> print testparse("""Paragraph\n- list item""")
<para>Paragraph</para>
- <ulist><li><text>list item</text></li></ulist>
+ <ulist><li><para inline=True>list item</para></li></ulist>
Make sure that indented lists are allowed:
>>> print testparse('This is a paragraph.\n - This is a list item.\n'+
... 'This is a paragraph')
<para>This is a paragraph.</para>
- <ulist><li><text>This is a list item.</text></li></ulist>
+ <ulist><li><para inline=True>This is a list item.</para></li>
+ </ulist>
<para>This is a paragraph</para>
>>> print testparse('This is a paragraph.\n\n - This is a list item.'+
... '\n\nThis is a paragraph')
<para>This is a paragraph.</para>
- <ulist><li><text>This is a list item.</text></li></ulist>
+ <ulist><li><para inline=True>This is a list item.</para></li>
+ </ulist>
<para>This is a paragraph</para>
>>> print testparse("""
@@ -145,7 +147,8 @@
...
... This is a paragraph""")
<para>This is a paragraph.</para>
- <ulist><li><text>This is a list item.</text></li></ulist>
+ <ulist><li><para inline=True>This is a list item.</para></li>
+ </ulist>
<para>This is a paragraph</para>
>>> print testparse("""
@@ -154,18 +157,22 @@
... - This is a list item.
... This is a paragraph""")
<para>This is a paragraph.</para>
- <ulist><li><text>This is a list item.</text></li></ulist>
+ <ulist><li><para inline=True>This is a list item.</para></li>
+ </ulist>
<para>This is a paragraph</para>
>>> print testparse("""
... - This is a list item.""")
- <ulist><li><text>This is a list item.</text></li></ulist>
+ <ulist><li><para inline=True>This is a list item.</para></li>
+ </ulist>
>>> print testparse("""- This is a list item.""")
- <ulist><li><text>This is a list item.</text></li></ulist>
+ <ulist><li><para inline=True>This is a list item.</para></li>
+ </ulist>
>>> print testparse("""\n- This is a list item.""")
- <ulist><li><text>This is a list item.</text></li></ulist>
+ <ulist><li><para inline=True>This is a list item.</para></li>
+ </ulist>
Basic list tests:
@@ -176,11 +183,11 @@
>>> LI3 = " - This is a list\n item."
>>> LI4 = "\n - This is a list\n item."
>>> PARA = ('<para>This is a paragraph.</para>')
- >>> ONELIST = ('<ulist><li><text>This is a '+
- ... 'list item.</text></li></ulist>')
- >>> TWOLIST = ('<ulist><li><text>This is a '+
- ... 'list item.</text></li><li><text>This is a '+
- ... 'list item.</text></li></ulist>')
+ >>> ONELIST = ('<ulist><li><para inline=True>This is a '+
+ ... 'list item.</para></li></ulist>')
+ >>> TWOLIST = ('<ulist><li><para inline=True>This is a '+
+ ... 'list item.</para></li><li><para inline=True>This is a '+
+ ... 'list item.</para></li></ulist>')
>>> for p in (P1, P2):
... for li1 in (LI1, LI2, LI3, LI4):
@@ -198,7 +205,7 @@
... PARA+TWOLIST+PARA)
>>> LI5 = " - This is a list item.\n\n It contains two paragraphs."
- >>> LI5LIST = ('<ulist><li><text>This is a list item.</text>'+
+ >>> LI5LIST = ('<ulist><li><para inline=True>This is a list item.</para>'+
... '<para>It contains two paragraphs.</para></li></ulist>')
>>> checkparse(LI5, LI5LIST)
>>> checkparse('%s\n%s' % (P1, LI5), PARA+LI5LIST)
@@ -206,8 +213,8 @@
>>> LI6 = (" - This is a list item with a literal block::\n" +
... " hello\n there")
- >>> LI6LIST = ('<ulist><li><text>This is a list item with a literal '+
- ... 'block:</text><literalblock> hello\n there'+
+ >>> LI6LIST = ('<ulist><li><para inline=True>This is a list item with a literal '+
+ ... 'block:</para><literalblock> hello\n there'+
... '</literalblock></li></ulist>')
>>> checkparse(LI6, LI6LIST)
>>> checkparse('%s\n%s' % (P1, LI6), PARA+LI6LIST)
@@ -216,11 +223,11 @@
Item wrap tests:
>>> LI = "- This is a list\n item."
- >>> ONELIST = ('<ulist><li><text>This is a '+
- ... 'list item.</text></li></ulist>')
- >>> TWOLIST = ('<ulist><li><text>This is a '+
- ... 'list item.</text></li><li><text>This is a '+
- ... 'list item.</text></li></ulist>')
+ >>> ONELIST = ('<ulist><li><para inline=True>This is a '+
+ ... 'list item.</para></li></ulist>')
+ >>> TWOLIST = ('<ulist><li><para inline=True>This is a '+
+ ... 'list item.</para></li><li><para inline=True>This is a '+
+ ... 'list item.</para></li></ulist>')
>>> for indent in ('', ' '):
... for nl1 in ('', '\n'):
... checkparse(nl1+indent+LI, ONELIST)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|