annotate MoinMoin/parser/text_rst.py @ 5711:58a9aa0d67bd

Raise exceptions as recommended in PEP 8.
author Pascal Volk <user@localhost.localdomain.org>
date Mon, 05 Jul 2010 23:21:21 +0000
parents 0c424b6dc029
children 97208f67798f
rev   line source
386
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
1 # -*- coding: iso-8859-1 -*-
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
2 """
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
3 MoinMoin - ReStructured Text Parser
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
4
1918
bb2e053067fb fixing copyright headers: remove umlauts (encoding troubles), make epydoc compatible, reformat
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1914
diff changeset
5 @copyright: 2004 Matthew Gilbert <gilbert AT voxmea DOT net>,
bb2e053067fb fixing copyright headers: remove umlauts (encoding troubles), make epydoc compatible, reformat
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1914
diff changeset
6 2004 Alexander Schremmer <alex AT alexanderweb DOT de>
386
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
7 @license: GNU GPL, see COPYING for details.
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
8
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
9 REQUIRES docutils 0.3.10 or later (must be later than December 30th, 2005)
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
10 """
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
11
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
12 import re
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
13 import new
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
14 import StringIO
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
15 import __builtin__
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
16 import sys
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
17
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
18 # docutils imports are below
657
016a8a3ef354 wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 656
diff changeset
19 from MoinMoin.parser.text_moin_wiki import Parser as WikiParser
386
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
20 from MoinMoin.Page import Page
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
21 from MoinMoin.action import AttachFile
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
22 from MoinMoin import wikiutil
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
23
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
24 Dependencies = [] # this parser just depends on the raw text
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
25
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
26 # --- make docutils safe by overriding all module-scoped names related to IO ---
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
27
884
c3694976f155 minor improvements
Felix Wiemann <Felix.Wiemann@gmx.net>
parents: 754
diff changeset
28 # TODO: Add an error message to dummyOpen so that the user knows that
c3694976f155 minor improvements
Felix Wiemann <Felix.Wiemann@gmx.net>
parents: 754
diff changeset
29 # they requested an unsupported feature of Docutils in MoinMoin.
386
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
30 def dummyOpen(x, y=None, z=None): return
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
31
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
32 class dummyIO(StringIO.StringIO):
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
33 def __init__(self, destination=None, destination_path=None,
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
34 encoding=None, error_handler='', autoclose=1,
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
35 handle_io_errors=1, source_path=None):
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
36 StringIO.StringIO.__init__(self)
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
37
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
38 class dummyUrllib2:
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
39 def urlopen(a):
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
40 return StringIO.StringIO()
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
41 urlopen = staticmethod(urlopen)
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
42
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
43 # # # All docutils imports must be contained below here
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
44 try:
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
45 import docutils
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
46 from docutils.core import publish_parts
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
47 from docutils.writers import html4css1
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
48 from docutils.nodes import reference
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
49 from docutils.parsers import rst
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
50 from docutils.parsers.rst import directives, roles
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
51 # # # All docutils imports must be contained above here
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
52
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
53 ErrorParser = None # used in the case of missing docutils
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
54 docutils.io.FileOutput = docutils.io.FileInput = dummyIO
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
55 except ImportError:
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
56 # we need to workaround this totally broken plugin interface that does
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
57 # not allow us to raise exceptions
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
58 class ErrorParser:
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
59 caching = 0
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
60 Dependencies = Dependencies # copy dependencies from module-scope
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
61
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
62 def __init__(self, raw, request, **kw):
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
63 self.raw = raw
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
64 self.request = request
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1920
diff changeset
65
386
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
66 def format(self, formatter):
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
67 _ = self.request.getText
721
ddc7d654fabb fix plain text parser imports in xslt/rst parsers
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 657
diff changeset
68 from MoinMoin.parser.text import Parser as TextParser
386
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
69 self.request.write(formatter.sysmsg(1) +
884
c3694976f155 minor improvements
Felix Wiemann <Felix.Wiemann@gmx.net>
parents: 754
diff changeset
70 formatter.rawHTML(_('Rendering of reStructured text is not possible, please install Docutils.')) +
386
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
71 formatter.sysmsg(0))
721
ddc7d654fabb fix plain text parser imports in xslt/rst parsers
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 657
diff changeset
72 TextParser(self.raw, self.request).format(formatter)
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1920
diff changeset
73
386
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
74 # Create a pseudo docutils environment
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
75 docutils = html4css1 = dummyUrllib2()
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
76 html4css1.HTMLTranslator = html4css1.Writer = object
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
77
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
78 def safe_import(name, globals = None, locals = None, fromlist = None):
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
79 mod = __builtin__.__import__(name, globals, locals, fromlist)
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
80 if mod:
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
81 mod.open = dummyOpen
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
82 mod.urllib2 = dummyUrllib2
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
83 return mod
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
84
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
85 # Go through and change all docutils modules to use a dummyOpen and dummyUrllib2
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
86 # module. Also make sure that any docutils imported modules also get the dummy
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
87 # implementations.
1871
89a95d272881 re-add some .keys() calls when we modify the dict in the loop
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1870
diff changeset
88 for i in sys.modules.keys():
386
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
89 if i.startswith('docutils') and sys.modules[i]:
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
90 sys.modules[i].open = dummyOpen
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
91 sys.modules[i].urllib2 = dummyUrllib2
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
92 sys.modules[i].__import__ = safe_import
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1920
diff changeset
93
386
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
94 # --- End of dummy-code --------------------------------------------------------
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
95
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
96 def html_escape_unicode(node):
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
97 # Find Python function that does this for me. string.encode('ascii',
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
98 # 'xmlcharrefreplace') only 2.3 and above.
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
99 for i in node:
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
100 if ord(i) > 127:
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
101 node = node.replace(i, '&#%d;' % (ord(i)))
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
102 return node
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
103
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
104 class MoinWriter(html4css1.Writer):
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
105
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
106 config_section = 'MoinMoin writer'
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1920
diff changeset
107 config_section_dependencies = ('writers', )
386
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
108
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
109 #"""Final translated form of `document`."""
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
110 output = None
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
111
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
112 def wiki_resolver(self, node):
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
113 """
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
114 Normally an unknown reference would be an error in an reST document.
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
115 However, this is how new documents are created in the wiki. This
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
116 passes on unknown references to eventually be handled by
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
117 MoinMoin.
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
118 """
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
119 if hasattr(node, 'indirect_reference_name'):
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
120 node['refuri'] = node.indirect_reference_name
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
121 elif (len(node['ids']) != 0):
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
122 # If the node has an id then it's probably an internal link. Let
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
123 # docutils generate an error.
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
124 return False
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
125 elif node.hasattr('name'):
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
126 node['refuri'] = node['name']
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
127 else:
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
128 node['refuri'] = node['refname']
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
129 del node['refname']
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
130 node.resolved = 1
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
131 self.nodes.append(node)
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
132 return True
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
133
2792
e4ebc0bcf5ed more octal cosmetics
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2789
diff changeset
134 wiki_resolver.priority = 1
386
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
135
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
136 def __init__(self, formatter, request):
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
137 html4css1.Writer.__init__(self)
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
138 self.formatter = formatter
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
139 self.request = request
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
140 # Add our wiki unknown_reference_resolver to our list of functions to
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
141 # run when a target isn't found
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
142 self.unknown_reference_resolvers = [self.wiki_resolver]
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
143 # We create a new parser to process MoinMoin wiki style links in the
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
144 # reST.
657
016a8a3ef354 wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 656
diff changeset
145 self.wikiparser = WikiParser('', self.request)
386
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
146 self.wikiparser.formatter = self.formatter
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
147 self.wikiparser.hilite_re = None
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
148 self.nodes = []
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
149 # Make sure it's a supported docutils version.
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
150 required_version = (0, 3, 10)
1920
b06ef2a53efa 'make pylint', fixed lots of minor stuff found by pylint (and there is still lots left to do)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
151 current_version = tuple([int(i) for i in (docutils.__version__.split('.') + ['0', '0'])[:3]])
386
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
152 if current_version < required_version:
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
153 err = 'ERROR: The installed docutils version is %s;' % ('.'.join([str(i) for i in current_version]))
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
154 err += ' version %s or later is required.' % ('.'.join([str(i) for i in required_version]))
5711
58a9aa0d67bd Raise exceptions as recommended in PEP 8.
Pascal Volk <user@localhost.localdomain.org>
parents: 5401
diff changeset
155 raise RuntimeError(err)
386
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
156
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
157 def translate(self):
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
158 visitor = MoinTranslator(self.document,
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
159 self.formatter,
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
160 self.request,
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
161 self.wikiparser,
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
162 self)
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
163 self.document.walkabout(visitor)
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
164 self.visitor = visitor
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1920
diff changeset
165 # Docutils 0.5 and later require the writer to have the visitor
627
b8e8697ea0af Increased docutils compatiblity, thanks to Matt for the patch.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 469
diff changeset
166 # attributes.
b8e8697ea0af Increased docutils compatiblity, thanks to Matt for the patch.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 469
diff changeset
167 if (hasattr(html4css1.Writer, 'visitor_attributes')):
b8e8697ea0af Increased docutils compatiblity, thanks to Matt for the patch.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 469
diff changeset
168 for attr in html4css1.Writer.visitor_attributes:
b8e8697ea0af Increased docutils compatiblity, thanks to Matt for the patch.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 469
diff changeset
169 setattr(self, attr, getattr(visitor, attr))
386
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
170 self.output = html_escape_unicode(visitor.astext())
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
171
3784
951ed1df8ec3 move editor quickhelp out of config into parser modules
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3308
diff changeset
172 # mark quickhelp as translatable
951ed1df8ec3 move editor quickhelp out of config into parser modules
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3308
diff changeset
173 _ = lambda x: x
951ed1df8ec3 move editor quickhelp out of config into parser modules
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3308
diff changeset
174
386
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
175 class Parser:
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
176 caching = 1
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
177 Dependencies = Dependencies # copy dependencies from module-scope
5401
0c424b6dc029 add extensions to the rst parser
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5104
diff changeset
178 extensions = ['.rst', '.rest', ]
3784
951ed1df8ec3 move editor quickhelp out of config into parser modules
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3308
diff changeset
179 quickhelp = _("""\
951ed1df8ec3 move editor quickhelp out of config into parser modules
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3308
diff changeset
180 {{{
951ed1df8ec3 move editor quickhelp out of config into parser modules
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3308
diff changeset
181 Emphasis: *italic* **bold** ``monospace``
951ed1df8ec3 move editor quickhelp out of config into parser modules
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3308
diff changeset
182
951ed1df8ec3 move editor quickhelp out of config into parser modules
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3308
diff changeset
183 Headings: Heading 1 Heading 2 Heading 3
951ed1df8ec3 move editor quickhelp out of config into parser modules
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3308
diff changeset
184 ========= --------- ~~~~~~~~~
951ed1df8ec3 move editor quickhelp out of config into parser modules
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3308
diff changeset
185
951ed1df8ec3 move editor quickhelp out of config into parser modules
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3308
diff changeset
186 Horizontal rule: ----
951ed1df8ec3 move editor quickhelp out of config into parser modules
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3308
diff changeset
187
951ed1df8ec3 move editor quickhelp out of config into parser modules
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3308
diff changeset
188 Links: TrailingUnderscore_ `multi word with backticks`_ external_
951ed1df8ec3 move editor quickhelp out of config into parser modules
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3308
diff changeset
189
951ed1df8ec3 move editor quickhelp out of config into parser modules
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3308
diff changeset
190 .. _external: http://external-site.example.org/foo/
951ed1df8ec3 move editor quickhelp out of config into parser modules
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3308
diff changeset
191
951ed1df8ec3 move editor quickhelp out of config into parser modules
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3308
diff changeset
192 Lists: * bullets; 1., a. numbered items.
951ed1df8ec3 move editor quickhelp out of config into parser modules
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3308
diff changeset
193 }}}
951ed1df8ec3 move editor quickhelp out of config into parser modules
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3308
diff changeset
194 (!) For more help, see the
951ed1df8ec3 move editor quickhelp out of config into parser modules
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3308
diff changeset
195 [[http://docutils.sourceforge.net/docs/user/rst/quickref.html|reStructuredText Quick Reference]].
951ed1df8ec3 move editor quickhelp out of config into parser modules
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3308
diff changeset
196 """)
386
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
197
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
198 def __init__(self, raw, request, **kw):
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
199 self.raw = raw
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
200 self.request = request
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
201 self.form = request.form
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
202
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
203 def format(self, formatter):
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
204 # Create our simple parser
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
205 parser = MoinDirectives(self.request)
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
206
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
207 parts = publish_parts(
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1920
diff changeset
208 source=self.raw,
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1920
diff changeset
209 writer=MoinWriter(formatter, self.request),
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1920
diff changeset
210 settings_overrides={
386
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
211 'halt_level': 5,
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
212 'traceback': True,
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
213 'file_insertion_enabled': 0,
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
214 'raw_enabled': 0,
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
215 'stylesheet_path': '',
627
b8e8697ea0af Increased docutils compatiblity, thanks to Matt for the patch.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 469
diff changeset
216 'template': '',
386
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
217 }
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
218 )
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
219
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
220 html = []
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
221 if parts['title']:
884
c3694976f155 minor improvements
Felix Wiemann <Felix.Wiemann@gmx.net>
parents: 754
diff changeset
222 # Document title.
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 386
diff changeset
223 html.append(formatter.rawHTML('<h1>%s</h1>' % parts['title']))
884
c3694976f155 minor improvements
Felix Wiemann <Felix.Wiemann@gmx.net>
parents: 754
diff changeset
224 # If there is only one subtitle it is propagated by Docutils
c3694976f155 minor improvements
Felix Wiemann <Felix.Wiemann@gmx.net>
parents: 754
diff changeset
225 # to a document subtitle and is held in parts['subtitle'].
c3694976f155 minor improvements
Felix Wiemann <Felix.Wiemann@gmx.net>
parents: 754
diff changeset
226 # However, if there is more than one subtitle then this is
c3694976f155 minor improvements
Felix Wiemann <Felix.Wiemann@gmx.net>
parents: 754
diff changeset
227 # empty and fragment contains all of the subtitles.
386
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
228 if parts['subtitle']:
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 386
diff changeset
229 html.append(formatter.rawHTML('<h2>%s</h2>' % parts['subtitle']))
386
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
230 if parts['docinfo']:
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
231 html.append(parts['docinfo'])
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
232 html.append(parts['fragment'])
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
233 self.request.write(html_escape_unicode('\n'.join(html)))
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
234
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
235 class RawHTMLList(list):
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
236 """
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
237 RawHTMLList catches all html appended to internal HTMLTranslator lists.
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1920
diff changeset
238 It passes the HTML through the MoinMoin rawHTML formatter to strip
386
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
239 markup when necessary. This is to support other formatting outputs
656
ad2ac49d17fe use only action=show with mimetype instead of deprecated format action
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 627
diff changeset
240 (such as ?action=show&mimetype=text/plain).
386
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
241 """
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1920
diff changeset
242
386
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
243 def __init__(self, formatter):
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
244 self.formatter = formatter
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1920
diff changeset
245
386
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
246 def append(self, text):
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
247 f = sys._getframe()
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
248 if f.f_back.f_code.co_filename.endswith('html4css1.py'):
1181
a7f8dceb4410 remove types module usage
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1091
diff changeset
249 if isinstance(text, (str, unicode)):
386
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
250 text = self.formatter.rawHTML(text)
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
251 list.append(self, text)
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
252
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
253 class MoinTranslator(html4css1.HTMLTranslator):
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
254
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
255 def __init__(self, document, formatter, request, parser, writer):
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
256 html4css1.HTMLTranslator.__init__(self, document)
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
257 self.formatter = formatter
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
258 self.request = request
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
259 # Using our own writer when needed. Save the old one to restore
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
260 # after the page has been processed by the html4css1 parser.
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
261 self.original_write, self.request.write = self.request.write, self.capture_wiki_formatting
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
262 self.wikiparser = parser
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
263 self.wikiparser.request = request
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
264 # MoinMoin likes to start the initial headers at level 3 and the title
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
265 # gets level 2, so to comply with their styles, we do here also.
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
266 # TODO: Could this be fixed by passing this value in settings_overrides?
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
267 self.initial_header_level = 3
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
268 # Temporary place for wiki returned markup. This will be filled when
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
269 # replacing the default writer with the capture_wiki_formatting
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
270 # function (see visit_image for an example).
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
271 self.wiki_text = ''
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
272 self.setup_wiki_handlers()
469
ff99c7d6ffcb Added rst admonition class patch by TiagoMacambira
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 407
diff changeset
273 self.setup_admonitions_handlers()
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1920
diff changeset
274
386
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
275 # Make all internal lists RawHTMLLists, see RawHTMLList class
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
276 # comment for more information.
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
277 for i in self.__dict__:
1181
a7f8dceb4410 remove types module usage
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1091
diff changeset
278 if isinstance(getattr(self, i), list):
386
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
279 setattr(self, i, RawHTMLList(formatter))
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
280
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
281 def depart_docinfo(self, node):
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
282 """
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
283 depart_docinfo assigns a new list to self.body, we need to re-make that
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
284 into a RawHTMLList.
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
285 """
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
286 html4css1.HTMLTranslator.depart_docinfo(self, node)
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
287 self.body = RawHTMLList(self.formatter)
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
288
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
289 def capture_wiki_formatting(self, text):
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
290 """
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
291 Captures MoinMoin generated markup to the instance variable
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
292 wiki_text.
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
293 """
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
294 # For some reason getting empty strings here which of course overwrites
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
295 # what we really want (this is called multiple times per MoinMoin
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
296 # format call, which I don't understand).
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
297 self.wiki_text += text
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
298
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
299 def process_wiki_text(self, text):
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
300 """
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
301 This sequence is repeated numerous times, so its captured as a
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
302 single call here. Its important that wiki_text is blanked before we
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
303 make the format call. format will call request.write which we've
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
304 hooked to capture_wiki_formatting. If wiki_text is not blanked
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
305 before a call to request.write we will get the old markup as well as
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
306 the newly generated markup.
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
307
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
308 TODO: Could implement this as a list so that it acts as a stack. I
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
309 don't like having to remember to blank wiki_text.
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
310 """
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
311 self.wiki_text = ''
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
312 self.wikiparser.raw = text
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
313 self.wikiparser.format(self.formatter)
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
314
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
315 def add_wiki_markup(self):
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
316 """
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
317 Place holder in case this becomes more elaborate someday. For now it
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
318 only appends the MoinMoin generated markup to the html body and
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
319 raises SkipNode.
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
320 """
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
321 self.body.append(self.wiki_text)
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
322 self.wiki_text = ''
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
323 raise docutils.nodes.SkipNode
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
324
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
325 def astext(self):
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
326 self.request.write = self.original_write
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
327 return html4css1.HTMLTranslator.astext(self)
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
328
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
329 def fixup_wiki_formatting(self, text):
754
86ca6b17aba9 Modified fixup_wiki_formatting to be more selective in the formatting it fixes. This allows macros to insert markup, but also allowing them to return inline markup (the initial paragraph tags are removed).
Matthew Gilbert <gilbert@voxmea.net>
parents: 721
diff changeset
330 replacement = {'\n': '', '> ': '>'}
386
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
331 for src, dst in replacement.items():
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
332 text = text.replace(src, dst)
754
86ca6b17aba9 Modified fixup_wiki_formatting to be more selective in the formatting it fixes. This allows macros to insert markup, but also allowing them to return inline markup (the initial paragraph tags are removed).
Matthew Gilbert <gilbert@voxmea.net>
parents: 721
diff changeset
333 # Fixup extraneous markup
86ca6b17aba9 Modified fixup_wiki_formatting to be more selective in the formatting it fixes. This allows macros to insert markup, but also allowing them to return inline markup (the initial paragraph tags are removed).
Matthew Gilbert <gilbert@voxmea.net>
parents: 721
diff changeset
334 # Removes any empty span tags
86ca6b17aba9 Modified fixup_wiki_formatting to be more selective in the formatting it fixes. This allows macros to insert markup, but also allowing them to return inline markup (the initial paragraph tags are removed).
Matthew Gilbert <gilbert@voxmea.net>
parents: 721
diff changeset
335 text = re.sub(r'\s*<\s*span.*?>\s*<\s*/\s*span\s*>', '', text)
86ca6b17aba9 Modified fixup_wiki_formatting to be more selective in the formatting it fixes. This allows macros to insert markup, but also allowing them to return inline markup (the initial paragraph tags are removed).
Matthew Gilbert <gilbert@voxmea.net>
parents: 721
diff changeset
336 # Removes the first paragraph tag
86ca6b17aba9 Modified fixup_wiki_formatting to be more selective in the formatting it fixes. This allows macros to insert markup, but also allowing them to return inline markup (the initial paragraph tags are removed).
Matthew Gilbert <gilbert@voxmea.net>
parents: 721
diff changeset
337 text = re.sub(r'^\s*<\s*p[^>]*?>', '', text)
86ca6b17aba9 Modified fixup_wiki_formatting to be more selective in the formatting it fixes. This allows macros to insert markup, but also allowing them to return inline markup (the initial paragraph tags are removed).
Matthew Gilbert <gilbert@voxmea.net>
parents: 721
diff changeset
338 # Removes the ending paragraph close tag and any remaining whitespace
86ca6b17aba9 Modified fixup_wiki_formatting to be more selective in the formatting it fixes. This allows macros to insert markup, but also allowing them to return inline markup (the initial paragraph tags are removed).
Matthew Gilbert <gilbert@voxmea.net>
parents: 721
diff changeset
339 text = re.sub(r'<\s*/\s*p\s*>\s*$', '', text)
386
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
340 return text
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
341
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
342 def visit_reference(self, node):
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
343 """
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
344 Pass links to MoinMoin to get the correct wiki space url. Extract
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
345 the url and pass it on to the html4css1 writer to handle. Inline
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
346 images are also handled by visit_image. Not sure what the "drawing:"
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
347 link scheme is used for, so for now it is handled here.
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
348
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
349 Also included here is a hack to allow MoinMoin macros. This routine
2789
637a6c5ff74e rst parser: use <<...>> for macros, no inline: any more
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2761
diff changeset
350 checks for a link which starts with "<<". This link is passed to the
386
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
351 MoinMoin formatter and the resulting markup is inserted into the
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
352 document in the place of the original link reference.
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
353 """
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
354 if 'refuri' in node.attributes:
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
355 refuri = node['refuri']
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
356 prefix = ''
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
357 link = refuri
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
358 if ':' in refuri:
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
359 prefix, link = refuri.lstrip().split(':', 1)
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1920
diff changeset
360
386
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
361 # First see if MoinMoin should handle completely. Exits through add_wiki_markup.
3089
7345503952dd RST parser: fix attachment: and drawing: processing (ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2804
diff changeset
362 if refuri.startswith('<<') and refuri.endswith('>>'): # moin macro
386
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
363 self.process_wiki_text(refuri)
754
86ca6b17aba9 Modified fixup_wiki_formatting to be more selective in the formatting it fixes. This allows macros to insert markup, but also allowing them to return inline markup (the initial paragraph tags are removed).
Matthew Gilbert <gilbert@voxmea.net>
parents: 721
diff changeset
364 self.wiki_text = self.fixup_wiki_formatting(self.wiki_text)
386
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
365 self.add_wiki_markup()
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
366
5104
b631aca46a48 drawings: fix creole/rst parsers
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4493
diff changeset
367 if prefix == 'drawing':
3089
7345503952dd RST parser: fix attachment: and drawing: processing (ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2804
diff changeset
368 self.process_wiki_text("[[%s]]" % refuri)
7345503952dd RST parser: fix attachment: and drawing: processing (ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2804
diff changeset
369 self.wiki_text = self.fixup_wiki_formatting(self.wiki_text)
7345503952dd RST parser: fix attachment: and drawing: processing (ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2804
diff changeset
370 self.add_wiki_markup()
7345503952dd RST parser: fix attachment: and drawing: processing (ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2804
diff changeset
371
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1920
diff changeset
372 # From here down, all links are handled by docutils (except
386
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
373 # missing attachments), just fixup node['refuri'].
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
374 if prefix == 'attachment':
1910
5c3dffe2abf1 new function AttachFile.exists to reduce code duplication
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1871
diff changeset
375 if not AttachFile.exists(self.request, self.request.page.page_name, link):
5c3dffe2abf1 new function AttachFile.exists to reduce code duplication
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1871
diff changeset
376 # Attachment doesn't exist, give to MoinMoin to insert upload text.
3089
7345503952dd RST parser: fix attachment: and drawing: processing (ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2804
diff changeset
377 self.process_wiki_text("[[%s]]" % refuri)
754
86ca6b17aba9 Modified fixup_wiki_formatting to be more selective in the formatting it fixes. This allows macros to insert markup, but also allowing them to return inline markup (the initial paragraph tags are removed).
Matthew Gilbert <gilbert@voxmea.net>
parents: 721
diff changeset
378 self.wiki_text = self.fixup_wiki_formatting(self.wiki_text)
386
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
379 self.add_wiki_markup()
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
380 # Attachment exists, just get a link to it.
3150
8ae94675b9f9 AttachFile: some cosmetical source changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3089
diff changeset
381 node['refuri'] = AttachFile.getAttachUrl(self.request.page.page_name, link, self.request)
386
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
382 if not [i for i in node.children if i.__class__ == docutils.nodes.image]:
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1920
diff changeset
383 node['classes'].append(prefix)
386
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
384 elif prefix == 'wiki':
2728
59b3d8b8971f remove (un)quoteName, new functions split_interwiki() and resolve_interwiki(), cleanup interwiki mess, fix some link markup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2286
diff changeset
385 wiki_name, page_name = wikiutil.split_interwiki(link)
59b3d8b8971f remove (un)quoteName, new functions split_interwiki() and resolve_interwiki(), cleanup interwiki mess, fix some link markup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2286
diff changeset
386 wikitag, wikiurl, wikitail, err = wikiutil.resolve_interwiki(self.request, wiki_name, page_name)
386
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
387 wikiurl = wikiutil.mapURL(self.request, wikiurl)
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
388 node['refuri'] = wikiutil.join_wiki(wikiurl, wikitail)
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
389 # Only add additional class information if the reference does
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
390 # not have a child image (don't want to add additional markup
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
391 # for images with targets).
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
392 if not [i for i in node.children if i.__class__ == docutils.nodes.image]:
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
393 node['classes'].append('interwiki')
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
394 elif prefix != '':
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
395 # Some link scheme (http, file, https, mailto, etc.), add class
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1920
diff changeset
396 # information if the reference doesn't have a child image (don't
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1920
diff changeset
397 # want additional markup for images with targets).
386
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
398 # Don't touch the refuri.
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
399 if not [i for i in node.children if i.__class__ == docutils.nodes.image]:
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
400 node['classes'].append(prefix)
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
401 else:
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
402 # Default case - make a link to a wiki page.
4493
af211e2f132c moved anchor parsing from formatter to parsers, fixed anchor parsing for interwiki links, reduce code duplication by new wikiutil.split_anchor()
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3784
diff changeset
403 pagename, anchor = wikiutil.split_anchor(refuri)
2706
d2d4e74978bd remove superfluous request parameter from AbsPageName/RelPageName
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2286
diff changeset
404 page = Page(self.request, wikiutil.AbsPageName(self.formatter.page.page_name, pagename))
3234
a739558ca3dc Page.url() default changed to relative=False
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3150
diff changeset
405 node['refuri'] = page.url(self.request, anchor=anchor)
386
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
406 if not page.exists():
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
407 node['classes'].append('nonexistent')
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
408 html4css1.HTMLTranslator.visit_reference(self, node)
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
409
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
410 def visit_image(self, node):
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
411 """
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
412 Need to intervene in the case of inline images. We need MoinMoin to
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
413 give us the actual src line to the image and then we can feed this
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
414 to the default html4css1 writer. NOTE: Since the writer can't "open"
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
415 this image the scale attribute doesn't work without directly
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
416 specifying the height or width (or both).
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
417
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
418 TODO: Need to handle figures similarly.
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
419 """
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
420 uri = node['uri'].lstrip()
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
421 prefix = '' # assume no prefix
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
422 attach_name = uri
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
423 if ':' in uri:
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
424 prefix = uri.split(':', 1)[0]
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
425 attach_name = uri.split(':', 1)[1]
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
426 # if prefix isn't URL, try to display in page
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
427 if not prefix.lower() in ('file', 'http', 'https', 'ftp'):
1910
5c3dffe2abf1 new function AttachFile.exists to reduce code duplication
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1871
diff changeset
428 if not AttachFile.exists(self.request, self.request.page.page_name, attach_name):
386
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
429 # Attachment doesn't exist, MoinMoin should process it
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
430 if prefix == '':
2804
0e033c419e07 parsers: 'inline:' is gone
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2794
diff changeset
431 prefix = 'attachment:'
3089
7345503952dd RST parser: fix attachment: and drawing: processing (ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2804
diff changeset
432 self.process_wiki_text("{{%s%s}}" % (prefix, attach_name))
386
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
433 self.wiki_text = self.fixup_wiki_formatting(self.wiki_text)
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
434 self.add_wiki_markup()
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
435 # Attachment exists, get a link to it.
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
436 # create the url
3150
8ae94675b9f9 AttachFile: some cosmetical source changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3089
diff changeset
437 node['uri'] = AttachFile.getAttachUrl(self.request.page.page_name, attach_name, self.request, addts=1)
386
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
438 if not node.hasattr('alt'):
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
439 node['alt'] = node.get('name', uri)
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
440 html4css1.HTMLTranslator.visit_image(self, node)
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
441
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
442 def create_wiki_functor(self, moin_func):
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
443 moin_callable = getattr(self.formatter, moin_func)
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
444 def visit_func(self, node):
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
445 self.wiki_text = ''
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
446 self.request.write(moin_callable(1))
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
447 self.body.append(self.wiki_text)
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
448 def depart_func(self, node):
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
449 self.wiki_text = ''
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
450 self.request.write(moin_callable(0))
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
451 self.body.append(self.wiki_text)
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
452 return visit_func, depart_func
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
453
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
454 def setup_wiki_handlers(self):
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
455 """
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
456 Have the MoinMoin formatter handle markup when it makes sense. These
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
457 are portions of the document that do not contain reST specific
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
458 markup. This allows these portions of the document to look
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
459 consistent with other wiki pages.
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
460
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
461 Setup dispatch routines to handle basic document markup. The
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
462 hanlders dict is the html4css1 handler name followed by the wiki
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
463 handler name.
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
464 """
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
465 handlers = {
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
466 # Text Markup
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
467 'emphasis': 'emphasis',
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
468 'strong': 'strong',
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
469 'literal': 'code',
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
470 # Blocks
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
471 'literal_block': 'preformatted',
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
472 # Simple Lists
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
473 # bullet-lists are handled completely by docutils because it uses
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1920
diff changeset
474 # the node context to decide when to make a compact list
386
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
475 # (no <p> tags).
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
476 'list_item': 'listitem',
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
477 # Definition List
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
478 'definition_list': 'definition_list',
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
479 }
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
480 for rest_func, moin_func in handlers.items():
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
481 visit_func, depart_func = self.create_wiki_functor(moin_func)
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
482 visit_func = new.instancemethod(visit_func, self, MoinTranslator)
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
483 depart_func = new.instancemethod(depart_func, self, MoinTranslator)
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
484 setattr(self, 'visit_%s' % (rest_func), visit_func)
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
485 setattr(self, 'depart_%s' % (rest_func), depart_func)
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
486
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
487 # Enumerated list takes an extra paramter so we handle this differently
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
488 def visit_enumerated_list(self, node):
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
489 self.wiki_text = ''
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
490 self.request.write(self.formatter.number_list(1, start=node.get('start', None)))
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
491 self.body.append(self.wiki_text)
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
492
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
493 def depart_enumerated_list(self, node):
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
494 self.wiki_text = ''
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
495 self.request.write(self.formatter.number_list(0))
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
496 self.body.append(self.wiki_text)
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
497
469
ff99c7d6ffcb Added rst admonition class patch by TiagoMacambira
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 407
diff changeset
498 # Admonitions are handled here -=- tmacam
ff99c7d6ffcb Added rst admonition class patch by TiagoMacambira
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 407
diff changeset
499 def create_admonition_functor(self, admotion_class):
ff99c7d6ffcb Added rst admonition class patch by TiagoMacambira
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 407
diff changeset
500 def visit_func(self, node):
ff99c7d6ffcb Added rst admonition class patch by TiagoMacambira
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 407
diff changeset
501 self.wiki_text = ''
ff99c7d6ffcb Added rst admonition class patch by TiagoMacambira
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 407
diff changeset
502 self.request.write(self.formatter.div(1,
3236
710160c96250 Added styles for admonitions and changed the rst-parser to use them
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3150
diff changeset
503 attr={'class': admotion_class},
469
ff99c7d6ffcb Added rst admonition class patch by TiagoMacambira
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 407
diff changeset
504 allowed_attrs=[]))
ff99c7d6ffcb Added rst admonition class patch by TiagoMacambira
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 407
diff changeset
505 self.body.append(self.wiki_text)
ff99c7d6ffcb Added rst admonition class patch by TiagoMacambira
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 407
diff changeset
506 def depart_func(self, node):
ff99c7d6ffcb Added rst admonition class patch by TiagoMacambira
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 407
diff changeset
507 self.wiki_text = ''
ff99c7d6ffcb Added rst admonition class patch by TiagoMacambira
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 407
diff changeset
508 self.request.write(self.formatter.div(0))
ff99c7d6ffcb Added rst admonition class patch by TiagoMacambira
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 407
diff changeset
509 self.body.append(self.wiki_text)
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1920
diff changeset
510
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1920
diff changeset
511 return visit_func, depart_func
469
ff99c7d6ffcb Added rst admonition class patch by TiagoMacambira
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 407
diff changeset
512
ff99c7d6ffcb Added rst admonition class patch by TiagoMacambira
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 407
diff changeset
513 def setup_admonitions_handlers(self):
ff99c7d6ffcb Added rst admonition class patch by TiagoMacambira
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 407
diff changeset
514 """
ff99c7d6ffcb Added rst admonition class patch by TiagoMacambira
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 407
diff changeset
515 Admonitions are handled here... We basically surround admonitions
ff99c7d6ffcb Added rst admonition class patch by TiagoMacambira
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 407
diff changeset
516 in a div with class admonition_{name of the admonition}.
ff99c7d6ffcb Added rst admonition class patch by TiagoMacambira
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 407
diff changeset
517 """
ff99c7d6ffcb Added rst admonition class patch by TiagoMacambira
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 407
diff changeset
518 handled_admonitions = [
ff99c7d6ffcb Added rst admonition class patch by TiagoMacambira
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 407
diff changeset
519 'attention',
ff99c7d6ffcb Added rst admonition class patch by TiagoMacambira
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 407
diff changeset
520 'caution',
ff99c7d6ffcb Added rst admonition class patch by TiagoMacambira
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 407
diff changeset
521 'danger',
ff99c7d6ffcb Added rst admonition class patch by TiagoMacambira
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 407
diff changeset
522 'error',
ff99c7d6ffcb Added rst admonition class patch by TiagoMacambira
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 407
diff changeset
523 'hint',
ff99c7d6ffcb Added rst admonition class patch by TiagoMacambira
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 407
diff changeset
524 'important',
ff99c7d6ffcb Added rst admonition class patch by TiagoMacambira
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 407
diff changeset
525 'note',
ff99c7d6ffcb Added rst admonition class patch by TiagoMacambira
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 407
diff changeset
526 'tip',
ff99c7d6ffcb Added rst admonition class patch by TiagoMacambira
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 407
diff changeset
527 'warning',
ff99c7d6ffcb Added rst admonition class patch by TiagoMacambira
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 407
diff changeset
528 ]
ff99c7d6ffcb Added rst admonition class patch by TiagoMacambira
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 407
diff changeset
529 for adm in handled_admonitions:
ff99c7d6ffcb Added rst admonition class patch by TiagoMacambira
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 407
diff changeset
530 visit_func, depart_func = self.create_admonition_functor(adm)
ff99c7d6ffcb Added rst admonition class patch by TiagoMacambira
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 407
diff changeset
531 visit_func = new.instancemethod(visit_func, self, MoinTranslator)
ff99c7d6ffcb Added rst admonition class patch by TiagoMacambira
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 407
diff changeset
532 depart_func = new.instancemethod(depart_func, self, MoinTranslator)
ff99c7d6ffcb Added rst admonition class patch by TiagoMacambira
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 407
diff changeset
533 setattr(self, 'visit_%s' % (adm), visit_func)
ff99c7d6ffcb Added rst admonition class patch by TiagoMacambira
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 407
diff changeset
534 setattr(self, 'depart_%s' % (adm), depart_func)
ff99c7d6ffcb Added rst admonition class patch by TiagoMacambira
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 407
diff changeset
535
386
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
536
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
537 class MoinDirectives:
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
538 """
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
539 Class to handle all custom directive handling. This code is called as
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
540 part of the parsing stage.
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
541 """
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
542
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
543 def __init__(self, request):
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
544 self.request = request
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
545
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
546 # include MoinMoin pages
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
547 directives.register_directive('include', self.include)
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
548
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
549 # used for MoinMoin macros
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
550 directives.register_directive('macro', self.macro)
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
551
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
552 # disallow a few directives in order to prevent XSS
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
553 # for directive in ('meta', 'include', 'raw'):
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
554 for directive in ('meta', 'raw'):
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
555 directives.register_directive(directive, None)
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
556
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
557 # disable the raw role
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
558 roles._roles['raw'] = None
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
559
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
560 # As a quick fix for infinite includes we only allow a fixed number of
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
561 # includes per page
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
562 self.num_includes = 0
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
563 self.max_includes = 10
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
564
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
565 # Handle the include directive rather than letting the default docutils
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
566 # parser handle it. This allows the inclusion of MoinMoin pages instead of
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
567 # something from the filesystem.
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
568 def include(self, name, arguments, options, content, lineno,
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
569 content_offset, block_text, state, state_machine):
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
570 # content contains the included file name
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
571
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
572 _ = self.request.getText
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
573
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
574 # Limit the number of documents that can be included
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
575 if self.num_includes < self.max_includes:
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
576 self.num_includes += 1
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
577 else:
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
578 lines = [_("**Maximum number of allowed includes exceeded**")]
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
579 state_machine.insert_input(lines, 'MoinDirectives')
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
580 return
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
581
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
582 if len(content):
3308
6eb96b8664b0 security fix: check the ACL of the included page when using the rst parser's include directive
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3237
diff changeset
583 pagename = content[0]
6eb96b8664b0 security fix: check the ACL of the included page when using the rst parser's include directive
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3237
diff changeset
584 page = Page(page_name=pagename, request=self.request)
6eb96b8664b0 security fix: check the ACL of the included page when using the rst parser's include directive
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3237
diff changeset
585 if not self.request.user.may.read(pagename):
6eb96b8664b0 security fix: check the ACL of the included page when using the rst parser's include directive
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3237
diff changeset
586 lines = [_("**You are not allowed to read the page: %s**") % (pagename, )]
386
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
587 else:
3308
6eb96b8664b0 security fix: check the ACL of the included page when using the rst parser's include directive
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3237
diff changeset
588 if page.exists():
6eb96b8664b0 security fix: check the ACL of the included page when using the rst parser's include directive
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3237
diff changeset
589 text = page.get_raw_body()
6eb96b8664b0 security fix: check the ACL of the included page when using the rst parser's include directive
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3237
diff changeset
590 lines = text.split('\n')
6eb96b8664b0 security fix: check the ACL of the included page when using the rst parser's include directive
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3237
diff changeset
591 # Remove the "#format rst" line
6eb96b8664b0 security fix: check the ACL of the included page when using the rst parser's include directive
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3237
diff changeset
592 if lines[0].startswith("#format"):
6eb96b8664b0 security fix: check the ACL of the included page when using the rst parser's include directive
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3237
diff changeset
593 del lines[0]
6eb96b8664b0 security fix: check the ACL of the included page when using the rst parser's include directive
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3237
diff changeset
594 else:
6eb96b8664b0 security fix: check the ACL of the included page when using the rst parser's include directive
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3237
diff changeset
595 lines = [_("**Could not find the referenced page: %s**") % (pagename, )]
6eb96b8664b0 security fix: check the ACL of the included page when using the rst parser's include directive
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3237
diff changeset
596 # Insert the text from the included document and then continue parsing
386
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
597 state_machine.insert_input(lines, 'MoinDirectives')
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
598 return
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
599
1558
5628126794b4 Changed the rst parser to be compatible to the new docutils interface for directives.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1183
diff changeset
600 include.has_content = include.content = True
5628126794b4 Changed the rst parser to be compatible to the new docutils interface for directives.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1183
diff changeset
601 include.option_spec = {}
5628126794b4 Changed the rst parser to be compatible to the new docutils interface for directives.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1183
diff changeset
602 include.required_arguments = 1
5628126794b4 Changed the rst parser to be compatible to the new docutils interface for directives.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1183
diff changeset
603 include.optional_arguments = 0
386
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
604
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
605 # Add additional macro directive.
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
606 # This allows MoinMoin macros to be used either by using the directive
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
607 # directly or by using the substitution syntax. Much cleaner than using the
2789
637a6c5ff74e rst parser: use <<...>> for macros, no inline: any more
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2761
diff changeset
608 # reference hack (`<<SomeMacro>>`_). This however simply adds a node to the
386
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
609 # document tree which is a reference, but through a much better user
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
610 # interface.
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
611 def macro(self, name, arguments, options, content, lineno,
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
612 content_offset, block_text, state, state_machine):
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
613 # content contains macro to be called
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
614 if len(content):
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
615 # Allow either with or without brackets
2789
637a6c5ff74e rst parser: use <<...>> for macros, no inline: any more
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2761
diff changeset
616 if content[0].startswith('<<'):
386
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
617 macro = content[0]
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
618 else:
2789
637a6c5ff74e rst parser: use <<...>> for macros, no inline: any more
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2761
diff changeset
619 macro = '<<%s>>' % content[0]
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1920
diff changeset
620 ref = reference(macro, refuri=macro)
386
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
621 ref['name'] = macro
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
622 return [ref]
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
623 return
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
624
1558
5628126794b4 Changed the rst parser to be compatible to the new docutils interface for directives.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1183
diff changeset
625 macro.has_content = macro.content = True
5628126794b4 Changed the rst parser to be compatible to the new docutils interface for directives.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1183
diff changeset
626 macro.option_spec = {}
5628126794b4 Changed the rst parser to be compatible to the new docutils interface for directives.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1183
diff changeset
627 macro.required_arguments = 1
5628126794b4 Changed the rst parser to be compatible to the new docutils interface for directives.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1183
diff changeset
628 macro.optional_arguments = 0
386
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
629
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
630 if ErrorParser: # fixup in case of missing docutils
44a5abc782ee Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 381
diff changeset
631 Parser = ErrorParser
469
ff99c7d6ffcb Added rst admonition class patch by TiagoMacambira
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 407
diff changeset
632
3784
951ed1df8ec3 move editor quickhelp out of config into parser modules
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3308
diff changeset
633 del _