annotate MoinMoin/formatter/text_html.py @ 6103:500f68d3e2fd

remove our own usage of python_compatibility module
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Tue, 06 Sep 2016 01:00:25 +0200
parents b86af2e26465
children
rev   line source
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1 # -*- coding: iso-8859-1 -*-
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
2 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
3 MoinMoin - "text/html+css" Formatter
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
4
1918
bb2e053067fb fixing copyright headers: remove umlauts (encoding troubles), make epydoc compatible, reformat
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1910
diff changeset
5 @copyright: 2000-2004 by Juergen Hermann <jh@web.de>
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
6 @license: GNU GPL, see COPYING for details.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
7 """
101
2202f548cbb0 use own urllib wrapper, see wikiutil
Thomas Waldmann <tw@waldmann-edv.de>
parents: 69
diff changeset
8 import os.path, re
1364
12ddd8661ad6 basic structure for new AdvancedSearch macro, py2.4 fix for html formatter
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1198
diff changeset
9
3127
ea5383222f2f refactored misc. modules to use own logger instead of request.log
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3123
diff changeset
10 from MoinMoin import log
ea5383222f2f refactored misc. modules to use own logger instead of request.log
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3123
diff changeset
11 logging = log.getLogger(__name__)
ea5383222f2f refactored misc. modules to use own logger instead of request.log
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3123
diff changeset
12
661
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 603
diff changeset
13 from MoinMoin.formatter import FormatterBase
1791
6dd2e29acffe Eclipse PyDev Check: fixed lots of its errors and warnings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1758
diff changeset
14 from MoinMoin import wikiutil, i18n
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
15 from MoinMoin.Page import Page
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
16 from MoinMoin.action import AttachFile
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
17
2572
ce0787373150 introduce ID cache in request, make everybody generate valid IDs even inside includes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2570
diff changeset
18 # insert IDs into output wherever they occur
ce0787373150 introduce ID cache in request, make everybody generate valid IDs even inside includes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2570
diff changeset
19 # warning: breaks toggle line numbers javascript
ce0787373150 introduce ID cache in request, make everybody generate valid IDs even inside includes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2570
diff changeset
20 _id_debug = False
ce0787373150 introduce ID cache in request, make everybody generate valid IDs even inside includes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2570
diff changeset
21
414
6a0bfc86b441 line anchors reactivated
Thomas Waldmann <tw@waldmann-edv.de>
parents: 410
diff changeset
22 line_anchors = True
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
23 prettyprint = False
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
24
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
25 # These are the HTML elements that we treat as block elements.
1364
12ddd8661ad6 basic structure for new AdvancedSearch macro, py2.4 fix for html formatter
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1198
diff changeset
26 _blocks = set(['dd', 'div', 'dl', 'dt', 'form', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6',
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
27 'hr', 'li', 'ol', 'p', 'pre', 'table', 'tbody', 'td', 'tfoot', 'th',
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
28 'thead', 'tr', 'ul', 'blockquote', ])
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
29
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
30 # These are the HTML elements which are typically only used with
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
31 # an opening tag without a separate closing tag. We do not
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
32 # include 'script' or 'style' because sometimes they do have
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
33 # content, and also IE has a parsing bug with those two elements (only)
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
34 # when they don't have a closing tag even if valid XHTML.
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
35
1364
12ddd8661ad6 basic structure for new AdvancedSearch macro, py2.4 fix for html formatter
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1198
diff changeset
36 _self_closing_tags = set(['area', 'base', 'br', 'col', 'frame', 'hr', 'img',
12ddd8661ad6 basic structure for new AdvancedSearch macro, py2.4 fix for html formatter
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1198
diff changeset
37 'input', 'isindex', 'link', 'meta', 'param'])
563
dde3d1b2a9d4 change p generation from self-closing to auto-closing, add \n before table for gui converter
Thomas Waldmann <tw@waldmann-edv.de>
parents: 534
diff changeset
38
dde3d1b2a9d4 change p generation from self-closing to auto-closing, add \n before table for gui converter
Thomas Waldmann <tw@waldmann-edv.de>
parents: 534
diff changeset
39 # We only open those tags and let the browser auto-close them:
1364
12ddd8661ad6 basic structure for new AdvancedSearch macro, py2.4 fix for html formatter
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1198
diff changeset
40 _auto_closing_tags = set(['p'])
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
41
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
42 # These are the elements which generally should cause an increase in the
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
43 # indention level in the html souce code.
1364
12ddd8661ad6 basic structure for new AdvancedSearch macro, py2.4 fix for html formatter
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1198
diff changeset
44 _indenting_tags = set(['ol', 'ul', 'dl', 'li', 'dt', 'dd', 'tr', 'td'])
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
45
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
46 # These are the elements that discard any whitespace they contain as
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
47 # immediate child nodes.
1364
12ddd8661ad6 basic structure for new AdvancedSearch macro, py2.4 fix for html formatter
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1198
diff changeset
48 _space_eating_tags = set(['colgroup', 'dl', 'frameset', 'head', 'map' 'menu',
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
49 'ol', 'optgroup', 'select', 'table', 'tbody', 'tfoot',
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
50 'thead', 'tr', 'ul'])
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
51
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
52 # These are standard HTML attributes which are typically used without any
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
53 # value; e.g., as boolean flags indicated by their presence.
1364
12ddd8661ad6 basic structure for new AdvancedSearch macro, py2.4 fix for html formatter
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1198
diff changeset
54 _html_attribute_boolflags = set(['compact', 'disabled', 'ismap', 'nohref',
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
55 'noresize', 'noshade', 'nowrap', 'readonly',
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
56 'selected', 'wrap'])
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
57
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
58 # These are all the standard HTML attributes that are allowed on any element.
1364
12ddd8661ad6 basic structure for new AdvancedSearch macro, py2.4 fix for html formatter
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1198
diff changeset
59 _common_attributes = set(['accesskey', 'class', 'dir', 'disabled', 'id', 'lang',
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
60 'style', 'tabindex', 'title'])
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
61
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
62
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
63 def rewrite_attribute_name(name, default_namespace='html'):
490
ca35d9e6d63e eypdoc comments: fixed some warnings/errors
Thomas Waldmann <tw@waldmann-edv.de>
parents: 486
diff changeset
64 """
ca35d9e6d63e eypdoc comments: fixed some warnings/errors
Thomas Waldmann <tw@waldmann-edv.de>
parents: 486
diff changeset
65 Takes an attribute name and tries to make it HTML correct.
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
66
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
67 This function takes an attribute name as a string, as it may be
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
68 passed in to a formatting method using a keyword-argument syntax,
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
69 and tries to convert it into a real attribute name. This is
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
70 necessary because some attributes may conflict with Python
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
71 reserved words or variable syntax (such as 'for', 'class', or
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
72 'z-index'); and also to help with backwards compatibility with
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
73 older versions of MoinMoin where different names may have been
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
74 used (such as 'content_id' or 'css').
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
75
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
76 Returns a tuple of strings: (namespace, attribute).
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
77
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
78 Namespaces: The default namespace is always assumed to be 'html',
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
79 unless the input string contains a colon or a double-underscore;
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
80 in which case the first such occurance is assumed to separate the
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
81 namespace prefix from name. So, for example, to get the HTML
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
82 attribute 'for' (as on a <label> element), you can pass in the
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
83 string 'html__for' or even '__for'.
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
84
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
85 Hyphens: To better support hyphens (which are not allowed in Python
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
86 variable names), all occurances of two underscores will be replaced
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
87 with a hyphen. If you use this, then you must also provide a
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
88 namespace since the first occurance of '__' separates a namespace
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
89 from the name.
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
90
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
91 Special cases: Within the 'html' namespace, mainly to preserve
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
92 backwards compatibility, these exceptions ars recognized:
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
93 'content_type', 'content_id', 'css_class', and 'css'.
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
94 Additionally all html attributes starting with 'on' are forced to
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
95 lower-case. Also the string 'xmlns' is recognized as having
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
96 no namespace.
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
97
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
98 Examples:
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
99 'id' -> ('html', 'id')
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
100 'css_class' -> ('html', 'class')
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
101 'content_id' -> ('html', 'id')
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
102 'content_type' -> ('html', 'type')
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
103 'html__for' -> ('html', 'for)
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
104 'xml__space' -> ('xml', 'space')
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
105 '__z__index' -> ('html', 'z-index')
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
106 '__http__equiv' -> ('html', 'http-equiv')
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
107 'onChange' -> ('html', 'onchange')
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
108 'xmlns' -> ('', 'xmlns')
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
109 'xmlns__abc' -> ('xmlns', 'abc')
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
110
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
111 (In actuality we only deal with namespace prefixes, not any real
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
112 namespace URI...we only care about the syntax not the meanings.)
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
113 """
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
114
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
115 # Handle any namespaces (just in case someday we support XHTML)
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
116 if ':' in name:
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
117 ns, name = name.split(':', 1)
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
118 elif '__' in name:
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
119 ns, name = name.split('__', 1)
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
120 elif name == 'xmlns':
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
121 ns = ''
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
122 else:
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
123 ns = default_namespace
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
124
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
125 name.replace('__', '-')
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
126 if ns == 'html':
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
127 # We have an HTML attribute, fix according to DTD
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
128 if name == 'content_type': # MIME type such as in <a> and <link> elements
999
97ce857bdebf whitespace-only cleanup and minor style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 828
diff changeset
129 name = 'type'
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
130 elif name == 'content_id': # moin historical convention
999
97ce857bdebf whitespace-only cleanup and minor style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 828
diff changeset
131 name = 'id'
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
132 elif name in ('css_class', 'css'): # to avoid python word 'class'
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
133 name = 'class'
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
134 elif name.startswith('on'): # event handler hook
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
135 name = name.lower()
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
136 return ns, name
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
137
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
138
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
139 def extend_attribute_dictionary(attributedict, ns, name, value):
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
140 """Add a new attribute to an attribute dictionary, merging values where possible.
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
141
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
142 The attributedict must be a dictionary with tuple-keys of the form:
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
143 (namespace, attrname).
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
144
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
145 The given ns, name, and value will be added to the dictionary. It
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
146 will replace the old value if it existed, except for a few special
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
147 cases where the values are logically merged instead (CSS class
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
148 names and style rules).
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
149
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
150 As a special case, if value is None (not just ''), then the
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
151 attribute is actually deleted from the dictionary.
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
152 """
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
153
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
154 key = ns, name
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
155 if value is None:
1868
64507f46beb2 reduce usage of has_key()
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1866
diff changeset
156 if key in attributedict:
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
157 del attributedict[key]
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
158 else:
1868
64507f46beb2 reduce usage of has_key()
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1866
diff changeset
159 if ns == 'html' and key in attributedict:
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
160 if name == 'class':
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
161 # CSS classes are appended by space-separated list
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
162 value = attributedict[key] + ' ' + value
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
163 elif name == 'style':
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
164 # CSS styles are appended by semicolon-separated rules list
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
165 value = attributedict[key] + '; ' + value
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
166 elif name in _html_attribute_boolflags:
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
167 # All attributes must have a value. According to XHTML those
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
168 # traditionally used as flags should have their value set to
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
169 # the same as the attribute name.
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
170 value = name
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
171 attributedict[key] = value
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
172
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
173
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
174 class Formatter(FormatterBase):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
175 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
176 Send HTML data.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
177 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
178
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
179 hardspace = '&nbsp;'
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
180 indentspace = ' '
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
181
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
182 def __init__(self, request, **kw):
1182
5de0dc972701 removed deprecated usage of apply()
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 999
diff changeset
183 FormatterBase.__init__(self, request, **kw)
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
184 self._indent_level = 0
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
185
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
186 self._in_code = 0 # used by text_gedit
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
187 self._in_code_area = 0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
188 self._in_code_line = 0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
189 self._code_area_js = 0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
190 self._code_area_state = ['', 0, -1, -1, 0]
5618
b86af2e26465 formatter/text_html: Added line number links to code blocks. Also line number show/hide script cleaned up slightly.
Eugene Syromyatnikov <evgsyr@gmail.com>
parents: 5298
diff changeset
191
b86af2e26465 formatter/text_html: Added line number links to code blocks. Also line number show/hide script cleaned up slightly.
Eugene Syromyatnikov <evgsyr@gmail.com>
parents: 5298
diff changeset
192 # code format string. id - code block id, num - line number.
b86af2e26465 formatter/text_html: Added line number links to code blocks. Also line number show/hide script cleaned up slightly.
Eugene Syromyatnikov <evgsyr@gmail.com>
parents: 5298
diff changeset
193 # Caution: upon changing, also check line numbers hide/show js.
b86af2e26465 formatter/text_html: Added line number links to code blocks. Also line number show/hide script cleaned up slightly.
Eugene Syromyatnikov <evgsyr@gmail.com>
parents: 5298
diff changeset
194 self._code_id_format = "%(id)s_%(num)d"
b86af2e26465 formatter/text_html: Added line number links to code blocks. Also line number show/hide script cleaned up slightly.
Eugene Syromyatnikov <evgsyr@gmail.com>
parents: 5298
diff changeset
195
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
196 self._show_section_numbers = None
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
197 self.pagelink_preclosed = False
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
198 self._is_included = kw.get('is_included', False)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
199 self.request = request
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
200 self.cfg = request.cfg
1534
8a53c6676240 Added no_magic to text_html formatter to disable tag autoclosing. (Thanks to Radomir Dopieralski.)
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1366
diff changeset
201 self.no_magic = kw.get('no_magic', False) # disabled tag auto closing
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
202
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
203 if not hasattr(request, '_fmt_hd_counters'):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
204 request._fmt_hd_counters = []
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
205
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
206 # Primitive formatter functions #####################################
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
207
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
208 # all other methods should use these to format tags. This keeps the
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
209 # code clean and handle pathological cases like unclosed p and
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
210 # inline tags.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
211
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
212 def _langAttr(self, lang=None):
401
61e50f3aaf68 fix projection CSS, fix win32 request init, revert Florian's langAttr fix (already done in refactor branch)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 399
diff changeset
213 """ Return lang and dir attribute
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
214 (INTERNAL USE BY HTML FORMATTER ONLY!)
401
61e50f3aaf68 fix projection CSS, fix win32 request init, revert Florian's langAttr fix (already done in refactor branch)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 399
diff changeset
215
61e50f3aaf68 fix projection CSS, fix win32 request init, revert Florian's langAttr fix (already done in refactor branch)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 399
diff changeset
216 Must be used on all block elements - div, p, table, etc.
61e50f3aaf68 fix projection CSS, fix win32 request init, revert Florian's langAttr fix (already done in refactor branch)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 399
diff changeset
217 @param lang: if defined, will return attributes for lang. if not
61e50f3aaf68 fix projection CSS, fix win32 request init, revert Florian's langAttr fix (already done in refactor branch)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 399
diff changeset
218 defined, will return attributes only if the current lang is
61e50f3aaf68 fix projection CSS, fix win32 request init, revert Florian's langAttr fix (already done in refactor branch)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 399
diff changeset
219 different from the content lang.
61e50f3aaf68 fix projection CSS, fix win32 request init, revert Florian's langAttr fix (already done in refactor branch)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 399
diff changeset
220 @rtype: dict
490
ca35d9e6d63e eypdoc comments: fixed some warnings/errors
Thomas Waldmann <tw@waldmann-edv.de>
parents: 486
diff changeset
221 @return: language attributes
401
61e50f3aaf68 fix projection CSS, fix win32 request init, revert Florian's langAttr fix (already done in refactor branch)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 399
diff changeset
222 """
61e50f3aaf68 fix projection CSS, fix win32 request init, revert Florian's langAttr fix (already done in refactor branch)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 399
diff changeset
223 if not lang:
61e50f3aaf68 fix projection CSS, fix win32 request init, revert Florian's langAttr fix (already done in refactor branch)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 399
diff changeset
224 lang = self.request.current_lang
61e50f3aaf68 fix projection CSS, fix win32 request init, revert Florian's langAttr fix (already done in refactor branch)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 399
diff changeset
225 # Actions that generate content in user language should change
61e50f3aaf68 fix projection CSS, fix win32 request init, revert Florian's langAttr fix (already done in refactor branch)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 399
diff changeset
226 # the content lang from the default defined in cfg.
61e50f3aaf68 fix projection CSS, fix win32 request init, revert Florian's langAttr fix (already done in refactor branch)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 399
diff changeset
227 if lang == self.request.content_lang:
61e50f3aaf68 fix projection CSS, fix win32 request init, revert Florian's langAttr fix (already done in refactor branch)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 399
diff changeset
228 # lang is inherited from content div
61e50f3aaf68 fix projection CSS, fix win32 request init, revert Florian's langAttr fix (already done in refactor branch)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 399
diff changeset
229 return {}
61e50f3aaf68 fix projection CSS, fix win32 request init, revert Florian's langAttr fix (already done in refactor branch)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 399
diff changeset
230
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
231 #attr = {'xml:lang': lang, 'lang': lang, 'dir': i18n.getDirection(lang),}
999
97ce857bdebf whitespace-only cleanup and minor style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 828
diff changeset
232 attr = {'lang': lang, 'dir': i18n.getDirection(lang), }
401
61e50f3aaf68 fix projection CSS, fix win32 request init, revert Florian's langAttr fix (already done in refactor branch)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 399
diff changeset
233 return attr
61e50f3aaf68 fix projection CSS, fix win32 request init, revert Florian's langAttr fix (already done in refactor branch)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 399
diff changeset
234
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
235 def _formatAttributes(self, attr=None, allowed_attrs=None, **kw):
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
236 """ Return HTML attributes formatted as a single string. (INTERNAL USE BY HTML FORMATTER ONLY!)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
237
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
238 @param attr: dict containing keys and values
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
239 @param allowed_attrs: A list of allowable attribute names
490
ca35d9e6d63e eypdoc comments: fixed some warnings/errors
Thomas Waldmann <tw@waldmann-edv.de>
parents: 486
diff changeset
240 @param kw: other arbitrary attributes expressed as keyword arguments.
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
241 @rtype: string
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
242 @return: formated attributes or empty string
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
243
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
244 The attributes and their values can either be given in the
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
245 'attr' dictionary, or as extra keyword arguments. They are
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
246 both merged together. See the function
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
247 rewrite_attribute_name() for special notes on how to name
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
248 attributes.
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
249
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
250 Setting a value to None rather than a string (or string
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
251 coercible) will remove that attribute from the list.
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2277
diff changeset
252
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
253 If the list of allowed_attrs is provided, then an error is
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
254 raised if an HTML attribute is encountered that is not in that
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
255 list (or is not a common attribute which is always allowed or
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
256 is not in another XML namespace using the double-underscore
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
257 syntax).
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
258 """
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
259
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
260 # Merge the attr dict and kw dict into a single attributes
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
261 # dictionary (rewriting any attribute names, extracting
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
262 # namespaces, and merging some values like css classes).
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
263 attributes = {} # dict of key=(namespace,name): value=attribute_value
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
264 if attr:
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
265 for a, v in attr.items():
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
266 a_ns, a_name = rewrite_attribute_name(a)
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
267 extend_attribute_dictionary(attributes, a_ns, a_name, v)
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
268 if kw:
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
269 for a, v in kw.items():
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
270 a_ns, a_name = rewrite_attribute_name(a)
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
271 extend_attribute_dictionary(attributes, a_ns, a_name, v)
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
272
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
273 # Add title attribute if missing, but it has an alt.
1868
64507f46beb2 reduce usage of has_key()
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1866
diff changeset
274 if ('html', 'alt') in attributes and ('html', 'title') not in attributes:
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
275 attributes[('html', 'title')] = attributes[('html', 'alt')]
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
276
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
277 # Force both lang and xml:lang to be present and identical if
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
278 # either exists. The lang takes precedence over xml:lang if
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
279 # both exist.
1868
64507f46beb2 reduce usage of has_key()
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1866
diff changeset
280 #if ('html', 'lang') in attributes:
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
281 # attributes[('xml', 'lang')] = attributes[('html', 'lang')]
1868
64507f46beb2 reduce usage of has_key()
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1866
diff changeset
282 #elif ('xml', 'lang') in attributes:
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
283 # attributes[('html', 'lang')] = attributes[('xml', 'lang')]
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
284
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
285 # Check all the HTML attributes to see if they are known and
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
286 # allowed. Ignore attributes if in non-HTML namespaces.
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
287 if allowed_attrs:
1870
9406e02388cf reduce usage of .keys()
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1868
diff changeset
288 for name in [key[1] for key in attributes if key[0] == 'html']:
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
289 if name in _common_attributes or name in allowed_attrs:
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
290 pass
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
291 elif name.startswith('on'):
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
292 pass # Too many event handlers to enumerate, just let them all pass.
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
293 else:
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
294 # Unknown or unallowed attribute.
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
295 err = 'Illegal HTML attribute "%s" passed to formatter' % name
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
296 raise ValueError(err)
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
297
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
298 # Finally, format them all as a single string.
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
299 if attributes:
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
300 # Construct a formatted string containing all attributes
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
301 # with their values escaped. Any html:* namespace
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
302 # attributes drop the namespace prefix. We build this by
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
303 # separating the attributes into three categories:
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
304 #
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
305 # * Those without any namespace (should only be xmlns attributes)
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
306 # * Those in the HTML namespace (we drop the html: prefix for these)
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
307 # * Those in any other non-HTML namespace, including xml:
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
308
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
309 xmlnslist = ['%s="%s"' % (k[1], wikiutil.escape(v, 1))
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
310 for k, v in attributes.items() if not k[0]]
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
311 htmllist = ['%s="%s"' % (k[1], wikiutil.escape(v, 1))
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
312 for k, v in attributes.items() if k[0] == 'html']
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
313 otherlist = ['%s:%s="%s"' % (k[0], k[1], wikiutil.escape(v, 1))
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
314 for k, v in attributes.items() if k[0] and k[0] != 'html']
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
315
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
316 # Join all these lists together in a space-separated string. Also
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
317 # prefix the whole thing with a space too.
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
318 htmllist.sort()
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
319 otherlist.sort()
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
320 all = [''] + xmlnslist + htmllist + otherlist
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
321 return ' '.join(all)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
322 return ''
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
323
2572
ce0787373150 introduce ID cache in request, make everybody generate valid IDs even inside includes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2570
diff changeset
324 def _open(self, tag, newline=False, attr=None, allowed_attrs=None,
ce0787373150 introduce ID cache in request, make everybody generate valid IDs even inside includes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2570
diff changeset
325 is_unique=False, **kw):
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
326 """ Open a tag with optional attributes (INTERNAL USE BY HTML FORMATTER ONLY!)
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2277
diff changeset
327
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
328 @param tag: html tag, string
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
329 @param newline: render tag so following data is on a separate line
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
330 @param attr: dict with tag attributes
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
331 @param allowed_attrs: list of allowed attributes for this element
2572
ce0787373150 introduce ID cache in request, make everybody generate valid IDs even inside includes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2570
diff changeset
332 @param is_unique: ID is already unique
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
333 @param kw: arbitrary attributes and values
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
334 @rtype: string ?
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
335 @return: open tag with attributes as a string
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
336 """
563
dde3d1b2a9d4 change p generation from self-closing to auto-closing, add \n before table for gui converter
Thomas Waldmann <tw@waldmann-edv.de>
parents: 534
diff changeset
337 # If it is self-closing, then don't expect a closing tag later on.
dde3d1b2a9d4 change p generation from self-closing to auto-closing, add \n before table for gui converter
Thomas Waldmann <tw@waldmann-edv.de>
parents: 534
diff changeset
338 is_self_closing = (tag in _self_closing_tags) and ' /' or ''
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
339
2572
ce0787373150 introduce ID cache in request, make everybody generate valid IDs even inside includes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2570
diff changeset
340 # make ID unique
ce0787373150 introduce ID cache in request, make everybody generate valid IDs even inside includes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2570
diff changeset
341 id = None
ce0787373150 introduce ID cache in request, make everybody generate valid IDs even inside includes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2570
diff changeset
342 if not is_unique:
ce0787373150 introduce ID cache in request, make everybody generate valid IDs even inside includes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2570
diff changeset
343 if attr and 'id' in attr:
2576
f4c371b00fec refactor the ID generation/writing code
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2572
diff changeset
344 id = self.make_id_unique(attr['id'])
f4c371b00fec refactor the ID generation/writing code
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2572
diff changeset
345 id = self.qualify_id(id)
f4c371b00fec refactor the ID generation/writing code
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2572
diff changeset
346 attr['id'] = id
2572
ce0787373150 introduce ID cache in request, make everybody generate valid IDs even inside includes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2570
diff changeset
347 if 'id' in kw:
2576
f4c371b00fec refactor the ID generation/writing code
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2572
diff changeset
348 id = self.make_id_unique(kw['id'])
f4c371b00fec refactor the ID generation/writing code
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2572
diff changeset
349 id = self.qualify_id(id)
f4c371b00fec refactor the ID generation/writing code
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2572
diff changeset
350 kw['id'] = id
2572
ce0787373150 introduce ID cache in request, make everybody generate valid IDs even inside includes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2570
diff changeset
351 else:
ce0787373150 introduce ID cache in request, make everybody generate valid IDs even inside includes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2570
diff changeset
352 if attr and 'id' in attr:
ce0787373150 introduce ID cache in request, make everybody generate valid IDs even inside includes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2570
diff changeset
353 id = attr['id']
ce0787373150 introduce ID cache in request, make everybody generate valid IDs even inside includes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2570
diff changeset
354 if 'id' in kw:
ce0787373150 introduce ID cache in request, make everybody generate valid IDs even inside includes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2570
diff changeset
355 id = kw['id']
ce0787373150 introduce ID cache in request, make everybody generate valid IDs even inside includes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2570
diff changeset
356
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
357 if tag in _blocks:
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
358 # Block elements
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
359 result = []
999
97ce857bdebf whitespace-only cleanup and minor style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 828
diff changeset
360
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
361 # Add language attributes, but let caller overide the default
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
362 attributes = self._langAttr()
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
363 if attr:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
364 attributes.update(attr)
999
97ce857bdebf whitespace-only cleanup and minor style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 828
diff changeset
365
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
366 # Format
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
367 attributes = self._formatAttributes(attributes, allowed_attrs=allowed_attrs, **kw)
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
368 result.append('<%s%s%s>' % (tag, attributes, is_self_closing))
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
369 if newline:
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
370 result.append(self._newline())
2572
ce0787373150 introduce ID cache in request, make everybody generate valid IDs even inside includes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2570
diff changeset
371 if _id_debug and id:
ce0787373150 introduce ID cache in request, make everybody generate valid IDs even inside includes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2570
diff changeset
372 result.append('(%s) ' % id)
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
373 tagstr = ''.join(result)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
374 else:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
375 # Inline elements
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
376 tagstr = '<%s%s%s>' % (tag,
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
377 self._formatAttributes(attr, allowed_attrs, **kw),
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
378 is_self_closing)
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
379 return tagstr
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
380
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
381 def _close(self, tag, newline=False):
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
382 """ Close tag (INTERNAL USE BY HTML FORMATTER ONLY!)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
383
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
384 @param tag: html tag, string
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
385 @param newline: render tag so following data is on a separate line
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
386 @rtype: string
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
387 @return: closing tag as a string
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
388 """
1534
8a53c6676240 Added no_magic to text_html formatter to disable tag autoclosing. (Thanks to Radomir Dopieralski.)
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1366
diff changeset
389 if tag in _self_closing_tags or (tag in _auto_closing_tags and not self.no_magic):
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
390 # This tag was already closed
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
391 tagstr = ''
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
392 elif tag in _blocks:
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
393 # Block elements
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
394 result = []
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
395 if newline:
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
396 result.append(self._newline())
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
397 result.append('</%s>' % (tag))
999
97ce857bdebf whitespace-only cleanup and minor style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 828
diff changeset
398 tagstr = ''.join(result)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
399 else:
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2277
diff changeset
400 # Inline elements
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
401 tagstr = '</%s>' % tag
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
402
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
403 if newline:
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
404 tagstr += self._newline()
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
405 return tagstr
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
406
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
407 # Public methods ###################################################
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
408
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
409 def startContent(self, content_id='content', newline=True, **kw):
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
410 """ Start page content div.
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
411
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
412 A link anchor is provided at the beginning of the div, with
2572
ce0787373150 introduce ID cache in request, make everybody generate valid IDs even inside includes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2570
diff changeset
413 an id of 'top' (modified by the request ID cache).
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
414 """
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
415
2572
ce0787373150 introduce ID cache in request, make everybody generate valid IDs even inside includes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2570
diff changeset
416 if hasattr(self, 'page'):
4169
1d5995a6a0e2 Moved unique-id-generation from request into own object
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 3415
diff changeset
417 self.request.uid_generator.begin(self.page.page_name)
2572
ce0787373150 introduce ID cache in request, make everybody generate valid IDs even inside includes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2570
diff changeset
418
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
419 result = []
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
420 # Use the content language
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
421 attr = self._langAttr(self.request.content_lang)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
422 attr['id'] = content_id
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
423 result.append(self._open('div', newline=False, attr=attr,
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
424 allowed_attrs=['align'], **kw))
2572
ce0787373150 introduce ID cache in request, make everybody generate valid IDs even inside includes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2570
diff changeset
425 result.append(self.anchordef('top'))
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
426 if newline:
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
427 result.append('\n')
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
428 return ''.join(result)
999
97ce857bdebf whitespace-only cleanup and minor style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 828
diff changeset
429
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
430 def endContent(self, newline=True):
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
431 """ Close page content div.
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
432
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
433 A link anchor is provided at the end of the div, with
2572
ce0787373150 introduce ID cache in request, make everybody generate valid IDs even inside includes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2570
diff changeset
434 an id of 'bottom' (modified by the request ID cache).
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
435 """
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
436
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
437 result = []
2572
ce0787373150 introduce ID cache in request, make everybody generate valid IDs even inside includes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2570
diff changeset
438 result.append(self.anchordef('bottom'))
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
439 result.append(self._close('div', newline=newline))
2572
ce0787373150 introduce ID cache in request, make everybody generate valid IDs even inside includes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2570
diff changeset
440 if hasattr(self, 'page'):
4169
1d5995a6a0e2 Moved unique-id-generation from request into own object
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 3415
diff changeset
441 self.request.uid_generator.end()
999
97ce857bdebf whitespace-only cleanup and minor style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 828
diff changeset
442 return ''.join(result)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
443
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
444 def lang(self, on, lang_name):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
445 """ Insert text with specific lang and direction.
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2277
diff changeset
446
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
447 Enclose within span tag if lang_name is different from
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2277
diff changeset
448 the current lang
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
449 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
450 tag = 'span'
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
451 if lang_name != self.request.current_lang:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
452 # Enclose text in span using lang attributes
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
453 if on:
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
454 attr = self._langAttr(lang=lang_name)
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
455 return self._open(tag, attr=attr)
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
456 return self._close(tag)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
457
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
458 # Direction did not change, no need for span
999
97ce857bdebf whitespace-only cleanup and minor style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 828
diff changeset
459 return ''
97ce857bdebf whitespace-only cleanup and minor style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 828
diff changeset
460
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
461 # Links ##############################################################
999
97ce857bdebf whitespace-only cleanup and minor style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 828
diff changeset
462
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
463 def pagelink(self, on, pagename='', page=None, **kw):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
464 """ Link to a page.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
465
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
466 formatter.text_python will use an optimized call with a page!=None
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
467 parameter. DO NOT USE THIS YOURSELF OR IT WILL BREAK.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
468
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
469 See wikiutil.link_tag() for possible keyword parameters.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
470 """
1182
5de0dc972701 removed deprecated usage of apply()
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 999
diff changeset
471 FormatterBase.pagelink(self, on, pagename, page, **kw)
1758
4b85e6506535 remove 'generated' attribute from pagelink html output (ported from 1.5-791)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1628
diff changeset
472 if 'generated' in kw:
4b85e6506535 remove 'generated' attribute from pagelink html output (ported from 1.5-791)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1628
diff changeset
473 del kw['generated']
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
474 if page is None:
999
97ce857bdebf whitespace-only cleanup and minor style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 828
diff changeset
475 page = Page(self.request, pagename, formatter=self)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
476 if self.request.user.show_nonexist_qm and on and not page.exists():
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
477 self.pagelink_preclosed = True
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
478 return (page.link_to(self.request, on=1, **kw) +
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
479 self.text("?") +
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
480 page.link_to(self.request, on=0, **kw))
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
481 elif not on and self.pagelink_preclosed:
516
ec330d9ec20b fixed double </a> with qm_noexist
Thomas Waldmann <tw@waldmann-edv.de>
parents: 515
diff changeset
482 self.pagelink_preclosed = False
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
483 return ""
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
484 else:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
485 return page.link_to(self.request, on=on, **kw)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
486
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
487 def interwikilink(self, on, interwiki='', pagename='', **kw):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
488 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
489 @keyword title: override using the interwiki wikiname as title
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
490 """
3054
d2e9afd64276 get formatters in sync with 1.6 cs 2558:3e3a549b49f0, add attachimg icon (needed by html formatter)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2761
diff changeset
491 querystr = kw.get('querystr', {})
2728
59b3d8b8971f remove (un)quoteName, new functions split_interwiki() and resolve_interwiki(), cleanup interwiki mess, fix some link markup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2723
diff changeset
492 wikitag, wikiurl, wikitail, wikitag_bad = wikiutil.resolve_interwiki(self.request, interwiki, pagename)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
493 wikiurl = wikiutil.mapURL(self.request, wikiurl)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
494 if wikitag == 'Self': # for own wiki, do simple links
1628
79679aa664a3 formatter: fix empty pagename Page object generation
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1534
diff changeset
495 wikitail = wikiutil.url_unquote(wikitail)
79679aa664a3 formatter: fix empty pagename Page object generation
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1534
diff changeset
496 try: # XXX this is the only place where we access self.page - do we need it? Crashes silently on actions!
2706
d2d4e74978bd remove superfluous request parameter from AbsPageName/RelPageName
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2701
diff changeset
497 pagename = wikiutil.AbsPageName(self.page.page_name, wikitail)
1628
79679aa664a3 formatter: fix empty pagename Page object generation
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1534
diff changeset
498 except:
79679aa664a3 formatter: fix empty pagename Page object generation
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1534
diff changeset
499 pagename = wikitail
79679aa664a3 formatter: fix empty pagename Page object generation
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1534
diff changeset
500 return self.pagelink(on, pagename, **kw)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
501 else: # return InterWiki hyperlink
569
6c572f52899f fixed missing </a> formatter bug
Thomas Waldmann <tw@waldmann-edv.de>
parents: 563
diff changeset
502 if on:
6c572f52899f fixed missing </a> formatter bug
Thomas Waldmann <tw@waldmann-edv.de>
parents: 563
diff changeset
503 href = wikiutil.join_wiki(wikiurl, wikitail)
3054
d2e9afd64276 get formatters in sync with 1.6 cs 2558:3e3a549b49f0, add attachimg icon (needed by html formatter)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2761
diff changeset
504 if querystr:
3415
cb22f4c4a0fd fix interwiki links using correct query arg separator for the case that there are query args in the interwiki map entry and additionally given in the link markup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3321
diff changeset
505 separator = ('?', '&')['?' in href]
cb22f4c4a0fd fix interwiki links using correct query arg separator for the case that there are query args in the interwiki map entry and additionally given in the link markup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3321
diff changeset
506 href = '%s%s%s' % (href, separator, wikiutil.makeQueryString(querystr))
4493
af211e2f132c moved anchor parsing from formatter to parsers, fixed anchor parsing for interwiki links, reduce code duplication by new wikiutil.split_anchor()
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4476
diff changeset
507 anchor = kw.get('anchor')
af211e2f132c moved anchor parsing from formatter to parsers, fixed anchor parsing for interwiki links, reduce code duplication by new wikiutil.split_anchor()
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4476
diff changeset
508 if anchor:
4560
050428d1c044 Fix processing of anchors (fragment identifiers), see details below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4493
diff changeset
509 href = '%s#%s' % (href, self.sanitize_to_id(anchor))
569
6c572f52899f fixed missing </a> formatter bug
Thomas Waldmann <tw@waldmann-edv.de>
parents: 563
diff changeset
510 if wikitag_bad:
6c572f52899f fixed missing </a> formatter bug
Thomas Waldmann <tw@waldmann-edv.de>
parents: 563
diff changeset
511 html_class = 'badinterwiki'
6c572f52899f fixed missing </a> formatter bug
Thomas Waldmann <tw@waldmann-edv.de>
parents: 563
diff changeset
512 else:
6c572f52899f fixed missing </a> formatter bug
Thomas Waldmann <tw@waldmann-edv.de>
parents: 563
diff changeset
513 html_class = 'interwiki'
6c572f52899f fixed missing </a> formatter bug
Thomas Waldmann <tw@waldmann-edv.de>
parents: 563
diff changeset
514 title = kw.get('title', wikitag)
1816
4a31739bc6e1 Page.url(): removed escaping support
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1796
diff changeset
515 return self.url(1, href, title=title, css=html_class) # interwiki links with umlauts
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
516 else:
569
6c572f52899f fixed missing </a> formatter bug
Thomas Waldmann <tw@waldmann-edv.de>
parents: 563
diff changeset
517 return self.url(0)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
518
3270
e06e15e90ba7 fix some wrong wikiutil.escape usage causing double-escaping
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3149
diff changeset
519 def url(self, on, url=None, css=None, do_escape=None, **kw):
490
ca35d9e6d63e eypdoc comments: fixed some warnings/errors
Thomas Waldmann <tw@waldmann-edv.de>
parents: 486
diff changeset
520 """
3270
e06e15e90ba7 fix some wrong wikiutil.escape usage causing double-escaping
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3149
diff changeset
521 Inserts an <a> element (you can give any A tag attributes as kw args).
490
ca35d9e6d63e eypdoc comments: fixed some warnings/errors
Thomas Waldmann <tw@waldmann-edv.de>
parents: 486
diff changeset
522
3270
e06e15e90ba7 fix some wrong wikiutil.escape usage causing double-escaping
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3149
diff changeset
523 @param on: 1 to start the link, 0 to end the link (no other arguments are needed when on==0).
e06e15e90ba7 fix some wrong wikiutil.escape usage causing double-escaping
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3149
diff changeset
524 @param url: the URL to link to; will go through Wiki URL mapping.
e06e15e90ba7 fix some wrong wikiutil.escape usage causing double-escaping
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3149
diff changeset
525 @param css: a space-separated list of CSS classes
e06e15e90ba7 fix some wrong wikiutil.escape usage causing double-escaping
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3149
diff changeset
526 @param do_escape: DEPRECATED and not used any more, please remove it from your code!
e06e15e90ba7 fix some wrong wikiutil.escape usage causing double-escaping
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3149
diff changeset
527 We will remove this parameter in moin 1.8 (it used to filter url
e06e15e90ba7 fix some wrong wikiutil.escape usage causing double-escaping
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3149
diff changeset
528 param through wikiutil.escape, but text_html formatter's _open
e06e15e90ba7 fix some wrong wikiutil.escape usage causing double-escaping
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3149
diff changeset
529 will do it again, so this just leads to double escaping now).
515
1b9f0d6b9f48 fixed double CSS class attribute for nonexistent links, removed ugly formatter.url attrs keyword handling code
Thomas Waldmann <tw@waldmann-edv.de>
parents: 490
diff changeset
530 """
3270
e06e15e90ba7 fix some wrong wikiutil.escape usage causing double-escaping
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3149
diff changeset
531 if do_escape is not None:
e06e15e90ba7 fix some wrong wikiutil.escape usage causing double-escaping
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3149
diff changeset
532 if do_escape:
e06e15e90ba7 fix some wrong wikiutil.escape usage causing double-escaping
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3149
diff changeset
533 logging.warning("Deprecation warning: MoinMoin.formatter.text_html.url being called with do_escape=1/True parameter, please review caller.")
e06e15e90ba7 fix some wrong wikiutil.escape usage causing double-escaping
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3149
diff changeset
534 else:
e06e15e90ba7 fix some wrong wikiutil.escape usage causing double-escaping
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3149
diff changeset
535 logging.warning("Deprecation warning: MoinMoin.formatter.text_html.url being called with do_escape=0/False parameter, please remove it from the caller.")
515
1b9f0d6b9f48 fixed double CSS class attribute for nonexistent links, removed ugly formatter.url attrs keyword handling code
Thomas Waldmann <tw@waldmann-edv.de>
parents: 490
diff changeset
536 if on:
1b9f0d6b9f48 fixed double CSS class attribute for nonexistent links, removed ugly formatter.url attrs keyword handling code
Thomas Waldmann <tw@waldmann-edv.de>
parents: 490
diff changeset
537 attrs = self._langAttr()
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
538
515
1b9f0d6b9f48 fixed double CSS class attribute for nonexistent links, removed ugly formatter.url attrs keyword handling code
Thomas Waldmann <tw@waldmann-edv.de>
parents: 490
diff changeset
539 # Handle the URL mapping
1868
64507f46beb2 reduce usage of has_key()
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1866
diff changeset
540 if url is None and 'href' in kw:
515
1b9f0d6b9f48 fixed double CSS class attribute for nonexistent links, removed ugly formatter.url attrs keyword handling code
Thomas Waldmann <tw@waldmann-edv.de>
parents: 490
diff changeset
541 url = kw['href']
1b9f0d6b9f48 fixed double CSS class attribute for nonexistent links, removed ugly formatter.url attrs keyword handling code
Thomas Waldmann <tw@waldmann-edv.de>
parents: 490
diff changeset
542 del kw['href']
1b9f0d6b9f48 fixed double CSS class attribute for nonexistent links, removed ugly formatter.url attrs keyword handling code
Thomas Waldmann <tw@waldmann-edv.de>
parents: 490
diff changeset
543 if url is not None:
1b9f0d6b9f48 fixed double CSS class attribute for nonexistent links, removed ugly formatter.url attrs keyword handling code
Thomas Waldmann <tw@waldmann-edv.de>
parents: 490
diff changeset
544 url = wikiutil.mapURL(self.request, url)
1b9f0d6b9f48 fixed double CSS class attribute for nonexistent links, removed ugly formatter.url attrs keyword handling code
Thomas Waldmann <tw@waldmann-edv.de>
parents: 490
diff changeset
545 attrs['href'] = url
1b9f0d6b9f48 fixed double CSS class attribute for nonexistent links, removed ugly formatter.url attrs keyword handling code
Thomas Waldmann <tw@waldmann-edv.de>
parents: 490
diff changeset
546
1b9f0d6b9f48 fixed double CSS class attribute for nonexistent links, removed ugly formatter.url attrs keyword handling code
Thomas Waldmann <tw@waldmann-edv.de>
parents: 490
diff changeset
547 if css:
1b9f0d6b9f48 fixed double CSS class attribute for nonexistent links, removed ugly formatter.url attrs keyword handling code
Thomas Waldmann <tw@waldmann-edv.de>
parents: 490
diff changeset
548 attrs['class'] = css
999
97ce857bdebf whitespace-only cleanup and minor style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 828
diff changeset
549
515
1b9f0d6b9f48 fixed double CSS class attribute for nonexistent links, removed ugly formatter.url attrs keyword handling code
Thomas Waldmann <tw@waldmann-edv.de>
parents: 490
diff changeset
550 markup = self._open('a', attr=attrs, **kw)
34
3ffdb52c6969 remove pretty_url kw where it was unsupported anyway
Thomas Waldmann <tw@waldmann-edv.de>
parents: 0
diff changeset
551 else:
515
1b9f0d6b9f48 fixed double CSS class attribute for nonexistent links, removed ugly formatter.url attrs keyword handling code
Thomas Waldmann <tw@waldmann-edv.de>
parents: 490
diff changeset
552 markup = self._close('a')
1b9f0d6b9f48 fixed double CSS class attribute for nonexistent links, removed ugly formatter.url attrs keyword handling code
Thomas Waldmann <tw@waldmann-edv.de>
parents: 490
diff changeset
553 return markup
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
554
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
555 def anchordef(self, id):
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
556 """Inserts an invisible element used as a link target.
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
557
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
558 Inserts an empty <span> element with an id attribute, used as an anchor
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
559 for link references. We use <span></span> rather than <span/>
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
560 for browser portability.
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
561 """
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
562 # Don't add newlines, \n, as it will break pre and
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
563 # line-numbered code sections (from line_achordef() method).
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
564 #return '<a id="%s"></a>' % (id, ) # do not use - this breaks PRE sections for IE
2572
ce0787373150 introduce ID cache in request, make everybody generate valid IDs even inside includes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2570
diff changeset
565 id = self.make_id_unique(id)
2576
f4c371b00fec refactor the ID generation/writing code
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2572
diff changeset
566 id = self.qualify_id(id)
f4c371b00fec refactor the ID generation/writing code
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2572
diff changeset
567 return '<span class="anchor" id="%s"></span>' % id
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
568
36
eb3b18ffb28b fixed some english strings, better converter debugging msgs, move lineno anchors to formatter
Thomas Waldmann <tw@waldmann-edv.de>
parents: 34
diff changeset
569 def line_anchordef(self, lineno):
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
570 if line_anchors:
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
571 return self.anchordef("line-%d" % lineno)
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
572 else:
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
573 return ''
36
eb3b18ffb28b fixed some english strings, better converter debugging msgs, move lineno anchors to formatter
Thomas Waldmann <tw@waldmann-edv.de>
parents: 34
diff changeset
574
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
575 def anchorlink(self, on, name='', **kw):
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
576 """Insert an <a> link pointing to an anchor on the same page.
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
577
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
578 Call once with on=1 to start the link, and a second time with
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
579 on=0 to end it. No other arguments are needed on the second
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
580 call.
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
581
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
582 The name argument should be the same as the id provided to the
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
583 anchordef() method, or some other elment. It should NOT start
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
584 with '#' as that will be added automatically.
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
585
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
586 The id argument, if provided, is instead the id of this link
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
587 itself and not of the target element the link references.
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
588 """
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
589 attrs = self._langAttr()
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
590 if name:
2576
f4c371b00fec refactor the ID generation/writing code
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2572
diff changeset
591 name = self.sanitize_to_id(name)
f4c371b00fec refactor the ID generation/writing code
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2572
diff changeset
592 attrs['href'] = '#' + self.qualify_id(name)
1868
64507f46beb2 reduce usage of has_key()
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1866
diff changeset
593 if 'href' in kw:
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
594 del kw['href']
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
595 if on:
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
596 str = self._open('a', attr=attrs, **kw)
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
597 else:
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
598 str = self._close('a')
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
599 return str
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
600
36
eb3b18ffb28b fixed some english strings, better converter debugging msgs, move lineno anchors to formatter
Thomas Waldmann <tw@waldmann-edv.de>
parents: 34
diff changeset
601 def line_anchorlink(self, on, lineno=0):
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
602 if line_anchors:
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
603 return self.anchorlink(on, name="line-%d" % lineno)
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
604 else:
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
605 return ''
36
eb3b18ffb28b fixed some english strings, better converter debugging msgs, move lineno anchors to formatter
Thomas Waldmann <tw@waldmann-edv.de>
parents: 34
diff changeset
606
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
607 # Attachments ######################################################
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
608
5125
b8d919e435d5 attachment_link formatter: fix processing of attributes (e.g. 'target', 'title')
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4560
diff changeset
609 def attachment_link(self, on, url=None, querystr=None, **kw):
2701
398af77c7ede fixed attachment_link api - it now has a 'on' parameter like most of the other methods
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2595
diff changeset
610 """ Link to an attachment.
398af77c7ede fixed attachment_link api - it now has a 'on' parameter like most of the other methods
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2595
diff changeset
611
398af77c7ede fixed attachment_link api - it now has a 'on' parameter like most of the other methods
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2595
diff changeset
612 @param on: 1/True=start link, 0/False=end link
398af77c7ede fixed attachment_link api - it now has a 'on' parameter like most of the other methods
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2595
diff changeset
613 @param url: filename.ext or PageName/filename.ext
398af77c7ede fixed attachment_link api - it now has a 'on' parameter like most of the other methods
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2595
diff changeset
614 """
398af77c7ede fixed attachment_link api - it now has a 'on' parameter like most of the other methods
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2595
diff changeset
615 assert on in (0, 1, False, True) # make sure we get called the new way, not like the 1.5 api was
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
616 _ = self.request.getText
5125
b8d919e435d5 attachment_link formatter: fix processing of attributes (e.g. 'target', 'title')
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4560
diff changeset
617 if querystr is None:
b8d919e435d5 attachment_link formatter: fix processing of attributes (e.g. 'target', 'title')
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4560
diff changeset
618 querystr = {}
3054
d2e9afd64276 get formatters in sync with 1.6 cs 2558:3e3a549b49f0, add attachimg icon (needed by html formatter)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2761
diff changeset
619 assert isinstance(querystr, dict) # new in 1.6, only support dicts
d2e9afd64276 get formatters in sync with 1.6 cs 2558:3e3a549b49f0, add attachimg icon (needed by html formatter)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2761
diff changeset
620 if 'do' not in querystr:
d2e9afd64276 get formatters in sync with 1.6 cs 2558:3e3a549b49f0, add attachimg icon (needed by html formatter)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2761
diff changeset
621 querystr['do'] = 'view'
2701
398af77c7ede fixed attachment_link api - it now has a 'on' parameter like most of the other methods
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2595
diff changeset
622 if on:
398af77c7ede fixed attachment_link api - it now has a 'on' parameter like most of the other methods
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2595
diff changeset
623 pagename, filename = AttachFile.absoluteName(url, self.page.page_name)
3127
ea5383222f2f refactored misc. modules to use own logger instead of request.log
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3123
diff changeset
624 #logging.debug("attachment_link: url %s pagename %s filename %s" % (url, pagename, filename))
2701
398af77c7ede fixed attachment_link api - it now has a 'on' parameter like most of the other methods
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2595
diff changeset
625 fname = wikiutil.taintfilename(filename)
398af77c7ede fixed attachment_link api - it now has a 'on' parameter like most of the other methods
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2595
diff changeset
626 if AttachFile.exists(self.request, pagename, fname):
3054
d2e9afd64276 get formatters in sync with 1.6 cs 2558:3e3a549b49f0, add attachimg icon (needed by html formatter)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2761
diff changeset
627 target = AttachFile.getAttachUrl(pagename, fname, self.request, do=querystr['do'])
5125
b8d919e435d5 attachment_link formatter: fix processing of attributes (e.g. 'target', 'title')
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4560
diff changeset
628 if not 'title' in kw:
b8d919e435d5 attachment_link formatter: fix processing of attributes (e.g. 'target', 'title')
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4560
diff changeset
629 kw['title'] = "attachment:%s" % url
b8d919e435d5 attachment_link formatter: fix processing of attributes (e.g. 'target', 'title')
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4560
diff changeset
630 kw['css'] = 'attachment'
2701
398af77c7ede fixed attachment_link api - it now has a 'on' parameter like most of the other methods
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2595
diff changeset
631 else:
5098
ff588e9e24d6 simplify getAttachUrl: remove upload parameter
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5061
diff changeset
632 target = AttachFile.getAttachUrl(pagename, fname, self.request, do='upload_form')
5125
b8d919e435d5 attachment_link formatter: fix processing of attributes (e.g. 'target', 'title')
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4560
diff changeset
633 kw['title'] = _('Upload new attachment "%(filename)s"') % {'filename': fname}
b8d919e435d5 attachment_link formatter: fix processing of attributes (e.g. 'target', 'title')
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4560
diff changeset
634 kw['css'] = 'attachment nonexistent'
b8d919e435d5 attachment_link formatter: fix processing of attributes (e.g. 'target', 'title')
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4560
diff changeset
635 return self.url(on, target, **kw)
2701
398af77c7ede fixed attachment_link api - it now has a 'on' parameter like most of the other methods
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2595
diff changeset
636 else:
398af77c7ede fixed attachment_link api - it now has a 'on' parameter like most of the other methods
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2595
diff changeset
637 return self.url(on)
999
97ce857bdebf whitespace-only cleanup and minor style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 828
diff changeset
638
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
639 def attachment_image(self, url, **kw):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
640 _ = self.request.getText
143
11df1156d432 fixed MoinMoinBugs/BrokenAttachmentPaths
Florian Festi <Florian.Festi@trick.informatik.uni-stuttgart.de>
parents: 104
diff changeset
641 pagename, filename = AttachFile.absoluteName(url, self.page.page_name)
11df1156d432 fixed MoinMoinBugs/BrokenAttachmentPaths
Florian Festi <Florian.Festi@trick.informatik.uni-stuttgart.de>
parents: 104
diff changeset
642 fname = wikiutil.taintfilename(filename)
3054
d2e9afd64276 get formatters in sync with 1.6 cs 2558:3e3a549b49f0, add attachimg icon (needed by html formatter)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2761
diff changeset
643 exists = AttachFile.exists(self.request, pagename, fname)
d2e9afd64276 get formatters in sync with 1.6 cs 2558:3e3a549b49f0, add attachimg icon (needed by html formatter)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2761
diff changeset
644 if exists:
d2e9afd64276 get formatters in sync with 1.6 cs 2558:3e3a549b49f0, add attachimg icon (needed by html formatter)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2761
diff changeset
645 kw['css'] = 'attachment'
5098
ff588e9e24d6 simplify getAttachUrl: remove upload parameter
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5061
diff changeset
646 kw['src'] = AttachFile.getAttachUrl(pagename, fname, self.request, addts=1)
3123
5cb80bd604b4 refactored _() getText calls to match new api
Radomir Dopieralski <moindev@sheep.art.pl>
parents: 3054
diff changeset
647 title = _('Inlined image: %(url)s') % {'url': self.text(url)}
3054
d2e9afd64276 get formatters in sync with 1.6 cs 2558:3e3a549b49f0, add attachimg icon (needed by html formatter)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2761
diff changeset
648 if not 'title' in kw:
d2e9afd64276 get formatters in sync with 1.6 cs 2558:3e3a549b49f0, add attachimg icon (needed by html formatter)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2761
diff changeset
649 kw['title'] = title
d2e9afd64276 get formatters in sync with 1.6 cs 2558:3e3a549b49f0, add attachimg icon (needed by html formatter)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2761
diff changeset
650 # alt is required for images:
d2e9afd64276 get formatters in sync with 1.6 cs 2558:3e3a549b49f0, add attachimg icon (needed by html formatter)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2761
diff changeset
651 if not 'alt' in kw:
d2e9afd64276 get formatters in sync with 1.6 cs 2558:3e3a549b49f0, add attachimg icon (needed by html formatter)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2761
diff changeset
652 kw['alt'] = kw['title']
d2e9afd64276 get formatters in sync with 1.6 cs 2558:3e3a549b49f0, add attachimg icon (needed by html formatter)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2761
diff changeset
653 return self.image(**kw)
d2e9afd64276 get formatters in sync with 1.6 cs 2558:3e3a549b49f0, add attachimg icon (needed by html formatter)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2761
diff changeset
654 else:
3270
e06e15e90ba7 fix some wrong wikiutil.escape usage causing double-escaping
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3149
diff changeset
655 title = _('Upload new attachment "%(filename)s"') % {'filename': fname}
3054
d2e9afd64276 get formatters in sync with 1.6 cs 2558:3e3a549b49f0, add attachimg icon (needed by html formatter)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2761
diff changeset
656 img = self.icon('attachimg')
d2e9afd64276 get formatters in sync with 1.6 cs 2558:3e3a549b49f0, add attachimg icon (needed by html formatter)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2761
diff changeset
657 css = 'nonexistent'
5098
ff588e9e24d6 simplify getAttachUrl: remove upload parameter
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5061
diff changeset
658 target = AttachFile.getAttachUrl(pagename, fname, self.request, do='upload_form')
3149
6749e003d7e2 remove attachments direct serving (cfg.attachments), refactor AttachFile to use formatter for link generation
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3131
diff changeset
659 return self.url(1, target, css=css, title=title) + img + self.url(0)
999
97ce857bdebf whitespace-only cleanup and minor style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 828
diff changeset
660
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
661 def attachment_drawing(self, url, text, **kw):
5061
4d90b17cb7b1 formatter.text_html: moved attachment_drawing to the twikidraw action.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 4640
diff changeset
662 # ToDo try to move this to a better place e.g. __init__
4476
f8e4e84525e8 streamline attachment_drawing formatter behaviour
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3415
diff changeset
663 try:
5102
9ae242080889 drawings/attachments: made editing support more generic (details see below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5098
diff changeset
664 drawing_action = AttachFile.get_action(self.request, url, do='modify')
9ae242080889 drawings/attachments: made editing support more generic (details see below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5098
diff changeset
665 assert drawing_action is not None
5061
4d90b17cb7b1 formatter.text_html: moved attachment_drawing to the twikidraw action.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 4640
diff changeset
666 attachment_drawing = wikiutil.importPlugin(self.request.cfg, 'action',
5102
9ae242080889 drawings/attachments: made editing support more generic (details see below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5098
diff changeset
667 drawing_action, 'attachment_drawing')
5061
4d90b17cb7b1 formatter.text_html: moved attachment_drawing to the twikidraw action.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 4640
diff changeset
668 return attachment_drawing(self, url, text, **kw)
5102
9ae242080889 drawings/attachments: made editing support more generic (details see below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5098
diff changeset
669 except (wikiutil.PluginMissingError, wikiutil.PluginAttributeError, AssertionError):
5061
4d90b17cb7b1 formatter.text_html: moved attachment_drawing to the twikidraw action.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 4640
diff changeset
670 return url
999
97ce857bdebf whitespace-only cleanup and minor style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 828
diff changeset
671
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
672 # Text ##############################################################
999
97ce857bdebf whitespace-only cleanup and minor style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 828
diff changeset
673
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
674 def _text(self, text):
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
675 text = wikiutil.escape(text)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
676 if self._in_code:
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
677 text = text.replace(' ', self.hardspace)
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
678 return text
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
679
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
680 # Inline ###########################################################
999
97ce857bdebf whitespace-only cleanup and minor style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 828
diff changeset
681
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
682 def strong(self, on, **kw):
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
683 """Creates an HTML <strong> element.
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
684
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
685 Call once with on=1 to start the region, and a second time
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
686 with on=0 to end it.
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
687 """
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
688 tag = 'strong'
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
689 if on:
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
690 return self._open(tag, allowed_attrs=[], **kw)
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
691 return self._close(tag)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
692
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
693 def emphasis(self, on, **kw):
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
694 """Creates an HTML <em> element.
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
695
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
696 Call once with on=1 to start the region, and a second time
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
697 with on=0 to end it.
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
698 """
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
699 tag = 'em'
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
700 if on:
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
701 return self._open(tag, allowed_attrs=[], **kw)
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
702 return self._close(tag)
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
703
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
704 def underline(self, on, **kw):
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
705 """Creates a text span for underlining (css class "u").
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
706
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
707 Call once with on=1 to start the region, and a second time
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
708 with on=0 to end it.
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
709 """
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
710 tag = 'span'
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
711 if on:
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
712 return self._open(tag, attr={'class': 'u'}, allowed_attrs=[], **kw)
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
713 return self._close(tag)
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
714
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
715 def highlight(self, on, **kw):
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
716 """Creates a text span for highlighting (css class "highlight").
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
717
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
718 Call once with on=1 to start the region, and a second time
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
719 with on=0 to end it.
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
720 """
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
721 tag = 'strong'
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
722 if on:
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
723 return self._open(tag, attr={'class': 'highlight'}, allowed_attrs=[], **kw)
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
724 return self._close(tag)
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
725
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
726 def sup(self, on, **kw):
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
727 """Creates a <sup> element for superscript text.
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
728
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
729 Call once with on=1 to start the region, and a second time
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
730 with on=0 to end it.
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
731 """
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
732 tag = 'sup'
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
733 if on:
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
734 return self._open(tag, allowed_attrs=[], **kw)
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
735 return self._close(tag)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
736
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
737 def sub(self, on, **kw):
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
738 """Creates a <sub> element for subscript text.
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
739
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
740 Call once with on=1 to start the region, and a second time
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
741 with on=0 to end it.
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
742 """
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
743 tag = 'sub'
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
744 if on:
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
745 return self._open(tag, allowed_attrs=[], **kw)
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
746 return self._close(tag)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
747
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
748 def strike(self, on, **kw):
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
749 """Creates a text span for line-through (strikeout) text (css class 'strike').
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
750
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
751 Call once with on=1 to start the region, and a second time
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
752 with on=0 to end it.
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
753 """
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
754 # This does not use <strike> because has been deprecated in standard HTML.
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
755 tag = 'span'
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
756 if on:
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
757 return self._open(tag, attr={'class': 'strike'},
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
758 allowed_attrs=[], **kw)
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
759 return self._close(tag)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
760
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
761 def code(self, on, **kw):
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
762 """Creates a <tt> element for inline code or monospaced text.
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
763
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
764 Call once with on=1 to start the region, and a second time
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
765 with on=0 to end it.
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
766
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
767 Any text within this section will have spaces converted to
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
768 non-break spaces.
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
769 """
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
770 tag = 'tt'
999
97ce857bdebf whitespace-only cleanup and minor style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 828
diff changeset
771 self._in_code = on
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
772 if on:
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
773 return self._open(tag, allowed_attrs=[], **kw)
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
774 return self._close(tag)
999
97ce857bdebf whitespace-only cleanup and minor style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 828
diff changeset
775
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
776 def small(self, on, **kw):
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
777 """Creates a <small> element for smaller font.
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
778
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
779 Call once with on=1 to start the region, and a second time
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
780 with on=0 to end it.
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
781 """
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
782 tag = 'small'
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
783 if on:
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
784 return self._open(tag, allowed_attrs=[], **kw)
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
785 return self._close(tag)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
786
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
787 def big(self, on, **kw):
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
788 """Creates a <big> element for larger font.
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
789
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
790 Call once with on=1 to start the region, and a second time
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
791 with on=0 to end it.
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
792 """
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
793 tag = 'big'
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
794 if on:
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
795 return self._open(tag, allowed_attrs=[], **kw)
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
796 return self._close(tag)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
797
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
798
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
799 # Block elements ####################################################
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
800
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
801 def preformatted(self, on, **kw):
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
802 """Creates a preformatted text region, with a <pre> element.
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
803
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
804 Call once with on=1 to start the region, and a second time
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
805 with on=0 to end it.
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
806 """
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
807 FormatterBase.preformatted(self, on)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
808 tag = 'pre'
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
809 if on:
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
810 return self._open(tag, newline=1, **kw)
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
811 return self._close(tag)
999
97ce857bdebf whitespace-only cleanup and minor style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 828
diff changeset
812
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
813 # Use by code area
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
814 _toggleLineNumbersScript = """
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
815 <script type="text/javascript">
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
816 function isnumbered(obj) {
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
817 return obj.childNodes.length && obj.firstChild.childNodes.length && obj.firstChild.firstChild.className == 'LineNumber';
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
818 }
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
819 function nformat(num,chrs,add) {
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
820 var nlen = Math.max(0,chrs-(''+num).length), res = '';
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
821 while (nlen>0) { res += ' '; nlen-- }
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
822 return res+num+add;
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
823 }
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
824 function addnumber(did, nstart, nstep) {
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
825 var c = document.getElementById(did), l = c.firstChild, n = 1;
5618
b86af2e26465 formatter/text_html: Added line number links to code blocks. Also line number show/hide script cleaned up slightly.
Eugene Syromyatnikov <evgsyr@gmail.com>
parents: 5298
diff changeset
826 if (!isnumbered(c)) {
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
827 if (typeof nstart == 'undefined') nstart = 1;
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
828 if (typeof nstep == 'undefined') nstep = 1;
5618
b86af2e26465 formatter/text_html: Added line number links to code blocks. Also line number show/hide script cleaned up slightly.
Eugene Syromyatnikov <evgsyr@gmail.com>
parents: 5298
diff changeset
829 var n = nstart;
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
830 while (l != null) {
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
831 if (l.tagName == 'SPAN') {
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
832 var s = document.createElement('SPAN');
5618
b86af2e26465 formatter/text_html: Added line number links to code blocks. Also line number show/hide script cleaned up slightly.
Eugene Syromyatnikov <evgsyr@gmail.com>
parents: 5298
diff changeset
833 var a = document.createElement('A');
b86af2e26465 formatter/text_html: Added line number links to code blocks. Also line number show/hide script cleaned up slightly.
Eugene Syromyatnikov <evgsyr@gmail.com>
parents: 5298
diff changeset
834 s.className = 'LineNumber';
b86af2e26465 formatter/text_html: Added line number links to code blocks. Also line number show/hide script cleaned up slightly.
Eugene Syromyatnikov <evgsyr@gmail.com>
parents: 5298
diff changeset
835 a.appendChild(document.createTextNode(nformat(n,4,'')));
b86af2e26465 formatter/text_html: Added line number links to code blocks. Also line number show/hide script cleaned up slightly.
Eugene Syromyatnikov <evgsyr@gmail.com>
parents: 5298
diff changeset
836 a.href = '#' + did + '_' + n;
b86af2e26465 formatter/text_html: Added line number links to code blocks. Also line number show/hide script cleaned up slightly.
Eugene Syromyatnikov <evgsyr@gmail.com>
parents: 5298
diff changeset
837 s.appendChild(a);
b86af2e26465 formatter/text_html: Added line number links to code blocks. Also line number show/hide script cleaned up slightly.
Eugene Syromyatnikov <evgsyr@gmail.com>
parents: 5298
diff changeset
838 s.appendChild(document.createTextNode(' '));
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
839 n += nstep;
5618
b86af2e26465 formatter/text_html: Added line number links to code blocks. Also line number show/hide script cleaned up slightly.
Eugene Syromyatnikov <evgsyr@gmail.com>
parents: 5298
diff changeset
840 if (l.childNodes.length) {
b86af2e26465 formatter/text_html: Added line number links to code blocks. Also line number show/hide script cleaned up slightly.
Eugene Syromyatnikov <evgsyr@gmail.com>
parents: 5298
diff changeset
841 l.insertBefore(s, l.firstChild);
b86af2e26465 formatter/text_html: Added line number links to code blocks. Also line number show/hide script cleaned up slightly.
Eugene Syromyatnikov <evgsyr@gmail.com>
parents: 5298
diff changeset
842 }
b86af2e26465 formatter/text_html: Added line number links to code blocks. Also line number show/hide script cleaned up slightly.
Eugene Syromyatnikov <evgsyr@gmail.com>
parents: 5298
diff changeset
843 else {
b86af2e26465 formatter/text_html: Added line number links to code blocks. Also line number show/hide script cleaned up slightly.
Eugene Syromyatnikov <evgsyr@gmail.com>
parents: 5298
diff changeset
844 l.appendChild(s);
b86af2e26465 formatter/text_html: Added line number links to code blocks. Also line number show/hide script cleaned up slightly.
Eugene Syromyatnikov <evgsyr@gmail.com>
parents: 5298
diff changeset
845 }
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
846 }
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
847 l = l.nextSibling;
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
848 }
5618
b86af2e26465 formatter/text_html: Added line number links to code blocks. Also line number show/hide script cleaned up slightly.
Eugene Syromyatnikov <evgsyr@gmail.com>
parents: 5298
diff changeset
849 }
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
850 return false;
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
851 }
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
852 function remnumber(did) {
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
853 var c = document.getElementById(did), l = c.firstChild;
5618
b86af2e26465 formatter/text_html: Added line number links to code blocks. Also line number show/hide script cleaned up slightly.
Eugene Syromyatnikov <evgsyr@gmail.com>
parents: 5298
diff changeset
854 if (isnumbered(c)) {
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
855 while (l != null) {
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
856 if (l.tagName == 'SPAN' && l.firstChild.className == 'LineNumber') l.removeChild(l.firstChild);
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
857 l = l.nextSibling;
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
858 }
5618
b86af2e26465 formatter/text_html: Added line number links to code blocks. Also line number show/hide script cleaned up slightly.
Eugene Syromyatnikov <evgsyr@gmail.com>
parents: 5298
diff changeset
859 }
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
860 return false;
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
861 }
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
862 function togglenumber(did, nstart, nstep) {
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
863 var c = document.getElementById(did);
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
864 if (isnumbered(c)) {
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
865 remnumber(did);
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
866 } else {
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
867 addnumber(did,nstart,nstep);
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
868 }
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
869 return false;
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
870 }
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
871 </script>
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
872 """
999
97ce857bdebf whitespace-only cleanup and minor style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 828
diff changeset
873
5284
a83a65fcbb69 bug fix for MoinMoinBugs/LineNumbersWorkingBuggyWithHighlightParser (thanks to Eugene Syromyatnikov for the patch)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 5144
diff changeset
874 def code_area(self, on, code_id, code_type='code', show=0, start=-1, step=-1, msg=None):
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
875 """Creates a formatted code region, with line numbering.
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
876
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
877 This region is formatted as a <div> with a <pre> inside it. The
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
878 code_id argument is assigned to the 'id' of the div element, and
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
879 must be unique within the document. The show, start, and step are
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
880 used for line numbering.
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
881
2576
f4c371b00fec refactor the ID generation/writing code
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2572
diff changeset
882 Note this is not like most formatter methods, it can not take any
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
883 extra keyword arguments.
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
884
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
885 Call once with on=1 to start the region, and a second time
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
886 with on=0 to end it.
5298
d57b74bc4cbd formatter: text_html comment moved to docstring
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 5297
diff changeset
887
d57b74bc4cbd formatter: text_html comment moved to docstring
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 5297
diff changeset
888 the msg string is not escaped
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
889 """
486
72e96d74f98d i18ned the linenumber toggle string
Thomas Waldmann <tw@waldmann-edv.de>
parents: 414
diff changeset
890 _ = self.request.getText
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
891 res = []
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
892 if on:
2576
f4c371b00fec refactor the ID generation/writing code
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2572
diff changeset
893 code_id = self.sanitize_to_id('CA-%s' % code_id)
f4c371b00fec refactor the ID generation/writing code
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2572
diff changeset
894 ci = self.qualify_id(self.make_id_unique(code_id))
f4c371b00fec refactor the ID generation/writing code
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2572
diff changeset
895
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
896 # Open a code area
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
897 self._in_code_area = 1
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
898 self._in_code_line = 0
2572
ce0787373150 introduce ID cache in request, make everybody generate valid IDs even inside includes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2570
diff changeset
899 # id in here no longer used
5618
b86af2e26465 formatter/text_html: Added line number links to code blocks. Also line number show/hide script cleaned up slightly.
Eugene Syromyatnikov <evgsyr@gmail.com>
parents: 5298
diff changeset
900 self._code_area_state = [None, show, start, step, start, ci]
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
901
5284
a83a65fcbb69 bug fix for MoinMoinBugs/LineNumbersWorkingBuggyWithHighlightParser (thanks to Eugene Syromyatnikov for the patch)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 5144
diff changeset
902 if msg:
a83a65fcbb69 bug fix for MoinMoinBugs/LineNumbersWorkingBuggyWithHighlightParser (thanks to Eugene Syromyatnikov for the patch)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 5144
diff changeset
903 attr = {'class': 'codemsg'}
a83a65fcbb69 bug fix for MoinMoinBugs/LineNumbersWorkingBuggyWithHighlightParser (thanks to Eugene Syromyatnikov for the patch)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 5144
diff changeset
904 res.append(self._open('div', attr={'class': 'codemsg'}))
5297
44dca95e51ab parser highlight: enables link to help page for messages
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 5284
diff changeset
905 res.append(msg)
5284
a83a65fcbb69 bug fix for MoinMoinBugs/LineNumbersWorkingBuggyWithHighlightParser (thanks to Eugene Syromyatnikov for the patch)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 5144
diff changeset
906 res.append(self._close('div'))
a83a65fcbb69 bug fix for MoinMoinBugs/LineNumbersWorkingBuggyWithHighlightParser (thanks to Eugene Syromyatnikov for the patch)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 5144
diff changeset
907
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
908 # Open the code div - using left to right always!
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
909 attr = {'class': 'codearea', 'lang': 'en', 'dir': 'ltr'}
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
910 res.append(self._open('div', attr=attr))
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
911
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
912 # Add the script only in the first code area on the page
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
913 if self._code_area_js == 0 and self._code_area_state[1] >= 0:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
914 res.append(self._toggleLineNumbersScript)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
915 self._code_area_js = 1
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
916
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
917 # Add line number link, but only for JavaScript enabled browsers.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
918 if self._code_area_state[1] >= 0:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
919 toggleLineNumbersLink = r'''
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
920 <script type="text/javascript">
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
921 document.write('<a href="#" onclick="return togglenumber(\'%s\', %d, %d);" \
486
72e96d74f98d i18ned the linenumber toggle string
Thomas Waldmann <tw@waldmann-edv.de>
parents: 414
diff changeset
922 class="codenumbers">%s<\/a>');
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
923 </script>
2572
ce0787373150 introduce ID cache in request, make everybody generate valid IDs even inside includes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2570
diff changeset
924 ''' % (ci, self._code_area_state[2], self._code_area_state[3],
486
72e96d74f98d i18ned the linenumber toggle string
Thomas Waldmann <tw@waldmann-edv.de>
parents: 414
diff changeset
925 _("Toggle line numbers"))
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
926 res.append(toggleLineNumbersLink)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
927
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
928 # Open pre - using left to right always!
2572
ce0787373150 introduce ID cache in request, make everybody generate valid IDs even inside includes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2570
diff changeset
929 attr = {'id': ci, 'lang': 'en', 'dir': 'ltr'}
ce0787373150 introduce ID cache in request, make everybody generate valid IDs even inside includes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2570
diff changeset
930 res.append(self._open('pre', newline=True, attr=attr, is_unique=True))
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
931 else:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
932 # Close code area
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
933 res = []
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
934 if self._in_code_line:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
935 res.append(self.code_line(0))
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
936 res.append(self._close('pre'))
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
937 res.append(self._close('div'))
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
938
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
939 # Update state
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
940 self._in_code_area = 0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
941
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
942 return ''.join(res)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
943
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
944 def code_line(self, on):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
945 res = ''
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
946 if not on or (on and self._in_code_line):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
947 res += '</span>\n'
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
948 if on:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
949 res += '<span class="line">'
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
950 if self._code_area_state[1] > 0:
5618
b86af2e26465 formatter/text_html: Added line number links to code blocks. Also line number show/hide script cleaned up slightly.
Eugene Syromyatnikov <evgsyr@gmail.com>
parents: 5298
diff changeset
951 res += ('<span class="LineNumber"><a href="#%(fmt)s">%%(num)4d</a> </span><span class="LineAnchor" id="%(fmt)s"></span>' % {'fmt': self._code_id_format, }) % {
b86af2e26465 formatter/text_html: Added line number links to code blocks. Also line number show/hide script cleaned up slightly.
Eugene Syromyatnikov <evgsyr@gmail.com>
parents: 5298
diff changeset
952 'id': self._code_area_state[5],
b86af2e26465 formatter/text_html: Added line number links to code blocks. Also line number show/hide script cleaned up slightly.
Eugene Syromyatnikov <evgsyr@gmail.com>
parents: 5298
diff changeset
953 'num': self._code_area_state[4],
b86af2e26465 formatter/text_html: Added line number links to code blocks. Also line number show/hide script cleaned up slightly.
Eugene Syromyatnikov <evgsyr@gmail.com>
parents: 5298
diff changeset
954 }
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
955 self._code_area_state[4] += self._code_area_state[3]
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
956 self._in_code_line = on != 0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
957 return res
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
958
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
959 def code_token(self, on, tok_type):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
960 return ['<span class="%s">' % tok_type, '</span>'][not on]
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
961
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
962 # Paragraphs, Lines, Rules ###########################################
999
97ce857bdebf whitespace-only cleanup and minor style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 828
diff changeset
963
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
964 def _indent_spaces(self):
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
965 """Returns space(s) for indenting the html source so list nesting is easy to read.
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
966
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
967 Note that this mostly works, but because of caching may not always be accurate."""
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
968 if prettyprint:
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
969 return self.indentspace * self._indent_level
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
970 else:
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
971 return ''
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
972
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
973 def _newline(self):
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
974 """Returns the whitespace for starting a new html source line, properly indented."""
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
975 if prettyprint:
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
976 return '\n' + self._indent_spaces()
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
977 else:
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
978 return ''
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
979
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
980 def linebreak(self, preformatted=1):
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
981 """Creates a line break in the HTML output.
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2277
diff changeset
982
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
983 If preformatted is true a <br> element is inserted, otherwise
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
984 the linebreak will only be visible in the HTML source.
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
985 """
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
986 if self._in_code_area:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
987 preformatted = 1
3321
8a54a5512c86 don't use <br/> but rather <br> as recommended by the HTML standard and w3c
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3270
diff changeset
988 return ['\n', '<br>\n'][not preformatted] + self._indent_spaces()
999
97ce857bdebf whitespace-only cleanup and minor style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 828
diff changeset
989
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
990 def paragraph(self, on, **kw):
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
991 """Creates a paragraph with a <p> element.
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2277
diff changeset
992
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
993 Call once with on=1 to start the region, and a second time
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
994 with on=0 to end it.
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
995 """
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
996 if self._terse:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
997 return ''
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
998 FormatterBase.paragraph(self, on)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
999 tag = 'p'
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1000 if on:
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1001 tagstr = self._open(tag, **kw)
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1002 else:
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1003 tagstr = self._close(tag)
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1004 return tagstr
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1005
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1006 def rule(self, size=None, **kw):
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1007 """Creates a horizontal rule with an <hr> element.
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1008
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1009 If size is a number in the range [1..6], the CSS class of the rule
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1010 is set to 'hr1' through 'hr6'. The intent is that the larger the
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1011 size number the thicker or bolder the rule will be.
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1012 """
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1013 if size and 1 <= size <= 6:
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1014 # Add hr class: hr1 - hr6
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1015 return self._open('hr', newline=1, attr={'class': 'hr%d' % size}, **kw)
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1016 return self._open('hr', newline=1, **kw)
999
97ce857bdebf whitespace-only cleanup and minor style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 828
diff changeset
1017
2713
ddb2d19684d7 add transclusion / transclusion_param formatter methods (for html: <object> / <param>)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2706
diff changeset
1018 # Images / Transclusion ##############################################
ddb2d19684d7 add transclusion / transclusion_param formatter methods (for html: <object> / <param>)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2706
diff changeset
1019
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1020 def icon(self, type):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1021 return self.request.theme.make_icon(type)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1022
734
bf2435e61f97 moved smileys from MoinMoin.config to theme, fixed smiley text_python caching bug
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 661
diff changeset
1023 smiley = icon
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1024
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1025 def image(self, src=None, **kw):
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1026 """Creates an inline image with an <img> element.
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1027
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1028 The src argument must be the URL to the image file.
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1029 """
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1030 if src:
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1031 kw['src'] = src
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1032 return self._open('img', **kw)
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1033
2713
ddb2d19684d7 add transclusion / transclusion_param formatter methods (for html: <object> / <param>)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2706
diff changeset
1034 def transclusion(self, on, **kw):
ddb2d19684d7 add transclusion / transclusion_param formatter methods (for html: <object> / <param>)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2706
diff changeset
1035 """Transcludes (includes/embeds) another object."""
ddb2d19684d7 add transclusion / transclusion_param formatter methods (for html: <object> / <param>)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2706
diff changeset
1036 if on:
ddb2d19684d7 add transclusion / transclusion_param formatter methods (for html: <object> / <param>)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2706
diff changeset
1037 return self._open('object',
ddb2d19684d7 add transclusion / transclusion_param formatter methods (for html: <object> / <param>)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2706
diff changeset
1038 allowed_attrs=['archive', 'classid', 'codebase',
ddb2d19684d7 add transclusion / transclusion_param formatter methods (for html: <object> / <param>)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2706
diff changeset
1039 'codetype', 'data', 'declare',
ddb2d19684d7 add transclusion / transclusion_param formatter methods (for html: <object> / <param>)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2706
diff changeset
1040 'height', 'name', 'standby',
ddb2d19684d7 add transclusion / transclusion_param formatter methods (for html: <object> / <param>)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2706
diff changeset
1041 'type', 'width', ],
ddb2d19684d7 add transclusion / transclusion_param formatter methods (for html: <object> / <param>)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2706
diff changeset
1042 **kw)
ddb2d19684d7 add transclusion / transclusion_param formatter methods (for html: <object> / <param>)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2706
diff changeset
1043 else:
ddb2d19684d7 add transclusion / transclusion_param formatter methods (for html: <object> / <param>)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2706
diff changeset
1044 return self._close('object')
ddb2d19684d7 add transclusion / transclusion_param formatter methods (for html: <object> / <param>)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2706
diff changeset
1045
ddb2d19684d7 add transclusion / transclusion_param formatter methods (for html: <object> / <param>)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2706
diff changeset
1046 def transclusion_param(self, **kw):
ddb2d19684d7 add transclusion / transclusion_param formatter methods (for html: <object> / <param>)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2706
diff changeset
1047 """Give a parameter to a transcluded object."""
ddb2d19684d7 add transclusion / transclusion_param formatter methods (for html: <object> / <param>)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2706
diff changeset
1048 return self._open('param',
ddb2d19684d7 add transclusion / transclusion_param formatter methods (for html: <object> / <param>)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2706
diff changeset
1049 allowed_attrs=['name', 'type', 'value', 'valuetype', ],
ddb2d19684d7 add transclusion / transclusion_param formatter methods (for html: <object> / <param>)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2706
diff changeset
1050 **kw)
ddb2d19684d7 add transclusion / transclusion_param formatter methods (for html: <object> / <param>)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2706
diff changeset
1051
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1052 # Lists ##############################################################
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1053
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1054 def number_list(self, on, type=None, start=None, **kw):
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1055 """Creates an HTML ordered list, <ol> element.
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1056
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1057 The 'type' if specified can be any legal numbered
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1058 list-style-type, such as 'decimal','lower-roman', etc.
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1059
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1060 The 'start' argument if specified gives the numeric value of
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1061 the first list item (default is 1).
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1062
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1063 Call once with on=1 to start the list, and a second time
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1064 with on=0 to end it.
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1065 """
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1066 tag = 'ol'
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1067 if on:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1068 attr = {}
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1069 if type is not None:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1070 attr['type'] = type
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1071 if start is not None:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1072 attr['start'] = start
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1073 tagstr = self._open(tag, newline=1, attr=attr, **kw)
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1074 else:
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1075 tagstr = self._close(tag, newline=1)
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1076 return tagstr
999
97ce857bdebf whitespace-only cleanup and minor style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 828
diff changeset
1077
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1078 def bullet_list(self, on, **kw):
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1079 """Creates an HTML ordered list, <ul> element.
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1080
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1081 The 'type' if specified can be any legal unnumbered
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1082 list-style-type, such as 'disc','square', etc.
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1083
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1084 Call once with on=1 to start the list, and a second time
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1085 with on=0 to end it.
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1086 """
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1087 tag = 'ul'
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1088 if on:
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1089 tagstr = self._open(tag, newline=1, **kw)
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1090 else:
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1091 tagstr = self._close(tag, newline=1)
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1092 return tagstr
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1093
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1094 def listitem(self, on, **kw):
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1095 """Adds a list item, <li> element, to a previously opened
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1096 bullet or number list.
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1097
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1098 Call once with on=1 to start the region, and a second time
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1099 with on=0 to end it.
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1100 """
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1101 tag = 'li'
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1102 if on:
999
97ce857bdebf whitespace-only cleanup and minor style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 828
diff changeset
1103 tagstr = self._open(tag, newline=1, **kw)
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1104 else:
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1105 tagstr = self._close(tag, newline=1)
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1106 return tagstr
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1107
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1108 def definition_list(self, on, **kw):
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1109 """Creates an HTML definition list, <dl> element.
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1110
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1111 Call once with on=1 to start the list, and a second time
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1112 with on=0 to end it.
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1113 """
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1114 tag = 'dl'
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1115 if on:
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1116 tagstr = self._open(tag, newline=1, **kw)
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1117 else:
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1118 tagstr = self._close(tag, newline=1)
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1119 return tagstr
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1120
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1121 def definition_term(self, on, **kw):
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1122 """Adds a new term to a definition list, HTML element <dt>.
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1123
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1124 Call once with on=1 to start the term, and a second time
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1125 with on=0 to end it.
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1126 """
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1127 tag = 'dt'
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1128 if on:
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1129 tagstr = self._open(tag, newline=1, **kw)
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1130 else:
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1131 tagstr = self._close(tag, newline=0)
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1132 return tagstr
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1133
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1134 def definition_desc(self, on, **kw):
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1135 """Gives the definition to a definition item, HTML element <dd>.
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1136
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1137 Call once with on=1 to start the definition, and a second time
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1138 with on=0 to end it.
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1139 """
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1140 tag = 'dd'
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1141 if on:
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1142 tagstr = self._open(tag, newline=1, **kw)
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1143 else:
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1144 tagstr = self._close(tag, newline=0)
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1145 return tagstr
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1146
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1147 def heading(self, on, depth, **kw):
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1148 # remember depth of first heading, and adapt counting depth accordingly
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1149 if not self._base_depth:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1150 self._base_depth = depth
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1151
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1152 count_depth = max(depth - (self._base_depth - 1), 1)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1153
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1154 # check numbering, possibly changing the default
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1155 if self._show_section_numbers is None:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1156 self._show_section_numbers = self.cfg.show_section_numbers
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1157 numbering = self.request.getPragma('section-numbers', '').lower()
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1158 if numbering in ['0', 'off']:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1159 self._show_section_numbers = 0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1160 elif numbering in ['1', 'on']:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1161 self._show_section_numbers = 1
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1162 elif numbering in ['2', '3', '4', '5', '6']:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1163 # explicit base level for section number display
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1164 self._show_section_numbers = int(numbering)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1165
1796
57f12932915f cleaning up comments, minor refactorings in heading formatter
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1791
diff changeset
1166 heading_depth = depth
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1167
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1168 # closing tag, with empty line after, to make source more readable
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1169 if not on:
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1170 return self._close('h%d' % heading_depth) + '\n'
999
97ce857bdebf whitespace-only cleanup and minor style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 828
diff changeset
1171
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1172 # create section number
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1173 number = ''
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1174 if self._show_section_numbers:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1175 # count headings on all levels
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1176 self.request._fmt_hd_counters = self.request._fmt_hd_counters[:count_depth]
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1177 while len(self.request._fmt_hd_counters) < count_depth:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1178 self.request._fmt_hd_counters.append(0)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1179 self.request._fmt_hd_counters[-1] = self.request._fmt_hd_counters[-1] + 1
1866
0194beaf511e reduce reduce, filter and map usage
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1816
diff changeset
1180 number = '.'.join([str(x) for x in self.request._fmt_hd_counters[self._show_section_numbers-1:]])
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1181 if number: number += ". "
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1182
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1183 # Add space before heading, easier to check source code
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1184 result = '\n' + self._open('h%d' % heading_depth, **kw)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1185
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1186 if self.request.user.show_topbottom:
1796
57f12932915f cleaning up comments, minor refactorings in heading formatter
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1791
diff changeset
1187 result += "%s%s%s%s%s%s" % (
2572
ce0787373150 introduce ID cache in request, make everybody generate valid IDs even inside includes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2570
diff changeset
1188 self.anchorlink(1, "bottom"), self.icon('bottom'), self.anchorlink(0),
ce0787373150 introduce ID cache in request, make everybody generate valid IDs even inside includes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2570
diff changeset
1189 self.anchorlink(1, "top"), self.icon('top'), self.anchorlink(0))
1796
57f12932915f cleaning up comments, minor refactorings in heading formatter
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1791
diff changeset
1190
57f12932915f cleaning up comments, minor refactorings in heading formatter
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1791
diff changeset
1191 return "%s%s" % (result, number)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1192
999
97ce857bdebf whitespace-only cleanup and minor style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 828
diff changeset
1193
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1194 # Tables #############################################################
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1195
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1196 _allowed_table_attrs = {
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1197 'table': ['class', 'id', 'style'],
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1198 'row': ['class', 'id', 'style'],
3131
61d2168cc010 allow "abbr" as table cell attribute
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3127
diff changeset
1199 '': ['colspan', 'rowspan', 'class', 'id', 'style', 'abbr'],
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1200 }
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1201
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1202 def _checkTableAttr(self, attrs, prefix):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1203 """ Check table attributes
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1204
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1205 Convert from wikitable attributes to html 4 attributes.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1206
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1207 @param attrs: attribute dict
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1208 @param prefix: used in wiki table attributes
490
ca35d9e6d63e eypdoc comments: fixed some warnings/errors
Thomas Waldmann <tw@waldmann-edv.de>
parents: 486
diff changeset
1209 @rtype: dict
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1210 @return: valid table attributes
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1211 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1212 if not attrs:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1213 return {}
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1214
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1215 result = {}
529
20f8bda12a7b fix table *bgcolor trouble, cleanup style synth, fix html_gedit api
Thomas Waldmann <tw@waldmann-edv.de>
parents: 525
diff changeset
1216 s = [] # we collect synthesized style in s
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1217 for key, val in attrs.items():
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1218 # Ignore keys that don't start with prefix
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1219 if prefix and key[:len(prefix)] != prefix:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1220 continue
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1221 key = key[len(prefix):]
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1222 val = val.strip('"')
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1223 # remove invalid attrs from dict and synthesize style
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1224 if key == 'width':
529
20f8bda12a7b fix table *bgcolor trouble, cleanup style synth, fix html_gedit api
Thomas Waldmann <tw@waldmann-edv.de>
parents: 525
diff changeset
1225 s.append("width: %s" % val)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1226 elif key == 'height':
529
20f8bda12a7b fix table *bgcolor trouble, cleanup style synth, fix html_gedit api
Thomas Waldmann <tw@waldmann-edv.de>
parents: 525
diff changeset
1227 s.append("height: %s" % val)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1228 elif key == 'bgcolor':
529
20f8bda12a7b fix table *bgcolor trouble, cleanup style synth, fix html_gedit api
Thomas Waldmann <tw@waldmann-edv.de>
parents: 525
diff changeset
1229 s.append("background-color: %s" % val)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1230 elif key == 'align':
529
20f8bda12a7b fix table *bgcolor trouble, cleanup style synth, fix html_gedit api
Thomas Waldmann <tw@waldmann-edv.de>
parents: 525
diff changeset
1231 s.append("text-align: %s" % val)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1232 elif key == 'valign':
529
20f8bda12a7b fix table *bgcolor trouble, cleanup style synth, fix html_gedit api
Thomas Waldmann <tw@waldmann-edv.de>
parents: 525
diff changeset
1233 s.append("vertical-align: %s" % val)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1234 # Ignore unknown keys
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents: