1 """
2 Creole Wiki (as used on bitbucket.org).
3 See http://www.wikicreole.org/wiki/Creole1.0 for syntax.
4 """
5
6
7 import re, os, commands, sys
8 from common import default_movie, plain_exercise
9
11 c = re.compile(r'^!bc(.*?)\n', re.MULTILINE)
12 filestr = c.sub(r'{{{\n', filestr)
13 filestr = re.sub(r'!ec\n', r'}}}\n', filestr)
14 c = re.compile(r'^!bt\n', re.MULTILINE)
15 filestr = c.sub(r'{{{\n', filestr)
16 filestr = re.sub(r'!et\n', r'}}}\n', filestr)
17 return filestr
18
43
44 from common import table_analysis
45
47 """Native Creole wiki table."""
48
49
50 column_width = [c+2 for c in table_analysis(table['rows'])]
51
52 s = '\n'
53 for i, row in enumerate(table['rows']):
54 if row == ['horizontal rule']:
55 continue
56 if i == 1 and \
57 table['rows'][i-1] == ['horizontal rule'] and \
58 table['rows'][i+1] == ['horizontal rule']:
59 headline = True
60 else:
61 headline = False
62
63 for column, w in zip(row, column_width):
64 if headline:
65 c = '=%s ' % ((column).ljust(w))
66 else:
67 c = ' %s ' % column.ljust(w)
68 s += ' | %s ' % c
69 s += ' |\n'
70 s += '\n\n'
71 return s
72
73 -def cwiki_author(authors_and_institutions, auth2index,
74 inst2index, index2inst, auth2email):
75
76 authors = []
77 for author, i, email in authors_and_institutions:
78 if email is None:
79 email_text = ''
80 else:
81 name, adr = email.split('@')
82 email_text = ' (%s at %s)' % (name, adr)
83 authors.append('_%s_%s' % (author, email_text))
84
85 if len(authors) == 1:
86 authors = authors[0]
87 elif len(authors) == 2:
88 authors = authors[0] + ' and ' + authors[1]
89 elif len(authors) > 2:
90 authors[-1] = 'and ' + authors[-1]
91 authors = ', '.join(authors)
92 else:
93
94 return ''
95 text = '\n\nBy ' + authors + '\n\n'
96
97 return text
98
100
101
102 pattern = r'[Ss]ection(s?)\s+ref\{'
103 replacement = r'the section\g<1> ref{'
104 filestr = re.sub(pattern, replacement, filestr)
105 pattern = r'[Cc]hapter(s?)\s+ref\{'
106 replacement = r'the chapter\g<1> ref{'
107 filestr = re.sub(pattern, replacement, filestr)
108
109
110 filestr = re.sub(r'label\{.+?\}', '', filestr)
111
112
113
114
115 for label in section_label2title:
116 title = section_label2title[label]
117 filestr = filestr.replace('ref{%s}' % label,
118 '[#%s]' % title.replace(' ', '_'))
119
120 from common import ref2equations
121 filestr = ref2equations(filestr)
122
123
124 filestr = re.sub(r'ref\{(.+?)\}', '\g<1>', filestr)
125
126 return filestr
127
128
129 -def define(FILENAME_EXTENSION,
130 BLANKLINE,
131 INLINE_TAGS_SUBST,
132 CODE,
133 LIST,
134 ARGLIST,
135 TABLE,
136 EXERCISE,
137 FIGURE_EXT,
138 CROSS_REFS,
139 INDEX_BIB,
140 INTRO,
141 OUTRO):
142
143
144 FILENAME_EXTENSION['cwiki'] = '.cwiki'
145 BLANKLINE['cwiki'] = '\n'
146
147
148 INLINE_TAGS_SUBST['cwiki'] = {
149
150 'math': r'\g<begin>{{{\g<subst>}}}\g<end>',
151 'math2': r'\g<begin>\g<puretext>\g<end>',
152 'emphasize': r'\g<begin>//\g<subst>//\g<end>',
153 'bold': r'\g<begin>**\g<subst>**\g<end>',
154 'verbatim': r'\g<begin>{{{\g<subst>}}}\g<end>',
155 'linkURL': r'\g<begin>[[\g<url>|\g<link>]]\g<end>',
156 'linkURL2': r'[[\g<url>|\g<link>]]',
157 'linkURL3': r'[[\g<url>|\g<link>]]',
158 'linkURL2v': r'[[\g<url>|{{{\g<link>}}}]]',
159 'linkURL3v': r'[[\g<url>|{{{\g<link>}}}]]',
160 'plainURL': r'[[\g<url>]]',
161 'chapter': '\n\n\n' + r'= \g<subst> =\n',
162 'section': '\n\n\n' + r'= \g<subst> =\n',
163 'subsection': '\n\n' + r'== \g<subst> ==\n',
164 'subsubsection': '\n' + r'=== \g<subst> ===\n',
165
166
167
168 'paragraph': r'//\g<subst>// ',
169 'title': r'#summary \g<subst>\n<wiki:toc max_depth="2" />',
170 'date': r'=== \g<subst> ===',
171 'author': cwiki_author,
172
173 'figure': cwiki_figure,
174 'movie': default_movie,
175 'comment': '<wiki:comment> %s </wiki:comment>',
176 'abstract': r'\n//\g<type>.// \g<text>\g<rest>',
177 }
178
179 CODE['cwiki'] = cwiki_code
180
181
182 TABLE['cwiki'] = cwiki_table
183
184
185 LIST['cwiki'] = {
186 'itemize': {'begin': '\n', 'item': '*', 'end': '\n\n'},
187 'enumerate': {'begin': '\n', 'item': '#', 'end': '\n\n'},
188 'description': {'begin': '\n', 'item': '* %s ', 'end': '\n\n'},
189 'separator': '\n'}
190
191
192
193
194
195
196
197 ARGLIST['cwiki'] = {
198 'parameter': '*argument*',
199 'keyword': '*keyword argument*',
200 'return': '*return value(s)*',
201 'instance variable': '*instance variable*',
202 'class variable': '*class variable*',
203 'module variable': '*module variable*',
204 }
205
206 FIGURE_EXT['cwiki'] = ('.png', '.gif', '.jpg', '.jpeg')
207 CROSS_REFS['cwiki'] = cwiki_ref_and_label
208 from plaintext import plain_index_bib
209 EXERCISE['cwiki'] = plain_exercise
210 INDEX_BIB['cwiki'] = plain_index_bib
211
212
213 INTRO['cwiki'] = ''
214
215