A Python parser for MediaWiki wikicode https://mwparserfromhell.readthedocs.io/
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 

349 wiersze
17 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: link_in_template_name
  12. label: a wikilink inside a template name, which breaks the template
  13. input: "{{foo[[bar]]}}"
  14. output: [Text(text="{{foo"), WikilinkOpen(), Text(text="bar"), WikilinkClose(), Text(text="}}")]
  15. ---
  16. name: rich_heading
  17. label: a heading with templates/wikilinks in it
  18. input: "== Head{{ing}} [[with]] {{{funky|{{stuf}}}}} =="
  19. 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()]
  20. ---
  21. name: html_entity_with_template
  22. label: a HTML entity with a template embedded inside
  23. input: "&n{{bs}}p;"
  24. output: [Text(text="&n"), TemplateOpen(), Text(text="bs"), TemplateClose(), Text(text="p;")]
  25. ---
  26. name: html_entity_with_comment
  27. label: a HTML entity with a comment embedded inside
  28. input: "&n<!--foo-->bsp;"
  29. output: [Text(text="&n"), CommentStart(), Text(text="foo"), CommentEnd(), Text(text="bsp;")]
  30. ---
  31. name: rich_tags
  32. label: a HTML tag with tons of other things in it
  33. input: "{{dubious claim}}<ref name={{abc}} foo="bar {{baz}}" abc={{de}}f ghi=j{{k}}{{l}} \n mno = "{{p}} [[q]] {{r}}">[[Source]]</ref>"
  34. output: [TemplateOpen(), Text(text="dubious claim"), TemplateClose(), TagOpenOpen(), Text(text="ref"), TagAttrStart(pad_first=" ", pad_before_eq="", pad_after_eq=""), Text(text="name"), TagAttrEquals(), TemplateOpen(), Text(text="abc"), TemplateClose(), TagAttrStart(pad_first=" ", pad_before_eq="", pad_after_eq=""), Text(text="foo"), TagAttrEquals(), TagAttrQuote(char="\""), Text(text="bar "), TemplateOpen(), Text(text="baz"), TemplateClose(), TagAttrStart(pad_first=" ", pad_before_eq="", pad_after_eq=""), Text(text="abc"), TagAttrEquals(), TemplateOpen(), Text(text="de"), TemplateClose(), Text(text="f"), TagAttrStart(pad_first=" ", pad_before_eq="", pad_after_eq=""), Text(text="ghi"), TagAttrEquals(), Text(text="j"), TemplateOpen(), Text(text="k"), TemplateClose(), TemplateOpen(), Text(text="l"), TemplateClose(), TagAttrStart(pad_first=" \n ", pad_before_eq=" ", pad_after_eq=" "), Text(text="mno"), TagAttrEquals(), TagAttrQuote(char="\""), TemplateOpen(), Text(text="p"), TemplateClose(), Text(text=" "), WikilinkOpen(), Text(text="q"), WikilinkClose(), Text(text=" "), TemplateOpen(), Text(text="r"), TemplateClose(), TagCloseOpen(padding=""), WikilinkOpen(), Text(text="Source"), WikilinkClose(), TagOpenClose(), Text(text="ref"), TagCloseClose()]
  35. ---
  36. name: wildcard
  37. label: a wildcard assortment of various things
  38. input: "{{{{{{{{foo}}bar|baz=biz}}buzz}}usr|{{bin}}}}"
  39. 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()]
  40. ---
  41. name: wildcard_redux
  42. label: an even wilder assortment of various things
  43. input: "{{a|b|{{c|[[d]]{{{e}}}}}}}[[f|{{{g}}}<!--h-->]]{{i|j=&nbsp;}}"
  44. 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()]
  45. ---
  46. name: link_inside_dl
  47. label: an external link inside a def list, such that the external link is parsed
  48. input: ";;;mailto:example"
  49. output: [TagOpenOpen(wiki_markup=";"), Text(text="dt"), TagCloseSelfclose(), TagOpenOpen(wiki_markup=";"), Text(text="dt"), TagCloseSelfclose(), TagOpenOpen(wiki_markup=";"), Text(text="dt"), TagCloseSelfclose(), ExternalLinkOpen(brackets=False), Text(text="mailto:example"), ExternalLinkClose()]
  50. ---
  51. name: link_inside_dl_2
  52. label: an external link inside a def list, such that the external link is not parsed
  53. input: ";;;malito:example"
  54. output: [TagOpenOpen(wiki_markup=";"), Text(text="dt"), TagCloseSelfclose(), TagOpenOpen(wiki_markup=";"), Text(text="dt"), TagCloseSelfclose(), TagOpenOpen(wiki_markup=";"), Text(text="dt"), TagCloseSelfclose(), Text(text="malito"), TagOpenOpen(wiki_markup=":"), Text(text="dd"), TagCloseSelfclose(), Text(text="example")]
  55. ---
  56. name: link_inside_template
  57. label: an external link nested inside a template, before the end
  58. input: "{{URL|http://example.com}}"
  59. output: [TemplateOpen(), Text(text="URL"), TemplateParamSeparator(), ExternalLinkOpen(brackets=False), Text(text="http://example.com"), ExternalLinkClose(), TemplateClose()]
  60. ---
  61. name: link_inside_template_2
  62. label: an external link nested inside a template, before a separator
  63. input: "{{URL|http://example.com|foobar}}"
  64. output: [TemplateOpen(), Text(text="URL"), TemplateParamSeparator(), ExternalLinkOpen(brackets=False), Text(text="http://example.com"), ExternalLinkClose(), TemplateParamSeparator(), Text(text="foobar"), TemplateClose()]
  65. ---
  66. name: link_inside_template_3
  67. label: an external link nested inside a template, before an equal sign
  68. input: "{{URL|http://example.com=foobar}}"
  69. output: [TemplateOpen(), Text(text="URL"), TemplateParamSeparator(), ExternalLinkOpen(brackets=False), Text(text="http://example.com"), ExternalLinkClose(), TemplateParamEquals(), Text(text="foobar"), TemplateClose()]
  70. ---
  71. name: link_inside_argument
  72. label: an external link nested inside an argument
  73. input: "{{{URL|http://example.com}}}"
  74. output: [ArgumentOpen(), Text(text="URL"), ArgumentSeparator(), ExternalLinkOpen(brackets=False), Text(text="http://example.com"), ExternalLinkClose(), ArgumentClose()]
  75. ---
  76. name: link_inside_heading
  77. label: an external link nested inside a heading
  78. input: "==http://example.com=="
  79. output: [HeadingStart(level=2), ExternalLinkOpen(brackets=False), Text(text="http://example.com"), ExternalLinkClose(), HeadingEnd()]
  80. ---
  81. name: link_inside_tag_body
  82. label: an external link nested inside the body of a tag
  83. input: "<ref>http://example.com</ref>"
  84. output: [TagOpenOpen(), Text(text="ref"), TagCloseOpen(padding=""), ExternalLinkOpen(brackets=False), Text(text="http://example.com"), ExternalLinkClose(), TagOpenClose(), Text(text="ref"), TagCloseClose()]
  85. ---
  86. name: link_inside_tag_style
  87. label: an external link nested inside style tags
  88. input: "''http://example.com''"
  89. output: [TagOpenOpen(wiki_markup="''"), Text(text="i"), TagCloseOpen(), ExternalLinkOpen(brackets=False), Text(text="http://example.com"), ExternalLinkClose(), TagOpenClose(), Text(text="i"), TagCloseClose()]
  90. ---
  91. name: style_tag_inside_link
  92. label: style tags disrupting an external link
  93. input: "http://example.com/foo''bar''"
  94. output: [ExternalLinkOpen(brackets=False), Text(text="http://example.com/foo"), ExternalLinkClose(), TagOpenOpen(wiki_markup="''"), Text(text="i"), TagCloseOpen(), Text(text="bar"), TagOpenClose(), Text(text="i"), TagCloseClose()]
  95. ---
  96. name: comment_inside_link
  97. label: an HTML comment inside an external link
  98. input: "http://example.com/foo<!--comment-->bar"
  99. output: [ExternalLinkOpen(brackets=False), Text(text="http://example.com/foo"), CommentStart(), Text(text="comment"), CommentEnd(), Text(text="bar"), ExternalLinkClose()]
  100. ---
  101. name: bracketed_link_inside_template
  102. label: a bracketed external link nested inside a template, before the end
  103. input: "{{URL|[http://example.com}}]"
  104. output: [Text(text="{{URL|"), ExternalLinkOpen(brackets=True), Text(text="http://example.com}}"), ExternalLinkClose()]
  105. ---
  106. name: comment_inside_bracketed_link
  107. label: an HTML comment inside a bracketed external link
  108. input: "[http://example.com/foo<!--comment-->bar]"
  109. output: [ExternalLinkOpen(brackets=True), Text(text="http://example.com/foo"), CommentStart(), Text(text="comment"), CommentEnd(), Text(text="bar"), ExternalLinkClose()]
  110. ---
  111. name: wikilink_inside_external_link
  112. label: a wikilink inside an external link, which the parser considers valid (see issue #61)
  113. input: "[http://example.com/foo Foo [[Bar]]]"
  114. output: [ExternalLinkOpen(brackets=True), Text(text="http://example.com/foo"), ExternalLinkSeparator(), Text(text="Foo "), WikilinkOpen(), Text(text="Bar"), WikilinkClose(), ExternalLinkClose()]
  115. ---
  116. name: external_link_inside_wikilink
  117. label: an external link inside a wikilink, valid in the case of images (see issue #62)
  118. input: "[[File:Example.png|thumb|http://example.com]]"
  119. output: [WikilinkOpen(), Text(text="File:Example.png"), WikilinkSeparator(), Text(text="thumb|"), ExternalLinkOpen(brackets=False), Text(text="http://example.com"), ExternalLinkClose(), WikilinkClose()]
  120. ---
  121. name: external_link_inside_wikilink_brackets
  122. label: an external link with brackets inside a wikilink
  123. input: "[[File:Example.png|thumb|[http://example.com Example]]]"
  124. output: [WikilinkOpen(), Text(text="File:Example.png"), WikilinkSeparator(), Text(text="thumb|"), ExternalLinkOpen(brackets=True), Text(text="http://example.com"), ExternalLinkSeparator(), Text(text="Example"), ExternalLinkClose(), WikilinkClose()]
  125. ---
  126. name: external_link_inside_wikilink_title
  127. label: an external link inside a wikilink title, which is not parsed
  128. input: "[[File:Example.png http://example.com]]"
  129. output: [WikilinkOpen(), Text(text="File:Example.png http://example.com"), WikilinkClose()]
  130. ---
  131. name: italics_inside_external_link_inside_incomplete_list
  132. label: italic text inside an external link inside an incomplete list
  133. input: "<li>[http://www.example.com ''example'']"
  134. output: [TagOpenOpen(), Text(text="li"), TagCloseSelfclose(padding="", implicit=True), ExternalLinkOpen(brackets=True), Text(text="http://www.example.com"), ExternalLinkSeparator(), TagOpenOpen(wiki_markup="''"), Text(text="i"), TagCloseOpen(), Text(text="example"), TagOpenClose(), Text(text="i"), TagCloseClose(), ExternalLinkClose()]
  135. ---
  136. name: nodes_inside_external_link_after_punct
  137. label: various complex nodes inside an external link following punctuation
  138. input: "http://example.com/foo.{{bar}}baz.&biz;<!--hello-->bingo"
  139. output: [ExternalLinkOpen(brackets=False), Text(text="http://example.com/foo."), TemplateOpen(), Text(text="bar"), TemplateClose(), Text(text="baz.&biz;"), CommentStart(), Text(text="hello"), CommentEnd(), Text(text="bingo"), ExternalLinkClose()]
  140. ---
  141. name: newline_and_comment_in_template_name
  142. label: a template name containing a newline followed by a comment
  143. input: "{{foobar\n<!-- comment -->}}"
  144. output: [TemplateOpen(), Text(text="foobar\n"), CommentStart(), Text(text=" comment "), CommentEnd(), TemplateClose()]
  145. ---
  146. name: newline_and_comment_in_template_name_2
  147. label: a template name containing a newline followed by a comment
  148. input: "{{foobar\n<!-- comment -->|key=value}}"
  149. output: [TemplateOpen(), Text(text="foobar\n"), CommentStart(), Text(text=" comment "), CommentEnd(), TemplateParamSeparator(), Text(text="key"), TemplateParamEquals(), Text(text="value"), TemplateClose()]
  150. ---
  151. name: newline_and_comment_in_template_name_3
  152. label: a template name containing a newline followed by a comment
  153. input: "{{foobar\n<!-- comment -->\n|key=value}}"
  154. output: [TemplateOpen(), Text(text="foobar\n"), CommentStart(), Text(text=" comment "), CommentEnd(), Text(text="\n"), TemplateParamSeparator(), Text(text="key"), TemplateParamEquals(), Text(text="value"), TemplateClose()]
  155. ---
  156. name: newline_and_comment_in_template_name_4
  157. label: a template name containing a newline followed by a comment
  158. input: "{{foobar\n<!-- comment -->invalid|key=value}}"
  159. output: [Text(text="{{foobar\n"), CommentStart(), Text(text=" comment "), CommentEnd(), Text(text="invalid|key=value}}")]
  160. ---
  161. name: newline_and_comment_in_template_name_5
  162. label: a template name containing a newline followed by a comment
  163. input: "{{foobar\n<!-- comment -->\ninvalid|key=value}}"
  164. output: [Text(text="{{foobar\n"), CommentStart(), Text(text=" comment "), CommentEnd(), Text(text="\ninvalid|key=value}}")]
  165. ---
  166. name: newline_and_comment_in_template_name_6
  167. label: a template name containing a newline followed by a comment
  168. input: "{{foobar\n<!--|key=value}}"
  169. output: [Text(text="{{foobar\n<!--|key=value}}")]
  170. ---
  171. name: newline_and_comment_in_template_name_7
  172. label: a template name containing a newline followed by a comment
  173. input: "{{foobar\n<!|key=value}}"
  174. output: [Text(text="{{foobar\n<!|key=value}}")]
  175. ---
  176. name: newline_and_comment_in_template_name_8
  177. label: a template name containing a newline followed by a comment
  178. input: "{{<!-- comment -->\nfoobar\n<!-- comment -->}}"
  179. output: [TemplateOpen(), CommentStart(), Text(text=" comment "), CommentEnd(), Text(text="\nfoobar\n"), CommentStart(), Text(text=" comment "), CommentEnd(), TemplateClose()]
  180. ---
  181. name: tag_in_link_title
  182. label: HTML tags are invalid in link titles, even when complete
  183. input: "[[foo<i>bar</i>baz]]"
  184. output: [Text(text="[[foo"), TagOpenOpen(), Text(text="i"), TagCloseOpen(padding=""), Text(text="bar"), TagOpenClose(), Text(text="i"), TagCloseClose(), Text(text="baz]]")]
  185. ---
  186. name: tag_in_template_name
  187. label: HTML tags are invalid in template names, even when complete
  188. input: "{{foo<i>bar</i>baz}}"
  189. output: [Text(text="{{foo"), TagOpenOpen(), Text(text="i"), TagCloseOpen(padding=""), Text(text="bar"), TagOpenClose(), Text(text="i"), TagCloseClose(), Text(text="baz}}")]
  190. ---
  191. name: tag_in_link_text
  192. label: HTML tags are valid in link text
  193. input: "[[foo|<i>bar</i>baz]]"
  194. output: [WikilinkOpen(), Text(text="foo"), WikilinkSeparator(), TagOpenOpen(), Text(text="i"), TagCloseOpen(padding=""), Text(text="bar"), TagOpenClose(), Text(text="i"), TagCloseClose(), Text(text="baz"), WikilinkClose()]
  195. ---
  196. name: comment_in_link_title
  197. label: comments are valid in link titles
  198. input: "[[foo<!--bar-->baz]]"
  199. output: [WikilinkOpen(), Text(text="foo"), CommentStart(), Text(text="bar"), CommentEnd(), Text(text="baz"), WikilinkClose()]
  200. ---
  201. name: incomplete_comment_in_link_title
  202. label: incomplete comments are invalid in link titles
  203. input: "[[foo<!--bar--baz]]"
  204. output: [Text(text="[[foo<!--bar--baz]]")]
  205. ---
  206. name: incomplete_comment_in_link_title_2
  207. label: incomplete comments are invalid in link titles
  208. input: "[[foo<!--barbaz]]"
  209. output: [Text(text="[[foo<!--barbaz]]")]
  210. ---
  211. name: incomplete_comment_in_link_title_3
  212. label: incomplete comments are invalid in link titles
  213. input: "[[foo<!barbaz]]"
  214. output: [Text(text="[[foo<!barbaz]]")]
  215. ---
  216. name: incomplete_comment_in_link_title_4
  217. label: incomplete comments are invalid in link titles
  218. input: "[[foo<!--]]"
  219. output: [Text(text="[[foo<!--]]")]
  220. ---
  221. name: incomplete_comment_in_link_title_5
  222. label: incomplete comments are invalid in link titles
  223. input: "[[foo<!-"
  224. output: [Text(text="[[foo<!-")]
  225. ---
  226. name: incomplete_comment_in_link_title_6
  227. label: incomplete comments are invalid in link titles
  228. input: "[[foo<!--bar"
  229. output: [Text(text="[[foo<!--bar")]
  230. ---
  231. name: wikilink_to_external_link_fallback
  232. label: an external link enclosed in an extra pair of brackets (see issue #120)
  233. input: "[[http://example.com foo bar]]"
  234. output: [Text(text="["), ExternalLinkOpen(brackets=True), Text(text="http://example.com"), ExternalLinkSeparator(), Text(text="foo bar"), ExternalLinkClose(), Text(text="]")]
  235. ---
  236. name: wikilink_to_external_link_fallback_2
  237. label: an external link enclosed in an extra pair of brackets (see issue #120)
  238. input: "[[http://example.com]]"
  239. output: [Text(text="["), ExternalLinkOpen(brackets=True), Text(text="http://example.com"), ExternalLinkClose(), Text(text="]")]
  240. ---
  241. name: tables_in_templates
  242. label: catch error handling mistakes when wikitables are inside templates
  243. input: "{{hello|test\n{|\n|} }}"
  244. output: [TemplateOpen(), Text(text="hello"), TemplateParamSeparator(), Text(text="test\n"), TagOpenOpen(wiki_markup="{|"), Text(text="table"), TagCloseOpen(padding="\n"), TagOpenClose(wiki_markup="|}"), Text(text="table"), TagCloseClose(), Text(text=" "), TemplateClose()]
  245. ---
  246. name: tables_in_templates_2
  247. label: catch error handling mistakes when wikitables are inside templates
  248. input: "{{hello|test\n{|\n| }}"
  249. output: [TemplateOpen(), Text(text="hello"), TemplateParamSeparator(), Text(text="test\n{"), TemplateParamSeparator(), Text(text="\n"), TemplateParamSeparator(), Text(text=" "), TemplateClose()]