paul@0 | 1 | #!/usr/bin/env python |
paul@0 | 2 | |
paul@0 | 3 | """ |
paul@0 | 4 | Moin wiki format parser. |
paul@0 | 5 | |
paul@11 | 6 | Copyright (C) 2017 Paul Boddie <paul@boddie.org.uk> |
paul@0 | 7 | |
paul@0 | 8 | This program is free software; you can redistribute it and/or modify it under |
paul@0 | 9 | the terms of the GNU General Public License as published by the Free Software |
paul@0 | 10 | Foundation; either version 3 of the License, or (at your option) any later |
paul@0 | 11 | version. |
paul@0 | 12 | |
paul@0 | 13 | This program is distributed in the hope that it will be useful, but WITHOUT |
paul@0 | 14 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
paul@0 | 15 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
paul@0 | 16 | details. |
paul@0 | 17 | |
paul@0 | 18 | You should have received a copy of the GNU General Public License along with |
paul@0 | 19 | this program. If not, see <http://www.gnu.org/licenses/>. |
paul@0 | 20 | """ |
paul@0 | 21 | |
paul@18 | 22 | from moinformat.tree import Block, Break, DefItem, DefTerm, FontStyle, Heading, \ |
paul@23 | 23 | Larger, ListItem, Monospace, Region, Rule, Smaller, \ |
paul@24 | 24 | Subscript, Superscript, TableCell, TableRow, Text, \ |
paul@24 | 25 | Underline |
paul@0 | 26 | import re |
paul@0 | 27 | |
paul@0 | 28 | # Regular expressions. |
paul@0 | 29 | |
paul@0 | 30 | syntax = { |
paul@0 | 31 | # Page regions: |
paul@13 | 32 | "regionstart" : r"((^\s*)([{]{3,}))", # {{{... |
paul@13 | 33 | "regionend" : r"^\s*([}]{3,})", # }}}... |
paul@13 | 34 | "header" : r"#!(.*?)\n", # #! char-excl-nl |
paul@0 | 35 | |
paul@0 | 36 | # Region contents: |
paul@13 | 37 | # Line-oriented patterns: |
paul@14 | 38 | # blank line |
paul@14 | 39 | "break" : r"^(\s*?)\n", |
paul@16 | 40 | # ws... expecting text :: |
paul@16 | 41 | "defterm" : r"^(\s+)(?=.+?::)", |
paul@16 | 42 | # ws... expecting :: ws... |
paul@16 | 43 | "defterm_empty" : r"^(\s+)(?=::\s+)", |
paul@14 | 44 | # [ws...] =... ws... expecting headingend |
paul@14 | 45 | "heading" : r"^(\s*)(?P<x>=+)(\s+)(?=.*?\s+(?P=x)\s*\n)", |
paul@16 | 46 | # ws... list-item [ws...] |
paul@14 | 47 | "listitem" : r"^(\s+)(\*)(\s*)", |
paul@16 | 48 | # ws... number-item ws... |
paul@14 | 49 | "listitem_num" : r"^(\s+)(\d+\.)(\s+)", |
paul@16 | 50 | # ws... alpha-item ws... |
paul@14 | 51 | "listitem_alpha": r"^(\s+)([aA]\.)(\s+)", |
paul@16 | 52 | # ws... roman-item ws... |
paul@14 | 53 | "listitem_roman": r"^(\s+)([iI]\.)(\s+)", |
paul@16 | 54 | # ws... dot-item [ws...] |
paul@14 | 55 | "listitem_dot" : r"^(\s+)(\.)(\s*)", |
paul@24 | 56 | # || |
paul@24 | 57 | "tablerow" : r"^\|\|", |
paul@13 | 58 | |
paul@13 | 59 | # Region contents: |
paul@13 | 60 | # Inline patterns: |
paul@18 | 61 | "fontstyle" : r"('{2,6})", |
paul@23 | 62 | "larger" : r"~\+", |
paul@18 | 63 | "monospace" : r"`", |
paul@13 | 64 | "rule" : r"(-----*)", # ----... |
paul@23 | 65 | "smaller" : r"~-", |
paul@20 | 66 | "sub" : r",,", |
paul@20 | 67 | "super" : r"\^", |
paul@19 | 68 | "underline" : r"__", |
paul@17 | 69 | |
paul@17 | 70 | # Inline contents: |
paul@23 | 71 | "largerend" : r"\+~", |
paul@18 | 72 | "monospaceend" : r"`", |
paul@23 | 73 | "smallerend" : r"-~", |
paul@20 | 74 | "subend" : r",,", |
paul@20 | 75 | "superend" : r"\^", |
paul@19 | 76 | "underlineend" : r"__", |
paul@13 | 77 | |
paul@13 | 78 | # Heading contents: |
paul@13 | 79 | "headingend" : r"(\s+)(=+)(\s*\n)", # ws... =... [ws...] nl |
paul@9 | 80 | |
paul@9 | 81 | # List contents: |
paul@16 | 82 | "deftermend" : r"::(\s*?\n)", |
paul@16 | 83 | "deftermsep" : r"::(\s+)", |
paul@13 | 84 | "listitemend" : r"^", # next line |
paul@24 | 85 | |
paul@24 | 86 | # Table contents: |
paul@24 | 87 | "tablecell" : r"\|\|", |
paul@24 | 88 | "tableend" : r"(\s*?)^", # [ws...] next line |
paul@0 | 89 | } |
paul@0 | 90 | |
paul@23 | 91 | # Define inline pattern details. |
paul@23 | 92 | |
paul@23 | 93 | inline_pattern_names = ["fontstyle", "larger", "monospace", "smaller", "sub", "super", "underline"] |
paul@23 | 94 | |
paul@23 | 95 | def inline_patterns_for(name): |
paul@23 | 96 | names = inline_pattern_names[:] |
paul@23 | 97 | names[names.index(name)] = "%send" % name |
paul@23 | 98 | return names |
paul@23 | 99 | |
paul@0 | 100 | # Define patterns for the regular expressions. |
paul@0 | 101 | |
paul@0 | 102 | patterns = {} |
paul@13 | 103 | for name, value in syntax.items(): |
paul@13 | 104 | patterns[name] = re.compile(value, re.UNICODE | re.MULTILINE) |
paul@0 | 105 | |
paul@0 | 106 | |
paul@0 | 107 | |
paul@2 | 108 | # Tokenising functions. |
paul@2 | 109 | |
paul@2 | 110 | class TokenStream: |
paul@2 | 111 | |
paul@2 | 112 | "A stream of tokens taken from a string." |
paul@2 | 113 | |
paul@2 | 114 | def __init__(self, s): |
paul@2 | 115 | self.s = s |
paul@2 | 116 | self.pos = 0 |
paul@2 | 117 | self.match = None |
paul@2 | 118 | self.matching = None |
paul@2 | 119 | |
paul@18 | 120 | def rewind(self, length): |
paul@18 | 121 | |
paul@18 | 122 | "Rewind in the string by 'length'." |
paul@18 | 123 | |
paul@18 | 124 | self.pos -= min(length, self.pos) |
paul@18 | 125 | |
paul@2 | 126 | def read_until(self, pattern_names, remaining=True): |
paul@2 | 127 | |
paul@2 | 128 | """ |
paul@2 | 129 | Find the first match for the given 'pattern_names'. Return the text |
paul@2 | 130 | preceding any match, the remaining text if no match was found, or None |
paul@2 | 131 | if no match was found and 'remaining' is given as a false value. |
paul@2 | 132 | """ |
paul@2 | 133 | |
paul@2 | 134 | first = None |
paul@2 | 135 | self.matching = None |
paul@2 | 136 | |
paul@2 | 137 | # Find the first matching pattern. |
paul@2 | 138 | |
paul@2 | 139 | for pattern_name in pattern_names: |
paul@2 | 140 | match = patterns[pattern_name].search(self.s, self.pos) |
paul@2 | 141 | if match: |
paul@2 | 142 | start, end = match.span() |
paul@2 | 143 | if self.matching is None or start < first: |
paul@2 | 144 | first = start |
paul@2 | 145 | self.matching = pattern_name |
paul@2 | 146 | self.match = match |
paul@2 | 147 | |
paul@2 | 148 | if self.matching is None: |
paul@2 | 149 | if remaining: |
paul@2 | 150 | return self.s[self.pos:] |
paul@2 | 151 | else: |
paul@2 | 152 | return None |
paul@2 | 153 | else: |
paul@2 | 154 | return self.s[self.pos:first] |
paul@2 | 155 | |
paul@10 | 156 | def read_match(self, group=1): |
paul@2 | 157 | |
paul@10 | 158 | """ |
paul@10 | 159 | Return the matched text, updating the position in the stream. If 'group' |
paul@10 | 160 | is specified, the indicated group in a match will be returned. |
paul@10 | 161 | Typically, group 1 should contain all pertinent data, but groups defined |
paul@10 | 162 | within group 1 can provide sections of the data. |
paul@10 | 163 | """ |
paul@2 | 164 | |
paul@2 | 165 | if self.match: |
paul@2 | 166 | _start, self.pos = self.match.span() |
paul@9 | 167 | try: |
paul@10 | 168 | return self.match.group(group) |
paul@9 | 169 | except IndexError: |
paul@9 | 170 | return "" |
paul@2 | 171 | else: |
paul@2 | 172 | self.pos = len(self.s) |
paul@2 | 173 | return None |
paul@2 | 174 | |
paul@2 | 175 | |
paul@2 | 176 | |
paul@0 | 177 | # Parser functions. |
paul@0 | 178 | |
paul@0 | 179 | def parse_page(s): |
paul@0 | 180 | |
paul@0 | 181 | """ |
paul@0 | 182 | Parse page text 's'. Pages consist of regions delimited by markers. |
paul@0 | 183 | """ |
paul@0 | 184 | |
paul@6 | 185 | return parse_region(TokenStream(s)) |
paul@1 | 186 | |
paul@10 | 187 | def parse_region(items, level=0, indent=0): |
paul@1 | 188 | |
paul@6 | 189 | """ |
paul@10 | 190 | Parse the data provided by 'items' to populate a region with the given |
paul@10 | 191 | 'level' at the given 'indent'. |
paul@6 | 192 | """ |
paul@0 | 193 | |
paul@10 | 194 | region = Region([], level, indent) |
paul@0 | 195 | |
paul@2 | 196 | # Parse section headers. |
paul@2 | 197 | |
paul@2 | 198 | parse_region_header(items, region) |
paul@2 | 199 | |
paul@8 | 200 | # Parse section body. |
paul@8 | 201 | |
paul@2 | 202 | if region.is_transparent(): |
paul@2 | 203 | parse_region_wiki(items, region) |
paul@2 | 204 | else: |
paul@2 | 205 | parse_region_opaque(items, region) |
paul@2 | 206 | |
paul@6 | 207 | return region |
paul@6 | 208 | |
paul@6 | 209 | def parse_region_header(items, region): |
paul@6 | 210 | |
paul@6 | 211 | """ |
paul@6 | 212 | Parse the region header from the 'items', setting it for the given 'region'. |
paul@6 | 213 | """ |
paul@6 | 214 | |
paul@6 | 215 | if items.read_until(["header"], False) == "": # None means no header |
paul@6 | 216 | region.type = items.read_match() |
paul@6 | 217 | |
paul@2 | 218 | def parse_region_wiki(items, region): |
paul@2 | 219 | |
paul@2 | 220 | "Parse the data provided by 'items' to populate a wiki 'region'." |
paul@0 | 221 | |
paul@8 | 222 | new_block(region) |
paul@20 | 223 | parse_region_details(items, region, inline_pattern_names + [ |
paul@16 | 224 | "break", "heading", |
paul@16 | 225 | "defterm", "defterm_empty", |
paul@16 | 226 | "listitem", "listitem_alpha", "listitem_dot", "listitem_num", |
paul@16 | 227 | "listitem_roman", |
paul@17 | 228 | "regionstart", "regionend", |
paul@17 | 229 | "rule", |
paul@24 | 230 | "tablerow", |
paul@18 | 231 | ]) |
paul@0 | 232 | |
paul@8 | 233 | def parse_region_opaque(items, region): |
paul@1 | 234 | |
paul@8 | 235 | "Parse the data provided by 'items' to populate an opaque 'region'." |
paul@8 | 236 | |
paul@8 | 237 | parse_region_details(items, region, ["regionend"]) |
paul@1 | 238 | |
paul@8 | 239 | def parse_region_details(items, region, pattern_names): |
paul@0 | 240 | |
paul@8 | 241 | "Parse 'items' within 'region' searching using 'pattern_names'." |
paul@0 | 242 | |
paul@8 | 243 | try: |
paul@8 | 244 | while True: |
paul@0 | 245 | |
paul@8 | 246 | # Obtain text before any marker or the end of the input. |
paul@2 | 247 | |
paul@8 | 248 | preceding = items.read_until(pattern_names) |
paul@8 | 249 | if preceding: |
paul@17 | 250 | region.append_inline(Text(preceding)) |
paul@2 | 251 | |
paul@8 | 252 | # End of input. |
paul@0 | 253 | |
paul@8 | 254 | if not items.matching: |
paul@8 | 255 | break |
paul@8 | 256 | |
paul@8 | 257 | # Obtain any feature. |
paul@2 | 258 | |
paul@8 | 259 | feature = items.read_match() |
paul@8 | 260 | handler = handlers.get(items.matching) |
paul@2 | 261 | |
paul@8 | 262 | # Handle each feature or add text to the region. |
paul@2 | 263 | |
paul@8 | 264 | if handler: |
paul@8 | 265 | handler(items, region) |
paul@8 | 266 | else: |
paul@17 | 267 | region.append_inline(Text(feature)) |
paul@2 | 268 | |
paul@8 | 269 | except StopIteration: |
paul@8 | 270 | pass |
paul@2 | 271 | |
paul@2 | 272 | region.normalise() |
paul@0 | 273 | |
paul@8 | 274 | def end_region(items, region): |
paul@7 | 275 | |
paul@8 | 276 | "End the parsing of 'region'." |
paul@7 | 277 | |
paul@8 | 278 | raise StopIteration |
paul@7 | 279 | |
paul@8 | 280 | def parse_break(items, region): |
paul@8 | 281 | |
paul@8 | 282 | "Handle a paragraph break within 'region'." |
paul@7 | 283 | |
paul@15 | 284 | region.add(Break()) |
paul@8 | 285 | new_block(region) |
paul@2 | 286 | |
paul@16 | 287 | def parse_defitem(items, region, extra=""): |
paul@16 | 288 | |
paul@16 | 289 | "Handle a definition item within 'region'." |
paul@16 | 290 | |
paul@16 | 291 | pad = items.read_match(1) |
paul@16 | 292 | item = DefItem([], pad, extra) |
paul@16 | 293 | parse_region_details(items, item, ["listitemend"]) |
paul@21 | 294 | region.add(item) |
paul@16 | 295 | new_block(region) |
paul@16 | 296 | |
paul@16 | 297 | def parse_defterm(items, region): |
paul@16 | 298 | |
paul@16 | 299 | "Handle a definition term within 'region'." |
paul@16 | 300 | |
paul@16 | 301 | pad = items.read_match(1) |
paul@16 | 302 | term = DefTerm([], pad) |
paul@16 | 303 | parse_region_details(items, term, ["deftermend", "deftermsep"]) |
paul@21 | 304 | region.add(term) |
paul@16 | 305 | if items.matching == "deftermsep": |
paul@16 | 306 | parse_defitem(items, region) |
paul@16 | 307 | |
paul@16 | 308 | def parse_defterm_empty(items, region): |
paul@16 | 309 | |
paul@16 | 310 | "Handle an empty definition term within 'region'." |
paul@16 | 311 | |
paul@16 | 312 | extra = items.read_match(1) |
paul@16 | 313 | parse_region_details(items, region, ["deftermsep"]) |
paul@16 | 314 | parse_defitem(items, region, extra) |
paul@16 | 315 | |
paul@18 | 316 | def parse_fontstyle(items, region): |
paul@18 | 317 | |
paul@18 | 318 | "Handle emphasis and strong styles." |
paul@18 | 319 | |
paul@18 | 320 | n = len(items.read_match(1)) |
paul@18 | 321 | |
paul@18 | 322 | # Handle endings. |
paul@18 | 323 | |
paul@18 | 324 | if isinstance(region, FontStyle): |
paul@18 | 325 | emphasis = n in (2, 4, 5) |
paul@18 | 326 | strong = n in (3, 5, 6) |
paul@18 | 327 | active = True |
paul@17 | 328 | |
paul@18 | 329 | if region.emphasis and emphasis: |
paul@18 | 330 | active = region.close_emphasis() |
paul@18 | 331 | n -= 2 |
paul@18 | 332 | if region.strong and strong: |
paul@18 | 333 | active = region.close_strong() |
paul@18 | 334 | n -= 3 |
paul@18 | 335 | |
paul@18 | 336 | if not active: |
paul@18 | 337 | if n: |
paul@18 | 338 | items.rewind(n) |
paul@18 | 339 | raise StopIteration |
paul@17 | 340 | |
paul@18 | 341 | elif not n: |
paul@18 | 342 | return |
paul@18 | 343 | |
paul@18 | 344 | # Handle new styles. |
paul@18 | 345 | |
paul@18 | 346 | emphasis = n in (2, 4, 5) |
paul@18 | 347 | strong = n in (3, 5, 6) |
paul@18 | 348 | double = n in (4, 6) |
paul@18 | 349 | |
paul@18 | 350 | span = FontStyle([], emphasis, strong) |
paul@18 | 351 | if not double: |
paul@20 | 352 | parse_region_details(items, span, inline_pattern_names) |
paul@17 | 353 | region.append_inline(span) |
paul@16 | 354 | |
paul@13 | 355 | def parse_heading(items, region): |
paul@13 | 356 | |
paul@13 | 357 | "Handle a heading." |
paul@9 | 358 | |
paul@13 | 359 | start_extra = items.read_match(1) |
paul@13 | 360 | level = len(items.read_match(2)) |
paul@13 | 361 | start_pad = items.read_match(3) |
paul@13 | 362 | heading = Heading([], level, start_extra, start_pad) |
paul@20 | 363 | parse_region_details(items, heading, ["headingend"] + inline_pattern_names) |
paul@21 | 364 | region.add(heading) |
paul@13 | 365 | new_block(region) |
paul@9 | 366 | |
paul@13 | 367 | def parse_heading_end(items, heading): |
paul@13 | 368 | |
paul@13 | 369 | "Handle the end of a heading." |
paul@13 | 370 | |
paul@13 | 371 | level = len(items.read_match(2)) |
paul@13 | 372 | if heading.level == level: |
paul@13 | 373 | heading.end_pad = items.read_match(1) |
paul@13 | 374 | heading.end_extra = items.read_match(3) |
paul@13 | 375 | raise StopIteration |
paul@9 | 376 | |
paul@9 | 377 | def parse_listitem(items, region): |
paul@9 | 378 | |
paul@9 | 379 | "Handle a list item marker within 'region'." |
paul@9 | 380 | |
paul@14 | 381 | indent = len(items.read_match(1)) |
paul@14 | 382 | marker = items.read_match(2) |
paul@14 | 383 | space = items.read_match(3) |
paul@14 | 384 | item = ListItem([], indent, marker, space) |
paul@9 | 385 | parse_region_details(items, item, ["listitemend"]) |
paul@21 | 386 | region.add(item) |
paul@9 | 387 | new_block(region) |
paul@9 | 388 | |
paul@12 | 389 | def parse_rule(items, region): |
paul@12 | 390 | |
paul@12 | 391 | "Handle a horizontal rule within 'region'." |
paul@12 | 392 | |
paul@12 | 393 | length = len(items.read_match(1)) |
paul@12 | 394 | rule = Rule(length) |
paul@21 | 395 | region.add(rule) |
paul@12 | 396 | new_block(region) |
paul@12 | 397 | |
paul@8 | 398 | def parse_section(items, region): |
paul@2 | 399 | |
paul@8 | 400 | "Handle the start of a new section within 'region'." |
paul@2 | 401 | |
paul@8 | 402 | # Parse the section and start a new block after the section. |
paul@2 | 403 | |
paul@10 | 404 | indent = len(items.read_match(2)) |
paul@10 | 405 | level = len(items.read_match(3)) |
paul@21 | 406 | region.add(parse_region(items, level, indent)) |
paul@8 | 407 | new_block(region) |
paul@2 | 408 | |
paul@8 | 409 | def parse_section_end(items, region): |
paul@2 | 410 | |
paul@8 | 411 | "Handle the end of a new section within 'region'." |
paul@1 | 412 | |
paul@8 | 413 | feature = items.read_match() |
paul@8 | 414 | if region.have_end(feature): |
paul@8 | 415 | raise StopIteration |
paul@8 | 416 | else: |
paul@17 | 417 | region.append_inline(Text(feature)) |
paul@17 | 418 | |
paul@24 | 419 | def parse_table_row(items, region): |
paul@24 | 420 | |
paul@24 | 421 | "Handle the start of a table row within 'region'." |
paul@24 | 422 | |
paul@24 | 423 | row = TableRow([]) |
paul@24 | 424 | |
paul@24 | 425 | while True: |
paul@24 | 426 | cell = TableCell([]) |
paul@24 | 427 | parse_region_details(items, cell, ["tablecell", "tableend"]) |
paul@24 | 428 | |
paul@24 | 429 | # Handle the end of the row. |
paul@24 | 430 | |
paul@24 | 431 | if items.matching == "tableend": |
paul@24 | 432 | trailing = items.read_match() |
paul@24 | 433 | |
paul@24 | 434 | # If the cell was started but not finished, convert the row into text. |
paul@24 | 435 | |
paul@24 | 436 | if not row.nodes or not cell.empty(): |
paul@24 | 437 | region.append_inline(Text("||")) |
paul@24 | 438 | |
paul@24 | 439 | # Convert all cells. |
paul@24 | 440 | |
paul@24 | 441 | for node in row.nodes: |
paul@24 | 442 | region.append_inline_many(node.nodes) |
paul@24 | 443 | region.append_inline(Text("||")) |
paul@24 | 444 | |
paul@24 | 445 | region.append_inline_many(cell.nodes) |
paul@24 | 446 | region.append_inline(Text(trailing)) |
paul@24 | 447 | |
paul@24 | 448 | new_block(region) |
paul@24 | 449 | return |
paul@24 | 450 | |
paul@24 | 451 | # Append the final cell, if not empty. |
paul@24 | 452 | |
paul@24 | 453 | else: |
paul@24 | 454 | row.trailing = trailing |
paul@24 | 455 | |
paul@24 | 456 | if not cell.empty(): |
paul@24 | 457 | row.append(cell) |
paul@24 | 458 | break |
paul@24 | 459 | |
paul@24 | 460 | row.append(cell) |
paul@24 | 461 | |
paul@24 | 462 | region.add(row) |
paul@24 | 463 | new_block(region) |
paul@24 | 464 | |
paul@23 | 465 | # Inline formatting handlers. |
paul@23 | 466 | |
paul@23 | 467 | def parse_inline(items, region, cls, pattern_name): |
paul@20 | 468 | |
paul@23 | 469 | "Handle an inline region." |
paul@20 | 470 | |
paul@23 | 471 | span = cls([]) |
paul@23 | 472 | parse_region_details(items, span, inline_patterns_for(pattern_name)) |
paul@20 | 473 | region.append_inline(span) |
paul@20 | 474 | |
paul@23 | 475 | parse_larger = lambda items, region: parse_inline(items, region, Larger, "larger") |
paul@23 | 476 | parse_monospace = lambda items, region: parse_inline(items, region, Monospace, "monospace") |
paul@23 | 477 | parse_smaller = lambda items, region: parse_inline(items, region, Smaller, "smaller") |
paul@23 | 478 | parse_sub = lambda items, region: parse_inline(items, region, Subscript, "sub") |
paul@23 | 479 | parse_super = lambda items, region: parse_inline(items, region, Superscript, "super") |
paul@23 | 480 | parse_underline = lambda items, region: parse_inline(items, region, Underline, "underline") |
paul@19 | 481 | |
paul@8 | 482 | # Pattern handlers. |
paul@2 | 483 | |
paul@8 | 484 | handlers = { |
paul@8 | 485 | None : end_region, |
paul@8 | 486 | "break" : parse_break, |
paul@16 | 487 | "defterm" : parse_defterm, |
paul@16 | 488 | "defterm_empty" : parse_defterm_empty, |
paul@17 | 489 | "deftermend" : end_region, |
paul@17 | 490 | "deftermsep" : end_region, |
paul@18 | 491 | "fontstyle" : parse_fontstyle, |
paul@13 | 492 | "heading" : parse_heading, |
paul@13 | 493 | "headingend" : parse_heading_end, |
paul@23 | 494 | "larger" : parse_larger, |
paul@23 | 495 | "largerend" : end_region, |
paul@17 | 496 | "listitemend" : end_region, |
paul@9 | 497 | "listitem" : parse_listitem, |
paul@14 | 498 | "listitem_alpha" : parse_listitem, |
paul@14 | 499 | "listitem_dot" : parse_listitem, |
paul@14 | 500 | "listitem_num" : parse_listitem, |
paul@14 | 501 | "listitem_roman" : parse_listitem, |
paul@18 | 502 | "monospace" : parse_monospace, |
paul@18 | 503 | "monospaceend" : end_region, |
paul@8 | 504 | "regionstart" : parse_section, |
paul@8 | 505 | "regionend" : parse_section_end, |
paul@12 | 506 | "rule" : parse_rule, |
paul@23 | 507 | "smaller" : parse_smaller, |
paul@23 | 508 | "smallerend" : end_region, |
paul@20 | 509 | "sub" : parse_sub, |
paul@20 | 510 | "subend" : end_region, |
paul@20 | 511 | "super" : parse_super, |
paul@20 | 512 | "superend" : end_region, |
paul@24 | 513 | "tablerow" : parse_table_row, |
paul@24 | 514 | "tablecell" : end_region, |
paul@24 | 515 | "tableend" : end_region, |
paul@19 | 516 | "underline" : parse_underline, |
paul@19 | 517 | "underlineend" : end_region, |
paul@8 | 518 | } |
paul@2 | 519 | |
paul@6 | 520 | def new_block(region): |
paul@6 | 521 | |
paul@6 | 522 | "Start a new block in 'region'." |
paul@0 | 523 | |
paul@6 | 524 | block = Block([]) |
paul@15 | 525 | region.add(block) |
paul@0 | 526 | |
paul@1 | 527 | |
paul@1 | 528 | |
paul@1 | 529 | # Top-level functions. |
paul@0 | 530 | |
paul@0 | 531 | parse = parse_page |
paul@0 | 532 | |
paul@0 | 533 | # vim: tabstop=4 expandtab shiftwidth=4 |