paul@0 | 1 | #!/usr/bin/env python |
paul@0 | 2 | |
paul@0 | 3 | """ |
paul@0 | 4 | Moin wiki format parser. |
paul@0 | 5 | |
paul@316 | 6 | Copyright (C) 2017, 2018, 2019, 2020, 2022 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@91 | 22 | # Document transformations. |
paul@91 | 23 | |
paul@89 | 24 | from moinformat.macros import get_macro |
paul@91 | 25 | |
paul@91 | 26 | # Parser functionality and pattern definition. |
paul@91 | 27 | |
paul@122 | 28 | from moinformat.parsers.common import ParserBase, get_patterns, choice, \ |
paul@83 | 29 | excl, expect, group, optional, recur, \ |
paul@83 | 30 | repeat |
paul@91 | 31 | |
paul@91 | 32 | # Serialisation. |
paul@91 | 33 | |
paul@28 | 34 | from moinformat.serialisers import serialise |
paul@91 | 35 | |
paul@91 | 36 | # Document tree nodes. |
paul@91 | 37 | |
paul@151 | 38 | from moinformat.tree.moin import Anchor, Break, Comment, DefItem, DefTerm, \ |
paul@151 | 39 | Directive, FontStyle, Heading, Larger, \ |
paul@167 | 40 | LineBreak, Link, LinkLabel, LinkParameter, \ |
paul@316 | 41 | List, ListItem, Macro, Monospace, \ |
paul@316 | 42 | NonBreakingSpace, Region, Rule, Smaller, \ |
paul@316 | 43 | Strikethrough, Subscript, Superscript, Table, \ |
paul@316 | 44 | TableAttr, TableAttrs, TableCell, TableRow, \ |
paul@316 | 45 | Text, Transclusion, Underline, Verbatim |
paul@32 | 46 | |
paul@222 | 47 | # Link parsing. |
paul@222 | 48 | |
paul@222 | 49 | from moinformat.utils.links import parse_link_target |
paul@222 | 50 | |
paul@55 | 51 | join = "".join |
paul@55 | 52 | |
paul@42 | 53 | class MoinParser(ParserBase): |
paul@2 | 54 | |
paul@32 | 55 | "A wiki region parser." |
paul@2 | 56 | |
paul@301 | 57 | formats = ["moin", "wiki"] |
paul@109 | 58 | |
paul@165 | 59 | def __init__(self, metadata, parsers=None, root=None): |
paul@2 | 60 | |
paul@2 | 61 | """ |
paul@165 | 62 | Initialise the parser with the given 'metadata' and optional 'parsers'. |
paul@165 | 63 | An optional 'root' indicates the document-level parser. |
paul@2 | 64 | """ |
paul@2 | 65 | |
paul@165 | 66 | ParserBase.__init__(self, metadata, parsers, root) |
paul@87 | 67 | |
paul@91 | 68 | # Record certain node occurrences for later evaluation. |
paul@87 | 69 | |
paul@87 | 70 | self.macros = [] |
paul@2 | 71 | |
paul@128 | 72 | # Record headings for identifier disambiguation. |
paul@128 | 73 | |
paul@128 | 74 | self.headings = [] |
paul@128 | 75 | |
paul@222 | 76 | # Record link targets for resource identification. |
paul@222 | 77 | |
paul@222 | 78 | self.link_targets = [] |
paul@222 | 79 | |
paul@33 | 80 | # Principal parser methods. |
paul@33 | 81 | |
paul@32 | 82 | def parse(self, s): |
paul@1 | 83 | |
paul@31 | 84 | """ |
paul@31 | 85 | Parse page text 's'. Pages consist of regions delimited by markers. |
paul@31 | 86 | """ |
paul@1 | 87 | |
paul@37 | 88 | self.items = self.get_items(s) |
paul@52 | 89 | self.region = Region([], type="moin") |
paul@2 | 90 | |
paul@151 | 91 | # Parse page header and directives. |
paul@31 | 92 | |
paul@37 | 93 | self.parse_region_header(self.region) |
paul@151 | 94 | self.parse_region_directives(self.region) |
paul@31 | 95 | |
paul@37 | 96 | # Handle pages directly with this parser. Pages do not need to use an |
paul@37 | 97 | # explicit format indicator. |
paul@37 | 98 | |
paul@37 | 99 | if not self.region.type: |
paul@37 | 100 | self.parse_region_content(self.items, self.region) |
paul@37 | 101 | |
paul@32 | 102 | # Otherwise, test the type and find an appropriate parser. |
paul@2 | 103 | |
paul@31 | 104 | else: |
paul@37 | 105 | self.parse_region_type(self.region) |
paul@0 | 106 | |
paul@128 | 107 | # Assign heading identifiers. |
paul@128 | 108 | |
paul@128 | 109 | self.identify_headings() |
paul@128 | 110 | |
paul@37 | 111 | return self.region |
paul@36 | 112 | |
paul@0 | 113 | |
paul@36 | 114 | |
paul@89 | 115 | # Macro evaluation. |
paul@89 | 116 | |
paul@89 | 117 | def evaluate_macros(self): |
paul@89 | 118 | |
paul@89 | 119 | "Evaluate the macro nodes in the document." |
paul@89 | 120 | |
paul@89 | 121 | for node in self.macros: |
paul@89 | 122 | |
paul@89 | 123 | # Obtain a class for the named macro. |
paul@89 | 124 | |
paul@89 | 125 | macro_cls = get_macro(node.name) |
paul@89 | 126 | if not macro_cls: |
paul@89 | 127 | continue |
paul@89 | 128 | |
paul@89 | 129 | # Instantiate the class and evaluate the macro. |
paul@89 | 130 | |
paul@224 | 131 | macro = macro_cls(node, self.region, self.metadata) |
paul@89 | 132 | macro.evaluate() |
paul@89 | 133 | |
paul@199 | 134 | # Metadata extraction. |
paul@199 | 135 | |
paul@199 | 136 | def update_metadata(self, metadata): |
paul@199 | 137 | |
paul@199 | 138 | "Update 'metadata' for the document." |
paul@199 | 139 | |
paul@199 | 140 | if self.headings: |
paul@199 | 141 | metadata.set("title", self.headings[0].text_content()) |
paul@238 | 142 | else: |
paul@238 | 143 | metadata.set("title", self.metadata.get("pagename")) |
paul@199 | 144 | |
paul@128 | 145 | # Heading disambiguation. |
paul@128 | 146 | |
paul@128 | 147 | def identify_headings(self): |
paul@128 | 148 | |
paul@128 | 149 | "Assign identifiers to headings based on their textual content." |
paul@128 | 150 | |
paul@128 | 151 | d = {} |
paul@128 | 152 | |
paul@128 | 153 | for heading in self.headings: |
paul@128 | 154 | text = heading.text_content() |
paul@128 | 155 | |
paul@128 | 156 | if not d.has_key(text): |
paul@128 | 157 | d[text] = 0 |
paul@128 | 158 | heading.identifier = text |
paul@128 | 159 | else: |
paul@128 | 160 | d[text] += 1 |
paul@128 | 161 | heading.identifier = "%s-%d" % (text, d[text]) |
paul@128 | 162 | |
paul@89 | 163 | |
paul@89 | 164 | |
paul@165 | 165 | # Conversion back to text. |
paul@165 | 166 | |
paul@165 | 167 | def get_serialiser(self): |
paul@165 | 168 | |
paul@165 | 169 | "Return metadata employing Moin as the output format." |
paul@165 | 170 | |
paul@165 | 171 | metadata = self.metadata.copy() |
paul@165 | 172 | metadata.set("link_format", None) |
paul@165 | 173 | metadata.set("output_context", "standalone") |
paul@165 | 174 | metadata.set("output_format", "moin") |
paul@165 | 175 | return metadata.get_serialiser() |
paul@165 | 176 | |
paul@165 | 177 | |
paul@165 | 178 | |
paul@31 | 179 | # Parser methods supporting different page features. |
paul@31 | 180 | |
paul@37 | 181 | def parse_attrname(self, attrs): |
paul@31 | 182 | |
paul@31 | 183 | "Handle an attribute name within 'attrs'." |
paul@8 | 184 | |
paul@55 | 185 | name = self.match_group("name") |
paul@31 | 186 | attr = TableAttr(name) |
paul@1 | 187 | |
paul@37 | 188 | preceding = self.read_until(["attrvalue"], False) |
paul@31 | 189 | if preceding == "": |
paul@55 | 190 | attr.quote = self.match_group("quote") |
paul@55 | 191 | attr.value = self.match_group("value") |
paul@25 | 192 | |
paul@31 | 193 | attrs.append(attr) |
paul@31 | 194 | |
paul@37 | 195 | def parse_break(self, region): |
paul@25 | 196 | |
paul@31 | 197 | "Handle a paragraph break within 'region'." |
paul@31 | 198 | |
paul@43 | 199 | self.add_node(region, Break()) |
paul@43 | 200 | self.new_block(region) |
paul@31 | 201 | |
paul@151 | 202 | def parse_comment(self, region): |
paul@151 | 203 | |
paul@151 | 204 | "Handle a comment within 'region'." |
paul@151 | 205 | |
paul@151 | 206 | comment = self.match_group("comment") |
paul@151 | 207 | extra = self.match_group("extra") |
paul@151 | 208 | self.add_node(region, Comment(comment, extra)) |
paul@151 | 209 | self.new_block(region) |
paul@151 | 210 | |
paul@37 | 211 | def parse_defitem(self, region, extra=""): |
paul@25 | 212 | |
paul@31 | 213 | "Handle a definition item within 'region'." |
paul@25 | 214 | |
paul@55 | 215 | pad = self.match_group("pad") |
paul@31 | 216 | item = DefItem([], pad, extra) |
paul@123 | 217 | self.parse_region_details(item, self.listitem_pattern_names) |
paul@43 | 218 | self.add_node(region, item) |
paul@43 | 219 | self.new_block(region) |
paul@8 | 220 | |
paul@37 | 221 | def parse_defterm(self, region): |
paul@31 | 222 | |
paul@31 | 223 | "Handle a definition term within 'region'." |
paul@7 | 224 | |
paul@55 | 225 | pad = self.match_group("pad") |
paul@31 | 226 | term = DefTerm([], pad) |
paul@255 | 227 | self.parse_region_details(term, ["deftermend", "deftermsep"] + self.inline_pattern_names) |
paul@43 | 228 | self.add_node(region, term) |
paul@122 | 229 | |
paul@54 | 230 | if self.matching_pattern() == "deftermsep": |
paul@37 | 231 | self.parse_defitem(region) |
paul@16 | 232 | |
paul@122 | 233 | # Add padding from the separator to the term, there being no item. |
paul@122 | 234 | |
paul@122 | 235 | else: |
paul@122 | 236 | term.extra = self.match_group("pad") |
paul@122 | 237 | |
paul@37 | 238 | def parse_defterm_empty(self, region): |
paul@31 | 239 | |
paul@31 | 240 | "Handle an empty definition term within 'region'." |
paul@16 | 241 | |
paul@55 | 242 | extra = self.match_group("pad") |
paul@37 | 243 | self.parse_region_details(region, ["deftermsep"]) |
paul@37 | 244 | self.parse_defitem(region, extra) |
paul@16 | 245 | |
paul@151 | 246 | def parse_directive(self, region): |
paul@151 | 247 | |
paul@151 | 248 | "Handle a processing directive within 'region'." |
paul@151 | 249 | |
paul@151 | 250 | directive = self.match_group("directive") |
paul@151 | 251 | extra = self.match_group("extra") |
paul@151 | 252 | self.add_node(region, Directive(directive, extra)) |
paul@151 | 253 | self.new_block(region) |
paul@151 | 254 | |
paul@37 | 255 | def parse_fontstyle(self, region): |
paul@31 | 256 | |
paul@31 | 257 | "Handle emphasis and strong styles." |
paul@16 | 258 | |
paul@55 | 259 | n = len(self.match_group("style")) |
paul@31 | 260 | |
paul@31 | 261 | # Handle endings. |
paul@16 | 262 | |
paul@31 | 263 | if isinstance(region, FontStyle): |
paul@31 | 264 | emphasis = n in (2, 4, 5) |
paul@31 | 265 | strong = n in (3, 5, 6) |
paul@31 | 266 | active = True |
paul@16 | 267 | |
paul@31 | 268 | if region.emphasis and emphasis: |
paul@31 | 269 | active = region.close_emphasis() |
paul@31 | 270 | n -= 2 |
paul@31 | 271 | if region.strong and strong: |
paul@31 | 272 | active = region.close_strong() |
paul@31 | 273 | n -= 3 |
paul@18 | 274 | |
paul@31 | 275 | if not active: |
paul@31 | 276 | if n: |
paul@37 | 277 | self.items.rewind(n) |
paul@31 | 278 | raise StopIteration |
paul@18 | 279 | |
paul@31 | 280 | elif not n: |
paul@31 | 281 | return |
paul@18 | 282 | |
paul@31 | 283 | # Handle new styles. |
paul@31 | 284 | |
paul@18 | 285 | emphasis = n in (2, 4, 5) |
paul@18 | 286 | strong = n in (3, 5, 6) |
paul@31 | 287 | double = n in (4, 6) |
paul@31 | 288 | |
paul@31 | 289 | span = FontStyle([], emphasis, strong) |
paul@31 | 290 | if not double: |
paul@37 | 291 | self.parse_region_details(span, self.inline_pattern_names) |
paul@31 | 292 | region.append_inline(span) |
paul@31 | 293 | |
paul@37 | 294 | def parse_halign(self, attrs): |
paul@31 | 295 | |
paul@31 | 296 | "Handle horizontal alignment within 'attrs'." |
paul@31 | 297 | |
paul@55 | 298 | value = self.match_group("value") |
paul@202 | 299 | attr = TableAttr("align", value == "(" and "left" or value == ")" and "right" or "center", True) |
paul@31 | 300 | attrs.append(attr) |
paul@31 | 301 | |
paul@37 | 302 | def parse_heading(self, region): |
paul@17 | 303 | |
paul@31 | 304 | "Handle a heading." |
paul@18 | 305 | |
paul@55 | 306 | start_extra = self.match_group("extra") |
paul@55 | 307 | level = len(self.match_group("level")) |
paul@55 | 308 | start_pad = self.match_group("pad") |
paul@31 | 309 | heading = Heading([], level, start_extra, start_pad) |
paul@37 | 310 | self.parse_region_details(heading, ["headingend"] + self.inline_pattern_names) |
paul@43 | 311 | self.add_node(region, heading) |
paul@43 | 312 | self.new_block(region) |
paul@31 | 313 | |
paul@128 | 314 | # Record the heading for later processing. |
paul@128 | 315 | |
paul@128 | 316 | self.root.headings.append(heading) |
paul@128 | 317 | |
paul@37 | 318 | def parse_heading_end(self, heading): |
paul@31 | 319 | |
paul@31 | 320 | "Handle the end of a heading." |
paul@31 | 321 | |
paul@55 | 322 | level = len(self.match_group("level")) |
paul@31 | 323 | if heading.level == level: |
paul@55 | 324 | heading.end_pad = self.match_group("pad") |
paul@55 | 325 | heading.end_extra = self.match_group("extra") |
paul@18 | 326 | raise StopIteration |
paul@17 | 327 | |
paul@43 | 328 | def parse_list(self, item): |
paul@43 | 329 | |
paul@43 | 330 | "Create a list, starting with 'item'." |
paul@43 | 331 | |
paul@229 | 332 | list = List([item]) |
paul@43 | 333 | self.parse_region_details(list, self.list_pattern_names, True) |
paul@43 | 334 | return list |
paul@43 | 335 | |
paul@37 | 336 | def parse_listitem(self, region): |
paul@31 | 337 | |
paul@31 | 338 | "Handle a list item marker within 'region'." |
paul@31 | 339 | |
paul@55 | 340 | indent = len(self.match_group("indent")) |
paul@55 | 341 | marker = self.match_group("marker") |
paul@55 | 342 | num = self.match_group("num") |
paul@55 | 343 | space = self.match_group("pad") |
paul@43 | 344 | |
paul@45 | 345 | last = region.node(-1) |
paul@45 | 346 | |
paul@51 | 347 | new_list = not isinstance(last, (List, ListItem)) |
paul@51 | 348 | same_indent = not new_list and indent == last.indent |
paul@51 | 349 | new_marker = not new_list and last.marker != marker and same_indent |
paul@51 | 350 | new_num = not new_list and num is not None and last.num != num and same_indent |
paul@51 | 351 | |
paul@51 | 352 | # If the marker or number changes at the same indent, or if the indent |
paul@49 | 353 | # is smaller, queue the item and end the list. |
paul@45 | 354 | |
paul@51 | 355 | # Note that Moin format does not seek to support item renumbering, |
paul@51 | 356 | # instead starting new lists on number changes. |
paul@51 | 357 | |
paul@51 | 358 | if not new_list and (new_marker or new_num or indent < last.indent): |
paul@45 | 359 | self.queue_match() |
paul@45 | 360 | self.end_region(region) |
paul@45 | 361 | |
paul@45 | 362 | # Obtain a list item and populate it. |
paul@45 | 363 | |
paul@51 | 364 | item = ListItem([], indent, marker, space, num) |
paul@37 | 365 | self.parse_region_details(item, self.listitem_pattern_names) |
paul@43 | 366 | |
paul@49 | 367 | # Start a new list if not preceded by a list item, adding a trailing |
paul@49 | 368 | # block for new elements. |
paul@43 | 369 | |
paul@49 | 370 | if new_list: |
paul@49 | 371 | item = self.parse_list(item) |
paul@45 | 372 | self.add_node(region, item) |
paul@49 | 373 | self.new_block(region) |
paul@43 | 374 | |
paul@49 | 375 | # Add a nested list to the last item. |
paul@49 | 376 | |
paul@49 | 377 | elif indent > last.indent: |
paul@49 | 378 | item = self.parse_list(item) |
paul@49 | 379 | self.add_node(last, item) |
paul@43 | 380 | |
paul@45 | 381 | # Add the item to the current list. |
paul@43 | 382 | |
paul@45 | 383 | else: |
paul@45 | 384 | self.add_node(region, item) |
paul@31 | 385 | |
paul@37 | 386 | def parse_rule(self, region): |
paul@31 | 387 | |
paul@31 | 388 | "Handle a horizontal rule within 'region'." |
paul@31 | 389 | |
paul@267 | 390 | height = len(self.match_group("rule")) - 4 |
paul@267 | 391 | rule = Rule(height) |
paul@43 | 392 | self.add_node(region, rule) |
paul@43 | 393 | self.new_block(region) |
paul@31 | 394 | |
paul@37 | 395 | def parse_section(self, region): |
paul@31 | 396 | |
paul@31 | 397 | "Handle the start of a new section within 'region'." |
paul@31 | 398 | |
paul@31 | 399 | # Parse the section and start a new block after the section. |
paul@31 | 400 | |
paul@55 | 401 | indent = len(self.match_group("indent")) |
paul@55 | 402 | level = len(self.match_group("level")) |
paul@67 | 403 | |
paul@67 | 404 | section = self.parse_region(level, indent, "inline") |
paul@67 | 405 | |
paul@67 | 406 | # If the section is inline, treat it like any other inline element. |
paul@67 | 407 | |
paul@67 | 408 | if section.type == "inline": |
paul@67 | 409 | region.append_inline(section) |
paul@67 | 410 | |
paul@67 | 411 | # Otherwise, add it as a new block element. |
paul@67 | 412 | |
paul@67 | 413 | else: |
paul@67 | 414 | self.add_node(region, section) |
paul@67 | 415 | if region.allow_blocks: |
paul@67 | 416 | self.new_block(region) |
paul@31 | 417 | |
paul@37 | 418 | def parse_table_attrs(self, cell): |
paul@31 | 419 | |
paul@31 | 420 | "Handle the start of table attributes within 'cell'." |
paul@31 | 421 | |
paul@31 | 422 | attrs = TableAttrs([]) |
paul@102 | 423 | self.parse_region_details(attrs, self.table_attr_pattern_names) |
paul@31 | 424 | |
paul@291 | 425 | # If no end marker was found, consider that the text was not table |
paul@291 | 426 | # attributes at all. |
paul@291 | 427 | |
paul@291 | 428 | if attrs.incomplete: |
paul@291 | 429 | cell.append_inline(Text(serialise(attrs, self.get_serialiser()))) |
paul@291 | 430 | if attrs.found_cell: |
paul@291 | 431 | self.end_region(cell) |
paul@291 | 432 | return |
paul@291 | 433 | |
paul@31 | 434 | # Test the validity of the attributes. |
paul@31 | 435 | |
paul@31 | 436 | last = None |
paul@31 | 437 | |
paul@31 | 438 | for node in attrs.nodes: |
paul@31 | 439 | |
paul@31 | 440 | # Text separator nodes must be whitespace. |
paul@31 | 441 | |
paul@31 | 442 | if isinstance(node, Text): |
paul@31 | 443 | if node.s.strip(): |
paul@31 | 444 | break |
paul@31 | 445 | |
paul@31 | 446 | # Named attributes must be preceded by space if not the first. |
paul@31 | 447 | |
paul@31 | 448 | elif last and not node.concise and not isinstance(last, Text): |
paul@31 | 449 | break |
paul@31 | 450 | |
paul@31 | 451 | last = node |
paul@31 | 452 | |
paul@31 | 453 | # All nodes were valid: preserve the collection. |
paul@31 | 454 | |
paul@31 | 455 | else: |
paul@67 | 456 | # Add the attributes as a node, also recording their presence. |
paul@67 | 457 | |
paul@31 | 458 | cell.attrs = attrs |
paul@308 | 459 | self.add_node(cell, attrs) |
paul@18 | 460 | return |
paul@18 | 461 | |
paul@31 | 462 | # Invalid nodes were found: serialise the attributes as text. |
paul@18 | 463 | |
paul@165 | 464 | cell.append_inline(Text(serialise(attrs, self.get_serialiser()))) |
paul@25 | 465 | |
paul@37 | 466 | def parse_table_row(self, region): |
paul@9 | 467 | |
paul@31 | 468 | "Handle the start of a table row within 'region'." |
paul@9 | 469 | |
paul@36 | 470 | # Identify any active table. |
paul@36 | 471 | |
paul@36 | 472 | table = region.node(-2) |
paul@36 | 473 | block = region.node(-1) |
paul@36 | 474 | |
paul@36 | 475 | if not (isinstance(table, Table) and block.empty()): |
paul@36 | 476 | new_table = table = Table([]) |
paul@36 | 477 | else: |
paul@36 | 478 | new_table = None |
paul@36 | 479 | |
paul@31 | 480 | row = TableRow([]) |
paul@9 | 481 | |
paul@31 | 482 | while True: |
paul@31 | 483 | cell = TableCell([]) |
paul@102 | 484 | self.parse_region_details(cell, self.table_row_pattern_names) |
paul@9 | 485 | |
paul@31 | 486 | # Handle the end of the row. |
paul@12 | 487 | |
paul@54 | 488 | if self.matching_pattern() == "tableend": |
paul@55 | 489 | trailing = self.match_group("extra") |
paul@2 | 490 | |
paul@31 | 491 | # If the cell was started but not finished, convert the row into text. |
paul@2 | 492 | |
paul@31 | 493 | if not row.nodes or not cell.empty(): |
paul@165 | 494 | |
paul@165 | 495 | # Convert the nodes back to text. |
paul@165 | 496 | |
paul@165 | 497 | serialiser = self.get_serialiser() |
paul@165 | 498 | |
paul@31 | 499 | for node in row.nodes: |
paul@165 | 500 | region.append_inline(Text(serialise(node, serialiser))) |
paul@165 | 501 | |
paul@165 | 502 | region.append_inline(Text(serialise(cell, serialiser) + trailing)) |
paul@17 | 503 | |
paul@43 | 504 | self.new_block(region) |
paul@31 | 505 | return |
paul@29 | 506 | |
paul@31 | 507 | # Append the final cell, if not empty. |
paul@29 | 508 | |
paul@31 | 509 | else: |
paul@31 | 510 | row.trailing = trailing |
paul@29 | 511 | |
paul@31 | 512 | if not cell.empty(): |
paul@31 | 513 | row.append(cell) |
paul@31 | 514 | break |
paul@24 | 515 | |
paul@31 | 516 | # A cell separator has been found. |
paul@24 | 517 | |
paul@31 | 518 | row.append(cell) |
paul@24 | 519 | |
paul@36 | 520 | # Add the row to the table and any new table to the region. |
paul@36 | 521 | |
paul@308 | 522 | self.add_node(table, row) |
paul@36 | 523 | if new_table: |
paul@43 | 524 | self.add_node(region, new_table) |
paul@36 | 525 | |
paul@43 | 526 | self.new_block(region) |
paul@24 | 527 | |
paul@37 | 528 | def parse_valign(self, attrs): |
paul@24 | 529 | |
paul@31 | 530 | "Handle vertical alignment within 'attrs'." |
paul@24 | 531 | |
paul@55 | 532 | value = self.match_group("value") |
paul@31 | 533 | attr = TableAttr("valign", value == "^" and "top" or "bottom", True) |
paul@31 | 534 | attrs.append(attr) |
paul@25 | 535 | |
paul@30 | 536 | |
paul@30 | 537 | |
paul@98 | 538 | def inline_patterns_for(self, name): |
paul@172 | 539 | |
paul@172 | 540 | "Return active patterns for the inline element having the given 'name'." |
paul@172 | 541 | |
paul@98 | 542 | names = self.inline_pattern_names[:] |
paul@98 | 543 | names[names.index(name)] = "%send" % name |
paul@98 | 544 | return names |
paul@98 | 545 | |
paul@98 | 546 | |
paul@98 | 547 | |
paul@31 | 548 | # Inline formatting handlers. |
paul@31 | 549 | |
paul@37 | 550 | def parse_inline(self, region, cls, pattern_name): |
paul@23 | 551 | |
paul@31 | 552 | "Handle an inline region." |
paul@31 | 553 | |
paul@31 | 554 | span = cls([]) |
paul@37 | 555 | self.parse_region_details(span, self.inline_patterns_for(pattern_name)) |
paul@31 | 556 | region.append_inline(span) |
paul@20 | 557 | |
paul@37 | 558 | def parse_larger(self, region): |
paul@37 | 559 | self.parse_inline(region, Larger, "larger") |
paul@31 | 560 | |
paul@37 | 561 | def parse_monospace(self, region): |
paul@64 | 562 | span = Monospace([]) |
paul@64 | 563 | self.parse_region_details(span, ["monospaceend"]) |
paul@64 | 564 | region.append_inline(span) |
paul@20 | 565 | |
paul@37 | 566 | def parse_smaller(self, region): |
paul@37 | 567 | self.parse_inline(region, Smaller, "smaller") |
paul@31 | 568 | |
paul@48 | 569 | def parse_strike(self, region): |
paul@48 | 570 | self.parse_inline(region, Strikethrough, "strike") |
paul@48 | 571 | |
paul@37 | 572 | def parse_sub(self, region): |
paul@37 | 573 | self.parse_inline(region, Subscript, "sub") |
paul@31 | 574 | |
paul@37 | 575 | def parse_super(self, region): |
paul@37 | 576 | self.parse_inline(region, Superscript, "super") |
paul@20 | 577 | |
paul@37 | 578 | def parse_underline(self, region): |
paul@37 | 579 | self.parse_inline(region, Underline, "underline") |
paul@31 | 580 | |
paul@167 | 581 | # Link formatting handlers. |
paul@167 | 582 | |
paul@167 | 583 | def _parse_link(self, region, cls, pattern_names): |
paul@167 | 584 | target = self.match_group("target") |
paul@167 | 585 | end = self.match_group("end") |
paul@167 | 586 | |
paul@222 | 587 | # Obtain an object for the link target. |
paul@222 | 588 | |
paul@222 | 589 | link_target = parse_link_target(target, self.metadata) |
paul@222 | 590 | |
paul@222 | 591 | # Obtain an object for the node. |
paul@222 | 592 | |
paul@222 | 593 | span = cls([], link_target) |
paul@167 | 594 | |
paul@167 | 595 | # Obtain the extra details. |
paul@167 | 596 | |
paul@167 | 597 | if not end: |
paul@167 | 598 | cls = LinkLabel |
paul@167 | 599 | |
paul@167 | 600 | # Introduce a label or parameter for each separated region. |
paul@167 | 601 | |
paul@167 | 602 | while True: |
paul@167 | 603 | param = cls([]) |
paul@167 | 604 | self.parse_region_details(param, pattern_names) |
paul@167 | 605 | span.append(param) |
paul@167 | 606 | |
paul@167 | 607 | if self.matching_pattern() != "linksep": |
paul@167 | 608 | break |
paul@167 | 609 | |
paul@167 | 610 | cls = LinkParameter |
paul@167 | 611 | |
paul@167 | 612 | region.append_inline(span) |
paul@167 | 613 | |
paul@222 | 614 | # Record the link target for later processing. |
paul@222 | 615 | |
paul@222 | 616 | self.root.link_targets.append(link_target) |
paul@222 | 617 | |
paul@167 | 618 | def parse_link(self, region): |
paul@167 | 619 | self._parse_link(region, Link, self.link_pattern_names) |
paul@167 | 620 | |
paul@167 | 621 | def parse_transclusion(self, region): |
paul@167 | 622 | self._parse_link(region, Transclusion, self.transclusion_pattern_names) |
paul@167 | 623 | |
paul@31 | 624 | |
paul@19 | 625 | |
paul@77 | 626 | # Complete inline pattern handlers. |
paul@77 | 627 | |
paul@116 | 628 | def parse_anchor(self, region): |
paul@116 | 629 | target = self.match_group("target") |
paul@116 | 630 | anchor = Anchor(target) |
paul@116 | 631 | region.append_inline(anchor) |
paul@116 | 632 | |
paul@106 | 633 | def parse_linebreak(self, region): |
paul@106 | 634 | region.append_inline(LineBreak()) |
paul@106 | 635 | |
paul@77 | 636 | def parse_macro(self, region): |
paul@77 | 637 | name = self.match_group("name") |
paul@77 | 638 | args = self.match_group("args") |
paul@77 | 639 | |
paul@77 | 640 | # Obtain the raw arguments. Moin usually leaves it to the macro to |
paul@77 | 641 | # interpret the individual arguments. |
paul@77 | 642 | |
paul@77 | 643 | arglist = args and args.split(",") or [] |
paul@162 | 644 | macro = Macro(name, arglist, region.append_point(), region) |
paul@77 | 645 | region.append_inline(macro) |
paul@77 | 646 | |
paul@87 | 647 | # Record the macro for later processing. |
paul@87 | 648 | |
paul@87 | 649 | self.root.macros.append(macro) |
paul@87 | 650 | |
paul@316 | 651 | def parse_nbsp(self, region): |
paul@316 | 652 | region.append_inline(NonBreakingSpace()) |
paul@316 | 653 | |
paul@169 | 654 | def parse_verbatim(self, region): |
paul@169 | 655 | text = self.match_group("verbatim") |
paul@169 | 656 | region.append_inline(Verbatim(text)) |
paul@169 | 657 | |
paul@77 | 658 | |
paul@77 | 659 | |
paul@31 | 660 | # Table attribute handlers. |
paul@31 | 661 | |
paul@37 | 662 | def parse_table_attr(self, attrs, pattern_name): |
paul@31 | 663 | |
paul@31 | 664 | "Handle a table attribute." |
paul@25 | 665 | |
paul@55 | 666 | attrs.append(TableAttr(pattern_name, self.match_group("value"), True)) |
paul@37 | 667 | |
paul@291 | 668 | def parse_colour(self, attrs): |
paul@291 | 669 | self.parse_table_attr(attrs, "bgcolor") |
paul@37 | 670 | |
paul@291 | 671 | def parse_colspan(self, attrs): |
paul@291 | 672 | self.parse_table_attr(attrs, "colspan") |
paul@291 | 673 | |
paul@291 | 674 | def parse_rowspan(self, attrs): |
paul@291 | 675 | self.parse_table_attr(attrs, "rowspan") |
paul@37 | 676 | |
paul@291 | 677 | def parse_width(self, attrs): |
paul@291 | 678 | self.parse_table_attr(attrs, "width") |
paul@37 | 679 | |
paul@291 | 680 | def parse_table_attrs_end(self, attrs): |
paul@291 | 681 | attrs.incomplete = False |
paul@291 | 682 | self.end_region(attrs) |
paul@291 | 683 | |
paul@291 | 684 | def parse_table_attrs_cell(self, attrs): |
paul@291 | 685 | attrs.found_cell = True |
paul@291 | 686 | self.end_region(attrs) |
paul@37 | 687 | |
paul@37 | 688 | |
paul@37 | 689 | |
paul@37 | 690 | # Regular expressions. |
paul@37 | 691 | |
paul@37 | 692 | syntax = { |
paul@37 | 693 | # Page regions: |
paul@55 | 694 | |
paul@55 | 695 | "regionstart" : join((group("indent", r"\N*"), # ws... (optional) |
paul@55 | 696 | group("level", repeat("[{]", 3)))), # {{{... |
paul@55 | 697 | |
paul@55 | 698 | "regionend" : join((r"\N*", # ws... (optional) |
paul@67 | 699 | group("feature", join(( |
paul@67 | 700 | group("level", repeat("[}]", 3)), # }}}... |
paul@151 | 701 | optional(group("extra", r"\n"))))))), # nl (optional) |
paul@151 | 702 | |
paul@151 | 703 | # Region header and directives: |
paul@55 | 704 | |
paul@55 | 705 | "header" : join(("#!", # #! |
paul@55 | 706 | group("args", ".*?"), "\n")), # text-excl-nl |
paul@25 | 707 | |
paul@151 | 708 | "directive" : join((r"^#", # # |
paul@151 | 709 | group("directive", r".*?$"), # rest of line |
paul@151 | 710 | optional(group("extra", r"\n")))), # nl (optional) |
paul@151 | 711 | |
paul@37 | 712 | # Region contents: |
paul@76 | 713 | |
paul@76 | 714 | # Line-oriented patterns support features which require their own |
paul@76 | 715 | # separate lines. |
paul@55 | 716 | |
paul@55 | 717 | "break" : r"^(\s*?)\n", # blank line |
paul@55 | 718 | |
paul@151 | 719 | "comment" : join((r"^##", # ## |
paul@151 | 720 | group("comment", r".*?$"), # rest of line |
paul@151 | 721 | optional(group("extra", r"\n")))), # nl (optional) |
paul@151 | 722 | |
paul@55 | 723 | "defterm" : join(("^", |
paul@55 | 724 | group("pad", r"\N+"), # ws... |
paul@55 | 725 | expect(".+?::"))), # text :: |
paul@55 | 726 | |
paul@55 | 727 | "defterm_empty" : join(("^", |
paul@55 | 728 | group("pad", r"\N+"), # ws... |
paul@122 | 729 | expect("::\s+"))), # :: ws... |
paul@55 | 730 | |
paul@55 | 731 | "heading" : join(("^", |
paul@55 | 732 | group("extra", r"\N*"), # ws... (optional) |
paul@55 | 733 | group("level", "=+"), # =... |
paul@55 | 734 | group("pad", r"\s+"), # ws... |
paul@55 | 735 | expect(join((r".*?\N+", # text |
paul@55 | 736 | recur("level"), # =... |
paul@55 | 737 | r"\N*$"))))), # ws... (optional) |
paul@55 | 738 | |
paul@55 | 739 | "listitem" : join(("^", |
paul@55 | 740 | group("indent", r"\N+"), # ws... |
paul@55 | 741 | group("marker", r"\*"), # list-marker |
paul@55 | 742 | group("pad", r"\s*"))), # ws... (optional) |
paul@55 | 743 | |
paul@55 | 744 | "listitem_num" : join(("^", |
paul@55 | 745 | group("indent", r"\N+"), # ws... |
paul@55 | 746 | group("marker", r"\d+\."), # decimal-marker |
paul@55 | 747 | optional(join(("#", group("num", r"\d+")))), # # num (optional) |
paul@55 | 748 | group("pad", r"\s+"))), # ws... |
paul@55 | 749 | |
paul@55 | 750 | "listitem_alpha": join(("^", |
paul@55 | 751 | group("indent", r"\N+"), # ws... |
paul@55 | 752 | group("marker", r"[aA]\."), # alpha-marker |
paul@55 | 753 | optional(join(("#", group("num", r"\d+")))), # # num (optional) |
paul@55 | 754 | group("pad", r"\s+"))), # ws... |
paul@55 | 755 | |
paul@55 | 756 | "listitem_roman": join(("^", |
paul@55 | 757 | group("indent", r"\N+"), # ws... |
paul@55 | 758 | group("marker", r"[iI]\."), # roman-marker |
paul@55 | 759 | optional(join(("#", group("num", r"\d+")))), # # num (optional) |
paul@55 | 760 | group("pad", r"\s+"))), # ws... |
paul@55 | 761 | |
paul@55 | 762 | "listitem_dot" : join(("^", |
paul@55 | 763 | group("indent", r"\N+"), # ws... |
paul@55 | 764 | group("marker", r"\."), # dot-marker |
paul@55 | 765 | group("pad", r"\s*"))), # ws... (optional) |
paul@55 | 766 | |
paul@55 | 767 | "tablerow" : r"^\|\|", # || |
paul@37 | 768 | |
paul@37 | 769 | # Region contents: |
paul@76 | 770 | |
paul@76 | 771 | # Inline patterns are for markup features that appear within blocks. |
paul@76 | 772 | # The patterns below start inline spans that can contain other markup |
paul@76 | 773 | # features. |
paul@55 | 774 | |
paul@55 | 775 | "fontstyle" : group("style", repeat("'", 2, 6)), # ''... |
paul@172 | 776 | |
paul@172 | 777 | # Trivial markup balancing is done below using the end features. |
paul@172 | 778 | |
paul@172 | 779 | "larger" : join((r"~\+", # ~+ |
paul@172 | 780 | expect(r"\P*?\+~"))), # ... +~ |
paul@172 | 781 | |
paul@172 | 782 | "monospace" : join((r"`", # ` |
paul@172 | 783 | expect(r"\P*?`"))), # ... ` |
paul@172 | 784 | |
paul@172 | 785 | "smaller" : join((r"~-", # ~- |
paul@172 | 786 | expect(r"\P*?-~"))), # ... -~ |
paul@172 | 787 | |
paul@172 | 788 | "strike" : join((r"--\(", # --( |
paul@172 | 789 | expect(r"\P*?\)--"))), # ... )-- |
paul@172 | 790 | |
paul@172 | 791 | "sub" : join((r",,", # ,, |
paul@172 | 792 | expect(r"\P*?,,"))), # ... ,, |
paul@172 | 793 | |
paul@172 | 794 | "super" : join((r"\^", # ^ |
paul@172 | 795 | expect(r"\P*?\^"))), # ... ^ |
paul@172 | 796 | |
paul@172 | 797 | "underline" : join((r"__", # __ |
paul@172 | 798 | expect(r"\P*?__"))), # ... __ |
paul@172 | 799 | |
paul@172 | 800 | # Rules are treated as inline but, unlike the above, appear without |
paul@172 | 801 | # contents. |
paul@172 | 802 | |
paul@55 | 803 | "rule" : group("rule", "-----*"), # ----... |
paul@25 | 804 | |
paul@167 | 805 | # Links and transclusions may start inline spans. |
paul@167 | 806 | |
paul@167 | 807 | "link" : join((r"\[\[", # [[ |
paul@252 | 808 | group("target", r"\P*?"), # ... |
paul@167 | 809 | choice((r"\|", # | |
paul@167 | 810 | group("end", r"]]"))))), # ]] |
paul@167 | 811 | |
paul@167 | 812 | "transclusion" : join((r"\{\{", # {{ |
paul@167 | 813 | excl(r"\{"), # not-{ |
paul@252 | 814 | group("target", r"\P*?"), # ... |
paul@167 | 815 | choice((r"\|", # | |
paul@167 | 816 | group("end", r"}}"))))), # }} |
paul@167 | 817 | |
paul@76 | 818 | # Complete inline patterns are for markup features that do not support |
paul@76 | 819 | # arbitrary content within them: |
paul@55 | 820 | |
paul@116 | 821 | "anchor" : join((r"\(\(", # (( |
paul@116 | 822 | group("target", ".*?"), # target |
paul@116 | 823 | r"\)\)")), # )) |
paul@116 | 824 | |
paul@106 | 825 | "linebreak" : r"\\\\", # \\ |
paul@106 | 826 | |
paul@77 | 827 | "macro" : join(("<<", # << |
paul@77 | 828 | group("name", "\w+?"), # digit-letter... |
paul@77 | 829 | optional(join((r"\(", # ( (optional) |
paul@77 | 830 | group("args", ".*?"), # not-)... |
paul@77 | 831 | r"\)"))), # ) (optional) |
paul@77 | 832 | ">>")), # >> |
paul@77 | 833 | |
paul@316 | 834 | "nbsp" : r"\\_", # \_ |
paul@316 | 835 | |
paul@169 | 836 | "verbatim" : join(("<<<", # <<< |
paul@250 | 837 | group("verbatim", r"\P*?"), # ... |
paul@169 | 838 | ">>>")), |
paul@169 | 839 | |
paul@76 | 840 | # Ending patterns for inline features: |
paul@55 | 841 | |
paul@55 | 842 | "largerend" : r"\+~", # +~ |
paul@167 | 843 | "linkend" : r"]]", # ]] |
paul@55 | 844 | "monospaceend" : r"`", # ` |
paul@55 | 845 | "smallerend" : r"-~", # -~ |
paul@55 | 846 | "strikeend" : r"\)--", # )-- |
paul@55 | 847 | "subend" : r",,", # ,, |
paul@55 | 848 | "superend" : r"\^", # ^ |
paul@167 | 849 | "transclusionend": r"}}", # }} |
paul@55 | 850 | "underlineend" : r"__", # __ |
paul@37 | 851 | |
paul@37 | 852 | # Heading contents: |
paul@55 | 853 | |
paul@55 | 854 | "headingend" : join((group("pad", r"\N+"), # ws... |
paul@55 | 855 | group("level", "=+"), # =... |
paul@63 | 856 | group("extra", r"\N*\n"))), # ws (optional) nl |
paul@37 | 857 | |
paul@167 | 858 | # Link/transclusion contents: |
paul@167 | 859 | |
paul@167 | 860 | "linksep" : r"\|", # | |
paul@167 | 861 | |
paul@37 | 862 | # List contents: |
paul@55 | 863 | |
paul@55 | 864 | "deftermend" : join(("::", group("pad", r"\s*?\n"))), # :: |
paul@55 | 865 | # ws... (optional) |
paul@55 | 866 | # nl |
paul@55 | 867 | |
paul@55 | 868 | "deftermsep" : join(("::", group("pad", r"\s+"))), # :: |
paul@122 | 869 | # ws... |
paul@55 | 870 | |
paul@122 | 871 | "listitemend" : join((r"^", # next line |
paul@148 | 872 | choice((expect(r"[^\s]"), # without indent |
paul@148 | 873 | expect(r"\Z"), # end of string |
paul@122 | 874 | expect(r"\N+\*"), # or with ws... list-marker |
paul@122 | 875 | expect(r"\N+\d\."), # or with ws... decimal-marker |
paul@122 | 876 | expect(r"\N+[aA]\."), # or with ws... alpha-marker |
paul@122 | 877 | expect(r"\N+[iI]\."), # or with ws... roman-marker |
paul@122 | 878 | expect(r"\N+\."), # or with ws... dot-marker |
paul@122 | 879 | expect(r"\N+.+?::\s"), # or with ws... text :: ws (next defterm) |
paul@122 | 880 | expect(r"\N+::\s"))))), # or with ws... :: ws (next defitem) |
paul@37 | 881 | |
paul@37 | 882 | # Table contents: |
paul@55 | 883 | |
paul@107 | 884 | "tableattrs" : join(("<", # lt |
paul@107 | 885 | excl("<"))), # not-lt |
paul@107 | 886 | |
paul@55 | 887 | "tablecell" : r"\|\|", # || |
paul@55 | 888 | |
paul@55 | 889 | "tableend" : join((group("extra", r"\s*?"), # ws... (optional) |
paul@55 | 890 | "^")), # next line |
paul@25 | 891 | |
paul@37 | 892 | # Table attributes: |
paul@55 | 893 | |
paul@55 | 894 | "tableattrsend" : r">", # > |
paul@55 | 895 | "halign" : group("value", "[(:)]"), # halign-marker |
paul@55 | 896 | "valign" : group("value", "[v^]"), # valign-marker |
paul@55 | 897 | "colour" : group("value", join(("\#", # # |
paul@205 | 898 | repeat("[0-9A-Fa-f]", 6, 6)))), # nnnnnn |
paul@55 | 899 | |
paul@55 | 900 | "colspan" : join(("-", # - |
paul@55 | 901 | group("value", "\d+"))), # n... |
paul@55 | 902 | |
paul@55 | 903 | "rowspan" : join((r"\|", # | |
paul@55 | 904 | group("value", "\d+"))), # n... |
paul@55 | 905 | |
paul@55 | 906 | "width" : group("value", "\d+%"), # n... % |
paul@55 | 907 | |
paul@55 | 908 | "attrname" : join((excl(r"[-\d]"), # not-dash-or-digit |
paul@55 | 909 | group("name", r"[-\w]+"))), # dash-digit-letter... |
paul@55 | 910 | |
paul@55 | 911 | "attrvalue" : join(("=", group("quote", r"\Q"), # quote |
paul@55 | 912 | group("value", ".*?"), # non-quote... (optional) |
paul@55 | 913 | recur("quote"))), # quote |
paul@291 | 914 | |
paul@291 | 915 | "bad_tablecell" : r"\|\|", # || |
paul@37 | 916 | } |
paul@37 | 917 | |
paul@37 | 918 | patterns = get_patterns(syntax) |
paul@37 | 919 | |
paul@37 | 920 | |
paul@37 | 921 | |
paul@76 | 922 | # Patterns available within certain markup features. |
paul@31 | 923 | |
paul@102 | 924 | table_attr_pattern_names = [ |
paul@37 | 925 | "attrname", "colour", "colspan", "halign", "rowspan", "tableattrsend", |
paul@291 | 926 | "valign", "width", |
paul@291 | 927 | "bad_tablecell" |
paul@37 | 928 | ] |
paul@37 | 929 | |
paul@167 | 930 | inline_without_links_pattern_names = [ |
paul@167 | 931 | "anchor", "fontstyle", "larger", "linebreak", "macro", |
paul@316 | 932 | "monospace", "nbsp", "regionstart", "smaller", "strike", "sub", "super", |
paul@169 | 933 | "underline", "verbatim" |
paul@37 | 934 | ] |
paul@37 | 935 | |
paul@167 | 936 | inline_pattern_names = inline_without_links_pattern_names + [ |
paul@167 | 937 | "link", "transclusion"] |
paul@167 | 938 | |
paul@167 | 939 | link_pattern_names = inline_without_links_pattern_names + [ |
paul@167 | 940 | "linkend", "linksep", "transclusion"] |
paul@167 | 941 | |
paul@43 | 942 | list_pattern_names = [ |
paul@43 | 943 | "listitem", "listitem_alpha", "listitem_dot", "listitem_num", |
paul@43 | 944 | "listitem_roman", |
paul@43 | 945 | ] |
paul@43 | 946 | |
paul@37 | 947 | listitem_pattern_names = inline_pattern_names + ["listitemend"] |
paul@37 | 948 | |
paul@57 | 949 | region_without_table_pattern_names = inline_pattern_names + list_pattern_names + [ |
paul@151 | 950 | "break", "comment", "heading", "defterm", "defterm_empty", |
paul@57 | 951 | "regionend", "rule", |
paul@37 | 952 | ] |
paul@37 | 953 | |
paul@102 | 954 | table_row_pattern_names = inline_pattern_names + [ |
paul@37 | 955 | "tableattrs", "tablecell", "tableend" |
paul@37 | 956 | ] |
paul@37 | 957 | |
paul@167 | 958 | transclusion_pattern_names = inline_without_links_pattern_names + [ |
paul@167 | 959 | "linksep", "transclusionend"] |
paul@167 | 960 | |
paul@98 | 961 | # The region pattern names are specifically used by the common parser |
paul@98 | 962 | # functionality. |
paul@98 | 963 | |
paul@98 | 964 | region_pattern_names = region_without_table_pattern_names + ["tablerow"] |
paul@25 | 965 | |
paul@30 | 966 | |
paul@30 | 967 | |
paul@32 | 968 | # Pattern handlers. |
paul@31 | 969 | |
paul@32 | 970 | end_region = ParserBase.end_region |
paul@98 | 971 | parse_section_end = ParserBase.parse_region_end |
paul@31 | 972 | |
paul@31 | 973 | handlers = { |
paul@31 | 974 | None : end_region, |
paul@116 | 975 | "anchor" : parse_anchor, |
paul@31 | 976 | "attrname" : parse_attrname, |
paul@31 | 977 | "break" : parse_break, |
paul@31 | 978 | "colour" : parse_colour, |
paul@31 | 979 | "colspan" : parse_colspan, |
paul@151 | 980 | "comment" : parse_comment, |
paul@31 | 981 | "defterm" : parse_defterm, |
paul@31 | 982 | "defterm_empty" : parse_defterm_empty, |
paul@31 | 983 | "deftermend" : end_region, |
paul@31 | 984 | "deftermsep" : end_region, |
paul@151 | 985 | "directive" : parse_directive, |
paul@31 | 986 | "fontstyle" : parse_fontstyle, |
paul@31 | 987 | "halign" : parse_halign, |
paul@31 | 988 | "heading" : parse_heading, |
paul@31 | 989 | "headingend" : parse_heading_end, |
paul@31 | 990 | "larger" : parse_larger, |
paul@31 | 991 | "largerend" : end_region, |
paul@106 | 992 | "linebreak" : parse_linebreak, |
paul@47 | 993 | "link" : parse_link, |
paul@167 | 994 | "linkend" : end_region, |
paul@167 | 995 | "linksep" : end_region, |
paul@77 | 996 | "macro" : parse_macro, |
paul@316 | 997 | "nbsp" : parse_nbsp, |
paul@31 | 998 | "listitemend" : end_region, |
paul@31 | 999 | "listitem" : parse_listitem, |
paul@31 | 1000 | "listitem_alpha" : parse_listitem, |
paul@31 | 1001 | "listitem_dot" : parse_listitem, |
paul@31 | 1002 | "listitem_num" : parse_listitem, |
paul@31 | 1003 | "listitem_roman" : parse_listitem, |
paul@31 | 1004 | "monospace" : parse_monospace, |
paul@31 | 1005 | "monospaceend" : end_region, |
paul@31 | 1006 | "regionstart" : parse_section, |
paul@31 | 1007 | "regionend" : parse_section_end, |
paul@31 | 1008 | "rowspan" : parse_rowspan, |
paul@31 | 1009 | "rule" : parse_rule, |
paul@31 | 1010 | "smaller" : parse_smaller, |
paul@31 | 1011 | "smallerend" : end_region, |
paul@48 | 1012 | "strike" : parse_strike, |
paul@48 | 1013 | "strikeend" : end_region, |
paul@31 | 1014 | "sub" : parse_sub, |
paul@31 | 1015 | "subend" : end_region, |
paul@31 | 1016 | "super" : parse_super, |
paul@31 | 1017 | "superend" : end_region, |
paul@31 | 1018 | "tableattrs" : parse_table_attrs, |
paul@291 | 1019 | "tableattrsend" : parse_table_attrs_end, |
paul@31 | 1020 | "tablerow" : parse_table_row, |
paul@31 | 1021 | "tablecell" : end_region, |
paul@31 | 1022 | "tableend" : end_region, |
paul@167 | 1023 | "transclusion" : parse_transclusion, |
paul@167 | 1024 | "transclusionend" : end_region, |
paul@31 | 1025 | "underline" : parse_underline, |
paul@31 | 1026 | "underlineend" : end_region, |
paul@291 | 1027 | "bad_tablecell" : parse_table_attrs_cell, |
paul@31 | 1028 | "valign" : parse_valign, |
paul@169 | 1029 | "verbatim" : parse_verbatim, |
paul@31 | 1030 | "width" : parse_width, |
paul@31 | 1031 | } |
paul@2 | 1032 | |
paul@42 | 1033 | parser = MoinParser |
paul@0 | 1034 | |
paul@0 | 1035 | # vim: tabstop=4 expandtab shiftwidth=4 |