Mercurial > moin > 1.9
annotate MoinMoin/parser/text_rst.py @ 4493:af211e2f132c
moved anchor parsing from formatter to parsers, fixed anchor parsing for interwiki links, reduce code duplication by new wikiutil.split_anchor()
author  Thomas Waldmann <tw AT waldmannedv DOT de> 

date  Sun, 18 Jan 2009 12:54:18 +0100 
parents  951ed1df8ec3 
children  b631aca46a48 
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: iso88591 * 
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 waldmannedv 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 waldmannedv 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 waldmannedv 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 modulescoped 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  28 # TODO: Add an error message to dummyOpen so that the user knows that 
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 modulescope 
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 waldmannedv 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 waldmannedv 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  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 waldmannedv 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 waldmannedv 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
readd some .keys() calls when we modify the dict in the loop
Thomas Waldmann <tw AT waldmannedv 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 waldmannedv 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 dummycode  
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 waldmannedv 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 waldmannedv 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 waldmannedv 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 waldmannedv 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])) 
44a5abc782ee
Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
381
diff
changeset

155 raise RuntimeError, err 
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 waldmannedv 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 modulescope 
3784
951ed1df8ec3
move editor quickhelp out of config into parser modules
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
3308
diff
changeset

178 quickhelp = _("""\ 
951ed1df8ec3
move editor quickhelp out of config into parser modules
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
3308
diff
changeset

179 {{{ 
951ed1df8ec3
move editor quickhelp out of config into parser modules
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
3308
diff
changeset

180 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

181 
951ed1df8ec3
move editor quickhelp out of config into parser modules
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
3308
diff
changeset

182 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

183 =========  ~~~~~~~~~ 
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 Horizontal rule:  
951ed1df8ec3
move editor quickhelp out of config into parser modules
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
3308
diff
changeset

186 
951ed1df8ec3
move editor quickhelp out of config into parser modules
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
3308
diff
changeset

187 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

188 
951ed1df8ec3
move editor quickhelp out of config into parser modules
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
3308
diff
changeset

189 .. _external: http://externalsite.example.org/foo/ 
951ed1df8ec3
move editor quickhelp out of config into parser modules
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
3308
diff
changeset

190 
951ed1df8ec3
move editor quickhelp out of config into parser modules
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
3308
diff
changeset

191 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

192 }}} 
951ed1df8ec3
move editor quickhelp out of config into parser modules
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
3308
diff
changeset

193 (!) 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

194 [[http://docutils.sourceforge.net/docs/user/rst/quickref.htmlreStructuredText Quick Reference]]. 
951ed1df8ec3
move editor quickhelp out of config into parser modules
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
3308
diff
changeset

195 """) 
386
44a5abc782ee
Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
381
diff
changeset

196 
44a5abc782ee
Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
381
diff
changeset

197 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

198 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

199 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

200 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

201 
44a5abc782ee
Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
381
diff
changeset

202 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

203 # 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

204 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

205 
44a5abc782ee
Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
381
diff
changeset

206 parts = publish_parts( 
2286
01f05e74aa9c
Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmannedv DOT de>
parents:
1920
diff
changeset

207 source=self.raw, 
01f05e74aa9c
Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmannedv DOT de>
parents:
1920
diff
changeset

208 writer=MoinWriter(formatter, self.request), 
01f05e74aa9c
Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmannedv DOT de>
parents:
1920
diff
changeset

209 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

210 '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

211 'traceback': True, 
44a5abc782ee
Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
381
diff
changeset

212 '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

213 '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

214 'stylesheet_path': '', 
627
b8e8697ea0af
Increased docutils compatiblity, thanks to Matt for the patch.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
469
diff
changeset

215 'template': '', 
386
44a5abc782ee
Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
381
diff
changeset

216 } 
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 html = [] 
44a5abc782ee
Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
381
diff
changeset

220 if parts['title']: 
884  221 # Document title. 
407
bea43f99cc27
starmerged moinrefactor1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmannedv.de>
parents:
386
diff
changeset

