[Moin-devel] CVS: MoinMoin/parser rst.py,1.1,1.2
J?rgen Hermann
jhermann at users.sourceforge.net
Thu May 9 04:28:02 EDT 2002
Update of /cvsroot/moin/MoinMoin/parser
In directory usw-pr-cvs1:/tmp/cvs-serv13248
Modified Files:
rst.py
Log Message:
Added most basic elements
Index: rst.py
===================================================================
RCS file: /cvsroot/moin/MoinMoin/parser/rst.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -r1.1 -r1.2
*** rst.py 9 May 2002 10:32:15 -0000 1.1
--- rst.py 9 May 2002 11:27:21 -0000 1.2
***************
*** 9,13 ****
import cgi, sys
! from docutils import core, utils
from docutils.parsers import rst
--- 9,13 ----
import cgi, sys
! from docutils import core, nodes, utils
from docutils.parsers import rst
***************
*** 18,22 ****
class Parser:
! """ Parse ReST via "docutils".
"""
--- 18,22 ----
class Parser:
! """ Parse RST via "docutils".
"""
***************
*** 35,38 ****
--- 35,41 ----
if 1:
+ document.walkabout(MoinTranslator(self.request, formatter, document))
+
+ if 0:
dom = document.asdom()
print '<pre>'
***************
*** 44,46 ****
--- 47,160 ----
print cgi.escape(document.astext())
print '</pre>'
+
+
+ class MoinTranslator(nodes.NodeVisitor):
+
+ def __init__(self, request, formatter, document):
+ nodes.NodeVisitor.__init__(self, document)
+ self.request = request
+ self.formatter = formatter
+
+ def visit_Text(self, node):
+ print self.formatter.text(node.astext())
+
+ def depart_Text(self, node):
+ pass
+
+ def visit_title(self, node):
+ print self.formatter.heading(1, node.astext())
+
+
+ #
+ # Text markup
+ #
+
+ def visit_emphasis(self, node):
+ print self.formatter.emphasis(1)
+
+ def depart_emphasis(self, node):
+ print self.formatter.emphasis(0)
+
+ def visit_strong(self, node):
+ print self.formatter.strong(1)
+
+ def depart_strong(self, node):
+ print self.formatter.strong(0)
+
+ def visit_literal(self, node):
+ print self.formatter.code(1)
+
+ def depart_literal(self, node):
+ print self.formatter.code(0)
+
+
+ #
+ # Blocks
+ #
+
+ def visit_paragraph(self, node):
+ #if self.topic_class != 'contents':
+ print self.formatter.paragraph(1)
+
+ def depart_paragraph(self, node):
+ #if self.topic_class == 'contents':
+ # print self.formatter.linebreak()
+ #else:
+ print self.formatter.paragraph(0)
+
+ def visit_literal_block(self, node):
+ print self.formatter.preformatted(1)
+
+ def depart_literal_block(self, node):
+ print self.formatter.preformatted(0)
+
+
+ #
+ # Lists
+ #
+
+ def visit_bullet_list(self, node):
+ print self.formatter.bullet_list(1)
+
+ def depart_bullet_list(self, node):
+ print self.formatter.bullet_list(0)
+
+ def visit_enumerated_list(self, node):
+ print self.formatter.number_list(1, start=node.get('start', None))
+
+ def depart_enumerated_list(self, node):
+ print self.formatter.number_list(0)
+
+ def visit_list_item(self, node):
+ print self.formatter.listitem(1)
+
+ def depart_list_item(self, node):
+ print self.formatter.listitem(0)
+
+ def visit_definition_list(self, node):
+ print self.formatter.definition_list(1)
+
+ def depart_definition_list(self, node):
+ print self.formatter.definition_list(0)
+
+
+ #
+ # Admonitions
+ #
+
+ def visit_warning(self, node):
+ print self.formatter.highlight(1)
+
+ def depart_warning(self, node):
+ print self.formatter.highlight(0)
+
+
+ #
+ # Misc
+ #
+
+ def visit_system_message(self, node):
+ print self.formatter.highlight(1)
+ print '[%s]' % node.astext()
+ print self.formatter.highlight(0)
More information about the Moin-devel
mailing list