A Python parser for MediaWiki wikicode https://mwparserfromhell.readthedocs.io/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

47 lines
2.6 KiB

  1. name: empty
  2. label: sanity check that parsing an empty string yields nothing
  3. input: ""
  4. output: []
  5. ---
  6. name: template_argument_mix
  7. label: an ambiguous mix of templates and arguments
  8. input: "{{{{{{{{foo}}}}}}}}{{{{{{{bar}}baz}}}buz}}"
  9. output: [TemplateOpen(), ArgumentOpen(), ArgumentOpen(), Text(text="foo"), ArgumentClose(), ArgumentClose(), TemplateClose(), TemplateOpen(), ArgumentOpen(), TemplateOpen(), Text(text="bar"), TemplateClose(), Text(text="baz"), ArgumentClose(), Text(text="buz"), TemplateClose()]
  10. ---
  11. name: rich_heading
  12. label: a heading with templates/wikilinks in it
  13. input: "== Head{{ing}} [[with]] {{{funky|{{stuf}}}}} =="
  14. output: [HeadingStart(level=2), Text(text=" Head"), TemplateOpen(), Text(text="ing"), TemplateClose(), Text(text=" "), WikilinkOpen(), Text(text="with"), WikilinkClose(), Text(text=" "), ArgumentOpen(), Text(text="funky"), ArgumentSeparator(), TemplateOpen(), Text(text="stuf"), TemplateClose(), ArgumentClose(), Text(text=" "), HeadingEnd()]
  15. ---
  16. name: html_entity_with_template
  17. label: a HTML entity with a template embedded inside
  18. input: "&n{{bs}}p;"
  19. output: [Text(text="&n"), TemplateOpen(), Text(text="bs"), TemplateClose(), Text(text="p;")]
  20. ---
  21. name: html_entity_with_comment
  22. label: a HTML entity with a comment embedded inside
  23. input: "&n<!--foo-->bsp;"
  24. output: [Text(text="&n"), CommentStart(), Text(text="foo"), CommentEnd(), Text(text="bsp;")]
  25. ---
  26. name: wildcard
  27. label: a wildcard assortment of various things
  28. input: "{{{{{{{{foo}}bar|baz=biz}}buzz}}usr|{{bin}}}}"
  29. output: [TemplateOpen(), TemplateOpen(), TemplateOpen(), TemplateOpen(), Text(text="foo"), TemplateClose(), Text(text="bar"), TemplateParamSeparator(), Text(text="baz"), TemplateParamEquals(), Text(text="biz"), TemplateClose(), Text(text="buzz"), TemplateClose(), Text(text="usr"), TemplateParamSeparator(), TemplateOpen(), Text(text="bin"), TemplateClose(), TemplateClose()]
  30. ---
  31. name: wildcard_redux
  32. label: an even wilder assortment of various things
  33. input: "{{a|b|{{c|[[d]]{{{e}}}}}}}[[f|{{{g}}}<!--h-->]]{{i|j=&nbsp;}}"
  34. output: [TemplateOpen(), Text(text="a"), TemplateParamSeparator(), Text(text="b"), TemplateParamSeparator(), TemplateOpen(), Text(text="c"), TemplateParamSeparator(), WikilinkOpen(), Text(text="d"), WikilinkClose(), ArgumentOpen(), Text(text="e"), ArgumentClose(), TemplateClose(), TemplateClose(), WikilinkOpen(), Text(text="f"), WikilinkSeparator(), ArgumentOpen(), Text(text="g"), ArgumentClose(), CommentStart(), Text(text="h"), CommentEnd(), WikilinkClose(), TemplateOpen(), Text(text="i"), TemplateParamSeparator(), Text(text="j"), TemplateParamEquals(), HTMLEntityStart(), Text(text="nbsp"), HTMLEntityEnd(), TemplateClose()]