222 html.append(formatter.rawHTML('<h1>%s</h1>' % parts['title'])) 
884  223 # If there is only one subtitle it is propagated by Docutils 
224 # to a document subtitle and is held in parts['subtitle'].  
225 # However, if there is more than one subtitle then this is  
226 # 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

227 if parts['subtitle']: 
407
bea43f99cc27
starmerged moinrefactor1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmannedv.de>
parents:
386
diff
changeset

228 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

229 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

230 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

231 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

232 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

233 
44a5abc782ee
Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
381
diff
changeset

234 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

235 """ 
44a5abc782ee
Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
381
diff
changeset

236 RawHTMLList catches all html appended to internal HTMLTranslator lists. 
2286
01f05e74aa9c
Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmannedv DOT de>
parents:
1920
diff
changeset

237 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

238 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 waldmannedv DOT de>
parents:
627
diff
changeset

239 (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

240 """ 
2286
01f05e74aa9c
Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmannedv DOT de>
parents:
1920
diff
changeset

241 
386
44a5abc782ee
Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
381
diff
changeset

242 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

243 self.formatter = formatter 
2286
01f05e74aa9c
Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmannedv DOT de>
parents:
1920
diff
changeset

244 
386
44a5abc782ee
Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
381
diff
changeset

245 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

246 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

247 if f.f_back.f_code.co_filename.endswith('html4css1.py'): 
1181
a7f8dceb4410
remove types module usage
Thomas Waldmann <tw AT waldmannedv DOT de>
parents:
1091
diff
changeset

248 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

249 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

250 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

251 
44a5abc782ee
Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
381
diff
changeset

252 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

253 
44a5abc782ee
Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
381
diff
changeset

254 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

255 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

256 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

257 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

258 # 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

259 # 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

260 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

261 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

262 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

263 # 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

264 # 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

265 # 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

266 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

267 # 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

268 # 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

269 # 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

270 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

271 self.setup_wiki_handlers() 
469
ff99c7d6ffcb
Added rst admonition class patch by TiagoMacambira
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
407
diff
changeset

272 self.setup_admonitions_handlers() 
2286
01f05e74aa9c
Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmannedv DOT de>
parents:
1920
diff
changeset

273 
386
44a5abc782ee
Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
381
diff
changeset

274 # 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

275 # 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

276 for i in self.__dict__: 
1181
a7f8dceb4410
remove types module usage
Thomas Waldmann <tw AT waldmannedv DOT de>
parents:
1091
diff
changeset

277 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

278 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

279 
44a5abc782ee
Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
381
diff
changeset

280 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

281 """ 
44a5abc782ee
Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
381
diff
changeset

282 depart_docinfo assigns a new list to self.body, we need to remake that 
44a5abc782ee
Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
381
diff
changeset

283 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

284 """ 
44a5abc782ee
Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
381
diff
changeset

285 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

286 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

287 
44a5abc782ee
Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
381
diff
changeset

288 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

289 """ 
44a5abc782ee
Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
381
diff
changeset

290 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

291 wiki_text. 
44a5abc782ee
Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
381
diff
changeset

292 """ 
44a5abc782ee
Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
381
diff
changeset

293 # 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

294 # 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

295 # 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

296 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

297 
44a5abc782ee
Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
381
diff
changeset

298 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

299 """ 
44a5abc782ee
Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
381
diff
changeset

300 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

301 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

302 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

303 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

304 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

305 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

306 
44a5abc782ee
Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
381
diff
changeset

307 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

308 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

309 """ 
44a5abc782ee
Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
381
diff
changeset

310 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

311 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

312 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

313 
44a5abc782ee
Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
381
diff
changeset

314 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

315 """ 
44a5abc782ee
Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
381
diff
changeset

316 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

317 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

318 raises SkipNode. 
44a5abc782ee
Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
381
diff
changeset

319 """ 
44a5abc782ee
Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
381
diff
changeset

320 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

321 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 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

