Attachment 'abbr.py'
Download 1 # -*- coding: utf-8 -*-
2 """
3 MoinMoin - Abbreviation Parser
4
5 This extension of the standard Moin wiki parser is mainly written for
6 AccessibleMoin since it is one criteria for accessible sites, that abbrevations
7 or acronyms should be marked with the <abbr title=.. lang=..> markup.
8
9 Since the <acronym> tag won't be probably part of future (X)HTML standards and
10 since Moin patches the missing <abbr> support of Internet Explorer, only <abbr>
11 is used in AccessibleMoin to mark acronyms and abbreviations.
12
13 Syntax:
14 ^WAI^
15 Marks the word WAI as an abbreviation and tries to retrieve the explanation from
16 the standard abbreviation definitions page "AbbrDict" or the page specified
17 with "#pragma abbreviation-definitions PageName" in the header of the page.
18
19 ^WAI|OtherPage^
20 Marks the word WAI as an abbreviation and tries to retrieve the explanation from
21 the specified page "OtherPage". You can use this to overwrite the default settings
22 like "AbbrDict" or "#pragma abbreviation-definitions PageName"
23
24 ^WAI:Web Accessibility Initiative^
25 Marks the word WAI as an abbreviation and uses the given explanation.
26
27 ^WAI|language=de^
28 ^WAI|OtherPage|language=de^
29 ^WAI:Web Accessibility Initiative|language=de^
30 Marks the word WAI as an foreign language abbreviation (compared to the language
31 default of the wiki and the page)
32
33 Please note:
34 * The explanation pages for abbreviations must be in WikiDict format, like
35 " WAI:: Web Accessibility Initiative" (don't forget the space at the beginning!)
36 * If the abbreviation is in an other language than the default page language, please
37 mark this with "|language=LanguageShortcut"
38 * Don't forget the caching mechanism of Moin: To get a page updated with a changed
39 abbreviation explanation (e.g. from AbbrDict) you have to delete the cache of the page
40 or reedit the page again.
41 * For correct display of abbreviations also in IE please put this line in your screen.css
42 "abbr[title] {border-bottom: 1px dotted; cursor: help}"
43
44 Abbreviation Parser heavily based on AcronymParser by Johannes Berg
45
46 MoinMoin - Abbreviation Parser
47 @copyright: 2007 by Oliver Siemoneit
48 @license: GNU GPL, see COPYING for details.
49 """
50
51
52 from MoinMoin.parser import text_moin_wiki as wiki
53 from MoinMoin.wikidicts import Dict
54 from MoinMoin import wikiutil
55 import re
56
57 #Dependencies = ['pages']
58
59 class Parser(wiki.Parser):
60 def __init__(self, raw, request, **kw):
61 self.formatting_rules = ur"(?P<abbr>\^[^\^]*\^)"+"\n" + self.formatting_rules
62 wiki.Parser.__init__(self, raw, request, **kw)
63 self.abbr_dict = Dict(request, "AbbrDict")
64
65 def _abbr_repl(self, word):
66 dictpage = self.request.getPragma('abbreviation-definitions')
67 word = word[1:-1]
68 word = word.strip()
69 key = word
70 exp = ''
71 tmp = word.split('|', 1)
72 if len(tmp) == 2:
73 key = tmp[0]
74 dictpage = tmp[1]
75 else:
76 tmp = word.split(':', 1)
77 if len(tmp) == 2:
78 key = tmp[0]
79 exp = tmp[1]
80
81 lang = ''
82 tmp = word.rsplit('|', 1)
83 if (len(tmp) == 2) and (tmp[1].startswith('language=')):
84 lang = ' lang=%s' % tmp[1].split('=', 1)[1]
85
86 # Explanation directly given?
87 if exp:
88 try:
89 html = '<abbr title="%(exp)s"%(lang)s>%(word)s</abbr>' % {
90 'exp': wikiutil.escape(exp),
91 'lang': lang,
92 'word': wikiutil.escape(key) }
93 return self.request.formatter.rawHTML(html)
94 except:
95 return self.request.formatter.escapedText(key)
96
97 if not self.abbr_dict.has_key(key):
98 return self.request.formatter.escapedText(key)
99 else:
100 try:
101 html = '<abbr title="%(exp)s"%(lang)s>%(word)s</abbr>' % {
102 'exp': wikiutil.escape(self.abbr_dict[key].replace('"','"')),
103 'lang': lang,
104 'word': wikiutil.escape(key) }
105 return self.request.formatter.rawHTML(html)
106 except:
107 return self.request.formatter.escapedText(key)
Attached Files
To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.You are not allowed to attach a file to this page.