[Epydoc-commits] SF.net SVN: epydoc: [1569] branches/exp-text_node/epydoc/src/epydoc
Brought to you by:
edloper
|
From: <dva...@us...> - 2007-03-05 01:52:09
|
Revision: 1569
http://svn.sourceforge.net/epydoc/?rev=1569&view=rev
Author: dvarrazzo
Date: 2007-03-04 17:52:05 -0800 (Sun, 04 Mar 2007)
Log Message:
-----------
- Added Token.TEXT to represent an inline chunk of text.
- Some tests updated. Not all tests pass yet anyway.
- Removed double <br/>'s from HTML output.
Modified Paths:
--------------
branches/exp-text_node/epydoc/src/epydoc/docstringparser.py
branches/exp-text_node/epydoc/src/epydoc/docwriter/html.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 01:39:41 UTC (rev 1568)
+++ branches/exp-text_node/epydoc/src/epydoc/docstringparser.py 2007-03-05 01:52:05 UTC (rev 1569)
@@ -507,6 +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"
######################################################################
#{ Field Processing Error Messages
Modified: branches/exp-text_node/epydoc/src/epydoc/docwriter/html.py
===================================================================
--- branches/exp-text_node/epydoc/src/epydoc/docwriter/html.py 2007-03-05 01:39:41 UTC (rev 1568)
+++ branches/exp-text_node/epydoc/src/epydoc/docwriter/html.py 2007-03-05 01:52:05 UTC (rev 1569)
@@ -739,11 +739,11 @@
out('<!-- ==================== %s ' % typ.upper() +
'DESCRIPTION ==================== -->\n')
out('<h1 class="epydoc">%s %s</h1>' % (typ, shortname))
- out(self.pysrc_link(doc) + '<br /><br />\n')
+ out('<p class="nomargin-top">%s</p>\n' % self.pysrc_link(doc))
# If the module has a description, then list it.
if doc.descr not in (None, UNKNOWN):
- out(self.descr(doc, 2)+'<br /><br />\n\n')
+ out(self.descr(doc, 2)+'\n\n')
# Write any standarad metadata (todo, author, etc.)
if doc.metadata is not UNKNOWN and doc.metadata:
@@ -830,7 +830,7 @@
out('<!-- ==================== %s ' % typ.upper() +
'DESCRIPTION ==================== -->\n')
out('<h1 class="epydoc">%s %s</h1>' % (typ, shortname))
- out(self.pysrc_link(doc) + '<br /><br />\n')
+ out('<p class="nomargin-top">%s</p>\n' % self.pysrc_link(doc))
if ((doc.bases not in (UNKNOWN, None) and len(doc.bases) > 0) or
(doc.subclasses not in (UNKNOWN,None) and len(doc.subclasses)>0)):
@@ -864,7 +864,7 @@
# If the class has a description, then list it.
if doc.descr not in (None, UNKNOWN):
- out(self.descr(doc, 2)+'<br /><br />\n\n')
+ out(self.descr(doc, 2)+'\n\n')
# Write any standarad metadata (todo, author, etc.)
if doc.metadata is not UNKNOWN and doc.metadata:
Modified: branches/exp-text_node/epydoc/src/epydoc/markup/epytext.py
===================================================================
--- branches/exp-text_node/epydoc/src/epydoc/markup/epytext.py 2007-03-05 01:39:41 UTC (rev 1568)
+++ branches/exp-text_node/epydoc/src/epydoc/markup/epytext.py 2007-03-05 01:52:05 UTC (rev 1569)
@@ -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 == Token.PARA:
+ if token.tag in (Token.PARA, Token.TEXT):
_add_para(doc, token, stack, indent_stack, errors)
# If Token has type HEADING, add the new section
@@ -366,7 +366,7 @@
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)
+ para = _colorize(doc, para_token, errors, tagName=para_token.tag)
stack[-1].children.append(para)
else:
estr = "Improper paragraph indentation."
@@ -511,9 +511,10 @@
"""
C{Token}s are an intermediate data structure used while
constructing the structuring DOM tree for a formatted docstring.
- There are five types of C{Token}:
+ There are six types of C{Token}:
- Paragraphs
+ - Text
- Literal blocks
- Doctest blocks
- Headings
@@ -533,8 +534,9 @@
@type tag: C{string}
@ivar tag: This C{Token}'s type. Possible values are C{Token.PARA}
- (paragraph), C{Token.LBLOCK} (literal block), C{Token.DTBLOCK}
- (doctest block), C{Token.HEADINGC}, and C{Token.BULLETC}.
+ (paragraph), C{Token.TEXT} (text node), 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,6 +558,8 @@
@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}
@@ -573,6 +577,7 @@
DTBLOCK = "doctestblock"
HEADING = "heading"
BULLET = "bullet"
+ TEXT = "text"
def __init__(self, tag, startline, contents, indent, level=None):
"""
@@ -801,7 +806,7 @@
[line.strip() for line in lines[start+1:linenum]])
pcontents = ' '.join(pcontents).strip()
if pcontents:
- tokens.append(Token(Token.PARA, start, pcontents, para_indent))
+ tokens.append(Token(Token.TEXT, start, pcontents, para_indent))
# Return the linenum after the paragraph token ends.
return linenum
@@ -940,7 +945,7 @@
linenum = _tokenize_para(lines, linenum, indent, tokens, errors)
# Paragraph tokens ending in '::' initiate literal blocks.
- if (tokens[-1].tag == Token.PARA and
+ if (tokens[-1].tag in (Token.PARA, Token.TEXT) and
tokens[-1].contents[-2:] == '::'):
tokens[-1].contents = tokens[-1].contents[:-1]
linenum = _tokenize_literal(lines, linenum, indent, tokens, errors)
@@ -1225,7 +1230,7 @@
# Clean up for literal blocks (add the double "::" back)
childstr = re.sub(':(\s*)\2', '::\\1', childstr)
- if tree.tag == 'para':
+ if tree.tag in ('para', 'text'):
str = wordwrap(childstr, indent)+'\n'
str = re.sub(r'((^|\n)\s*\d+)\.', r'\1E{.}', str)
str = re.sub(r'((^|\n)\s*)-', r'\1E{-}', str)
@@ -1312,7 +1317,7 @@
variables = [to_plaintext(c, cindent, seclevel) for c in tree.children]
childstr = ''.join(variables)
- if tree.tag == 'para':
+ if tree.tag in ('para', 'text'):
return wordwrap(childstr, indent)+'\n'
elif tree.tag == 'li':
# We should be able to use getAttribute here; but there's no
@@ -1392,7 +1397,7 @@
# Clean up for literal blocks (add the double "::" back)
childstr = re.sub(':( *\n \|\n)\2', '::\\1', childstr)
- if tree.tag == 'para':
+ if tree.tag in ('para', 'text'):
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)
@@ -1768,25 +1773,14 @@
indent+2, seclevel)
for c in tree.children]
- # Get rid of unnecessary <P>...</P> tags; they introduce extra
- # space on most browsers that we don't want.
- for i in range(len(variables)-1):
- if (not isinstance(tree.children[i], basestring) and
- tree.children[i].tag == 'para' and
- (isinstance(tree.children[i+1], basestring) or
- tree.children[i+1].tag != 'para')):
- variables[i] = ' '*(indent+2)+variables[i][5+indent:-5]+'\n'
- if (tree.children and
- not isinstance(tree.children[-1], basestring) and
- tree.children[-1].tag == 'para'):
- variables[-1] = ' '*(indent+2)+variables[-1][5+indent:-5]+'\n'
-
# Construct the HTML string for the variables.
childstr = ''.join(variables)
# 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(str(childstr), indent)
elif tree.tag == 'code':
style = tree.attribs.get('style')
if style:
@@ -1904,7 +1898,7 @@
for c in tree.children]
childstr = ''.join(variables)
- if tree.tag == 'para':
+ if tree.tag in ('para', 'text'):
return wordwrap(childstr, indent)+'\n'
elif tree.tag == 'code':
return '\\texttt{%s}' % childstr
@@ -1974,7 +1968,7 @@
# Find the first paragraph.
variables = tree.children
- while (len(variables) > 0) and (variables[0].tag != 'para'):
+ while (len(variables) > 0) and (variables[0].tag not in ('para', 'text')):
if variables[0].tag in ('section', 'ulist', 'olist', 'li'):
variables = variables[0].children
else:
@@ -2002,7 +1996,7 @@
# Extract the first sentence.
parachildren = variables[0].children
- para = Element('para')
+ para = Element('text')
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 01:39:41 UTC (rev 1568)
+++ branches/exp-text_node/epydoc/src/epydoc/test/epytext.doctest 2007-03-05 01:52:05 UTC (rev 1569)
@@ -45,14 +45,14 @@
... @foo: This is a field.""")
<para>This is a paragraph.</para>
<fieldlist><field><tag>foo</tag>
- <para>This is a field.</para></field></fieldlist>
+ <text>This is a field.</text></field></fieldlist>
>>> print testparse("""
... This is a paragraph.
... @foo: This is a field.""")
<para>This is a paragraph.</para>
<fieldlist><field><tag>foo</tag>
- <para>This is a field.</para></field></fieldlist>
+ <text>This is a field.</text></field></fieldlist>
>>> print testparse("""
... This is a paragraph.
@@ -60,23 +60,23 @@
... Hello.""")
<para>This is a paragraph.</para>
<fieldlist><field><tag>foo</tag>
- <para>This is a field. Hello.</para></field></fieldlist>
+ <text>This is a field. Hello.</text></field></fieldlist>
>>> print testparse("""Paragraph\n@foo: field""")
<para>Paragraph</para>
<fieldlist><field><tag>foo</tag>
- <para>field</para></field></fieldlist>
+ <text>field</text></field></fieldlist>
>>> print testparse("""Paragraph\n\n@foo: field""")
<para>Paragraph</para>
<fieldlist><field><tag>foo</tag>
- <para>field</para></field></fieldlist>
+ <text>field</text></field></fieldlist>
>>> print testparse("""\nParagraph\n@foo: field""")
<para>Paragraph</para>
<fieldlist><field><tag>foo</tag>
- <para>field</para></field></fieldlist>
+ <text>field</text></field></fieldlist>
Make sure thta unindented lists are not allowed:
@@ -122,20 +122,20 @@
>>> print testparse("""Paragraph\n- list item""")
<para>Paragraph</para>
- <ulist><li><para>list item</para></li></ulist>
+ <ulist><li><text>list item</text></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><para>This is a list item.</para></li></ulist>
+ <ulist><li><text>This is a list item.</text></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><para>This is a list item.</para></li></ulist>
+ <ulist><li><text>This is a list item.</text></li></ulist>
<para>This is a paragraph</para>
>>> print testparse("""
@@ -145,7 +145,7 @@
...
... This is a paragraph""")
<para>This is a paragraph.</para>
- <ulist><li><para>This is a list item.</para></li></ulist>
+ <ulist><li><text>This is a list item.</text></li></ulist>
<para>This is a paragraph</para>
>>> print testparse("""
@@ -154,18 +154,18 @@
... - This is a list item.
... This is a paragraph""")
<para>This is a paragraph.</para>
- <ulist><li><para>This is a list item.</para></li></ulist>
+ <ulist><li><text>This is a list item.</text></li></ulist>
<para>This is a paragraph</para>
>>> print testparse("""
... - This is a list item.""")
- <ulist><li><para>This is a list item.</para></li></ulist>
+ <ulist><li><text>This is a list item.</text></li></ulist>
>>> print testparse("""- This is a list item.""")
- <ulist><li><para>This is a list item.</para></li></ulist>
+ <ulist><li><text>This is a list item.</text></li></ulist>
>>> print testparse("""\n- This is a list item.""")
- <ulist><li><para>This is a list item.</para></li></ulist>
+ <ulist><li><text>This is a list item.</text></li></ulist>
Basic list tests:
@@ -176,11 +176,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><para>This is a '+
- ... 'list item.</para></li></ulist>')
- >>> TWOLIST = ('<ulist><li><para>This is a '+
- ... 'list item.</para></li><li><para>This is a '+
- ... 'list item.</para></li></ulist>')
+ >>> 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>')
>>> for p in (P1, P2):
... for li1 in (LI1, LI2, LI3, LI4):
@@ -198,7 +198,7 @@
... PARA+TWOLIST+PARA)
>>> LI5 = " - This is a list item.\n\n It contains two paragraphs."
- >>> LI5LIST = ('<ulist><li><para>This is a list item.</para>'+
+ >>> LI5LIST = ('<ulist><li><text>This is a list item.</text>'+
... '<para>It contains two paragraphs.</para></li></ulist>')
>>> checkparse(LI5, LI5LIST)
>>> checkparse('%s\n%s' % (P1, LI5), PARA+LI5LIST)
@@ -206,8 +206,8 @@
>>> LI6 = (" - This is a list item with a literal block::\n" +
... " hello\n there")
- >>> LI6LIST = ('<ulist><li><para>This is a list item with a literal '+
- ... 'block:</para><literalblock> hello\n there'+
+ >>> LI6LIST = ('<ulist><li><text>This is a list item with a literal '+
+ ... 'block:</text><literalblock> hello\n there'+
... '</literalblock></li></ulist>')
>>> checkparse(LI6, LI6LIST)
>>> checkparse('%s\n%s' % (P1, LI6), PARA+LI6LIST)
@@ -216,11 +216,11 @@
Item wrap tests:
>>> LI = "- This is a list\n item."
- >>> ONELIST = ('<ulist><li><para>This is a '+
- ... 'list item.</para></li></ulist>')
- >>> TWOLIST = ('<ulist><li><para>This is a '+
- ... 'list item.</para></li><li><para>This is a '+
- ... 'list item.</para></li></ulist>')
+ >>> 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>')
>>> for indent in ('', ' '):
... for nl1 in ('', '\n'):
... checkparse(nl1+indent+LI, ONELIST)
@@ -229,7 +229,7 @@
Summary
=======
-The implementation of the summaization function works as expected.
+The implementation of the summarization function works as expected.
>>> from epydoc.markup import epytext
>>> def getsummary(s):
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|