323 
44a5abc782ee
Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
381
diff
changeset

324 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

325 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

326 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

327 
44a5abc782ee
Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
381
diff
changeset

328 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

329 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

330 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

331 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

332 # 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

333 # 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

334 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

335 # 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

336 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

337 # 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

338 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

339 return text 
44a5abc782ee
Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
381
diff
changeset

340 
44a5abc782ee
Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
381
diff
changeset

341 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

342 """ 
44a5abc782ee
Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
381
diff
changeset

343 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

344 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

345 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

346 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

347 
44a5abc782ee
Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
381
diff
changeset

348 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 waldmannedv DOT de>
parents:
2761
diff
changeset

349 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

350 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

351 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

352 """ 
44a5abc782ee
Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
381
diff
changeset

353 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

354 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

355 prefix = '' 
44a5abc782ee
Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
381
diff
changeset

356 link = refuri 
44a5abc782ee
Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
381
diff
changeset

357 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

358 prefix, link = refuri.lstrip().split(':', 1) 
2286
01f05e74aa9c
Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmannedv DOT de>
parents:
1920
diff
changeset

359 
386
44a5abc782ee
Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
381
diff
changeset

360 # 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 waldmannedv DOT de>
parents:
2804
diff
changeset

361 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

362 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

363 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

364 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

365 
3089
7345503952dd
RST parser: fix attachment: and drawing: processing (ported from 1.6)
Thomas Waldmann <tw AT waldmannedv DOT de>
parents:
2804
diff
changeset

366 if prefix == 'drawing': # twikidraw drawing 
7345503952dd
RST parser: fix attachment: and drawing: processing (ported from 1.6)
Thomas Waldmann <tw AT waldmannedv DOT de>
parents:
2804
diff
changeset

367 self.process_wiki_text("[[%s]]" % refuri) 
7345503952dd
RST parser: fix attachment: and drawing: processing (ported from 1.6)
Thomas Waldmann <tw AT waldmannedv DOT de>
parents:
2804
diff
changeset

368 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 waldmannedv DOT de>
parents:
2804
diff
changeset

369 self.add_wiki_markup() 
7345503952dd
RST parser: fix attachment: and drawing: processing (ported from 1.6)
Thomas Waldmann <tw AT waldmannedv DOT de>
parents:
2804
diff
changeset

370 
2286
01f05e74aa9c
Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmannedv DOT de>
parents:
1920
diff
changeset

371 # 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

372 # 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

373 if prefix == 'attachment': 
1910
5c3dffe2abf1
new function AttachFile.exists to reduce code duplication
Thomas Waldmann <tw AT waldmannedv DOT de>
parents:
1871
diff
changeset

374 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 waldmannedv DOT de>
parents:
1871
diff
changeset

375 # 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 waldmannedv DOT de>
parents:
2804
diff
changeset

376 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

377 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

378 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

379 # Attachment exists, just get a link to it. 
3150
8ae94675b9f9
AttachFile: some cosmetical source changes
Thomas Waldmann <tw AT waldmannedv DOT de>
parents:
3089
diff
changeset

380 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

381 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 waldmannedv DOT de>
parents:
1920
diff
changeset

382 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

383 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 waldmannedv DOT de>
parents:
2286
diff
changeset

384 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 waldmannedv DOT de>
parents:
2286
diff
changeset

385 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

386 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

387 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

388 # 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

389 # 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

390 # 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

391 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

392 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

393 elif prefix != '': 
44a5abc782ee
Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
381
diff
changeset

394 # Some link scheme (http, file, https, mailto, etc.), add class 
2286
01f05e74aa9c
Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmannedv DOT de>
parents:
1920
diff
changeset

395 # information if the reference doesn't have a child image (don't 
01f05e74aa9c
Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmannedv DOT de>
parents:
1920
diff
changeset

396 # 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

397 # 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

398 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

399 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

400 else: 
44a5abc782ee
Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
381
diff
changeset

401 # 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 waldmannedv DOT de>
parents:
3784
diff
changeset

402 pagename, anchor = wikiutil.split_anchor(refuri) 
2706
d2d4e74978bd
remove superfluous request parameter from AbsPageName/RelPageName
Thomas Waldmann <tw AT waldmannedv DOT de>
parents:
2286
diff
changeset

403 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 waldmannedv DOT de>
parents:
3150
diff
changeset

404 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

405 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

406 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

407 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

408 
44a5abc782ee
Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
381
diff
changeset

409 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

410 """ 
44a5abc782ee
Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
381
diff
changeset

411 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

412 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

413 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

414 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

415 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

416 
44a5abc782ee
Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
381
diff
changeset

417 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

418 """ 
44a5abc782ee
Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
381
diff
changeset

419 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

420 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

421 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

422 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

423 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

424 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

425 # 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

426 if not prefix.lower() in ('file', 'http', 'https', 'ftp'): 
1910
5c3dffe2abf1
new function AttachFile.exists to reduce code duplication
Thomas Waldmann <tw AT waldmannedv DOT de>
parents:
1871
diff
changeset

427 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

428 # 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

429 if prefix == '': 
2804
0e033c419e07
parsers: 'inline:' is gone
Thomas Waldmann <tw AT waldmannedv DOT de>
parents:
2794
diff
changeset

430 prefix = 'attachment:' 
3089
7345503952dd
RST parser: fix attachment: and drawing: processing (ported from 1.6)
Thomas Waldmann <tw AT waldmannedv DOT de>
parents:
2804
diff
changeset

431 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

432 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

433 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

434 # 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

435 # create the url 
3150
8ae94675b9f9
AttachFile: some cosmetical source changes
Thomas Waldmann <tw AT waldmannedv DOT de>
parents:
3089
diff
changeset

436 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

437 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

438 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

439 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

440 
44a5abc782ee
Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
381
diff
changeset

441 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

442 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

443 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

444 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

445 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

446 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

447 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

448 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

449 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

450 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

451 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

452 
44a5abc782ee
Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
381
diff
changeset

453 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

454 """ 
44a5abc782ee
Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
381
diff
changeset

455 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

456 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

457 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

458 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

459 
44a5abc782ee
Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
381
diff
changeset

460 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

461 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

462 handler name. 
44a5abc782ee
Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
381
diff
changeset

463 """ 
44a5abc782ee
Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
381
diff
changeset

464 handlers = { 
44a5abc782ee
Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
381
diff
changeset

465 # Text Markup 
44a5abc782ee
Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
381
diff
changeset

466 'emphasis': 'emphasis', 
44a5abc782ee
Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
381
diff
changeset

467 'strong': 'strong', 
44a5abc782ee
Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
381
diff
changeset

468 'literal': 'code', 
44a5abc782ee
Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
381
diff
changeset

469 # Blocks 
44a5abc782ee
Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
381
diff
changeset

470 '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

471 # Simple Lists 
44a5abc782ee
Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
381
diff
changeset

472 # bulletlists are handled completely by docutils because it uses 
2286
01f05e74aa9c
Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmannedv DOT de>
parents:
1920
diff
changeset

473 # 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

474 # (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

475 '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

476 # Definition List 
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': '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 } 
44a5abc782ee
Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
381
diff
changeset

479 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

480 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

481 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

482 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

483 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

484 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

485 
44a5abc782ee
Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
381
diff
changeset

486 # 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

487 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

488 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

489 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

490 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

491 
44a5abc782ee
Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
381
diff
changeset

492 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

493 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

494 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

495 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

496 
469
ff99c7d6ffcb
Added rst admonition class patch by TiagoMacambira
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
407
diff
changeset

497 # Admonitions are handled here = tmacam 
ff99c7d6ffcb
Added rst admonition class patch by TiagoMacambira
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
407
diff
changeset

498 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

499 def visit_func(self, node): 
ff99c7d6ffcb
Added rst admonition class patch by TiagoMacambira
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
407
diff
changeset

500 self.wiki_text = '' 
ff99c7d6ffcb
Added rst admonition class patch by TiagoMacambira
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
407
diff
changeset

501 self.request.write(self.formatter.div(1, 
3236
710160c96250
Added styles for admonitions and changed the rstparser to use them
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents:
3150
diff
changeset

502 attr={'class': admotion_class}, 
469
ff99c7d6ffcb
Added rst admonition class patch by TiagoMacambira
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
407
diff
changeset

503 allowed_attrs=[])) 
ff99c7d6ffcb
Added rst admonition class patch by TiagoMacambira
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
407
diff
changeset

504 self.body.append(self.wiki_text) 
ff99c7d6ffcb
Added rst admonition class patch by TiagoMacambira
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
407
diff
changeset

505 def depart_func(self, node): 
ff99c7d6ffcb
Added rst admonition class patch by TiagoMacambira
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
407
diff
changeset

506 self.wiki_text = '' 
ff99c7d6ffcb
Added rst admonition class patch by TiagoMacambira
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
407
diff
changeset

507 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

508 self.body.append(self.wiki_text) 
2286
01f05e74aa9c
Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmannedv DOT de>
parents:
1920
diff
changeset

509 
01f05e74aa9c
Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmannedv DOT de>
parents:
1920
diff
changeset

510 return visit_func, depart_func 
469
ff99c7d6ffcb
Added rst admonition class patch by TiagoMacambira
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
407
diff
changeset

511 
ff99c7d6ffcb
Added rst admonition class patch by TiagoMacambira
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
407
diff
changeset

512 def setup_admonitions_handlers(self): 
ff99c7d6ffcb
Added rst admonition class patch by TiagoMacambira
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
407
diff
changeset

513 """ 
ff99c7d6ffcb
Added rst admonition class patch by TiagoMacambira
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
407
diff
changeset

514 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

515 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

516 """ 
ff99c7d6ffcb
Added rst admonition class patch by TiagoMacambira
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
407
diff
changeset

517 handled_admonitions = [ 
ff99c7d6ffcb
Added rst admonition class patch by TiagoMacambira
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
407
diff
changeset

518 'attention', 
ff99c7d6ffcb
Added rst admonition class patch by TiagoMacambira
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
407
diff
changeset

519 'caution', 
ff99c7d6ffcb
Added rst admonition class patch by TiagoMacambira
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
407
diff
changeset

520 'danger', 
ff99c7d6ffcb
Added rst admonition class patch by TiagoMacambira
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
407
diff
changeset

521 'error', 
ff99c7d6ffcb
Added rst admonition class patch by TiagoMacambira
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
407
diff
changeset

522 'hint', 
ff99c7d6ffcb
Added rst admonition class patch by TiagoMacambira
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
407
diff
changeset

523 'important', 
ff99c7d6ffcb
Added rst admonition class patch by TiagoMacambira
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
407
diff
changeset

524 'note', 
ff99c7d6ffcb
Added rst admonition class patch by TiagoMacambira
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
407
diff
changeset

525 'tip', 
ff99c7d6ffcb
Added rst admonition class patch by TiagoMacambira
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
407
diff
changeset

526 'warning', 
ff99c7d6ffcb
Added rst admonition class patch by TiagoMacambira
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
407
diff
changeset

527 ] 
ff99c7d6ffcb
Added rst admonition class patch by TiagoMacambira
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
407
diff
changeset

528 for adm in handled_admonitions: 
ff99c7d6ffcb
Added rst admonition class patch by TiagoMacambira
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
407
diff
changeset

529 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

530 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

531 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

532 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

533 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

534 
386
44a5abc782ee
Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
381
diff
changeset

535 
44a5abc782ee
Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
381
diff
changeset

536 class MoinDirectives: 
44a5abc782ee
Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
381
diff
changeset

537 """ 
44a5abc782ee
Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
381
diff
changeset

538 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

539 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

540 """ 
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 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

543 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

544 
44a5abc782ee
Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
381
diff
changeset

545 # 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

546 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

547 
44a5abc782ee
Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
381
diff
changeset

548 # 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

549 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

550 
44a5abc782ee
Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
381
diff
changeset

551 # 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

552 # 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

553 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

554 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

555 
44a5abc782ee
Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
381
diff
changeset

556 # 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

557 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

558 
44a5abc782ee
Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
381
diff
changeset

559 # 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

560 # 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

561 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

562 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

563 
44a5abc782ee
Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
381
diff
changeset

564 # 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

565 # 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

566 # 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

567 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

568 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

569 # 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

570 
44a5abc782ee
Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
381
diff
changeset

571 _ = 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

572 
44a5abc782ee
Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
381
diff
changeset

573 # 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

574 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

575 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

576 else: 
44a5abc782ee
Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
381
diff
changeset

577 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

578 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

579 return 
44a5abc782ee
Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
381
diff
changeset

580 
44a5abc782ee
Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
381
diff
changeset

581 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 waldmannedv DOT de>
parents:
3237
diff
changeset

582 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 waldmannedv DOT de>
parents:
3237
diff
changeset

583 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 waldmannedv DOT de>
parents:
3237
diff
changeset

584 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 waldmannedv DOT de>
parents:
3237
diff
changeset

585 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

586 else: 
3308
6eb96b8664b0
security fix: check the ACL of the included page when using the rst parser's include directive
Thomas Waldmann <tw AT waldmannedv DOT de>
parents:
3237
diff
changeset

587 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 waldmannedv DOT de>
parents:
3237
diff
changeset

588 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 waldmannedv DOT de>
parents:
3237
diff
changeset

589 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 waldmannedv DOT de>
parents:
3237
diff
changeset

590 # 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 waldmannedv DOT de>
parents:
3237
diff
changeset

591 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 waldmannedv DOT de>
parents:
3237
diff
changeset

592 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 waldmannedv DOT de>
parents:
3237
diff
changeset

593 else: 
6eb96b8664b0
security fix: check the ACL of the included page when using the rst parser's include directive
Thomas Waldmann <tw AT waldmannedv DOT de>
parents:
3237
diff
changeset

594 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 waldmannedv DOT de>
parents:
3237
diff
changeset

595 # 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

596 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

597 return 
44a5abc782ee
Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
381
diff
changeset

598 
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

599 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

600 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

601 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

602 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

603 
44a5abc782ee
Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
381
diff
changeset

604 # 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

605 # 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

606 # 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 waldmannedv DOT de>
parents:
2761
diff
changeset

607 # 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

608 # 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

609 # interface. 
44a5abc782ee
Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
381
diff
changeset

610 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

611 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

612 # 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

613 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

614 # Allow either with or without brackets 
2789
637a6c5ff74e
rst parser: use <<...>> for macros, no inline: any more
Thomas Waldmann <tw AT waldmannedv DOT de>
parents:
2761
diff
changeset

615 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

616 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

617 else: 
2789
637a6c5ff74e
rst parser: use <<...>> for macros, no inline: any more
Thomas Waldmann <tw AT waldmannedv DOT de>
parents:
2761
diff
changeset

618 macro = '<<%s>>' % content[0] 
2286
01f05e74aa9c
Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmannedv DOT de>
parents:
1920
diff
changeset

619 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

620 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

621 return [ref] 
44a5abc782ee
Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
381
diff
changeset

622 return 
44a5abc782ee
Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
381
diff
changeset

623 
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

624 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

625 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

626 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

627 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

628 
44a5abc782ee
Fixed line endings in rst parser and removed the copy import.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
381
diff
changeset

629 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

630 Parser = ErrorParser 
469
ff99c7d6ffcb
Added rst admonition class patch by TiagoMacambira
Alexander Schremmer <alex@alexanderweb.de.tla>
parents:
407
diff
changeset

631 
3784
951ed1df8ec3
move editor quickhelp out of config into parser modules
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
3308
diff
changeset

632 del _ 