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.
 
 
 
 

138 lines
7.3 KiB

  1. name: empty_table
  2. label: Parsing an empty table.
  3. input: "{|\n|}"
  4. output: [TagOpenOpen(wiki_markup="{|"), Text(text="table"), TagCloseOpen(), Text(text="\n"), TagOpenClose(), Text(text="table"), TagCloseClose()]
  5. ---
  6. name: inline_table
  7. label: Correctly handle tables with close on the same line.
  8. input: "{||}"
  9. output: [TagOpenOpen(wiki_markup="{|"), Text(text="table"), TagCloseOpen(), TagOpenClose(), Text(text="table"), TagCloseClose()]
  10. ---
  11. name: no_table_close_simple
  12. label: Handle case when there is no table close.
  13. input: "{| "
  14. output: [Text(text="{| ")]
  15. ---
  16. name: no_table_close_inside_cell
  17. label: Handle case when there is no table close while inside of a cell.
  18. input: "{| | "
  19. output: [Text(text="{| | ")]
  20. ---
  21. name: leading_whitespace_table
  22. label: Handle leading whitespace for a table.
  23. input: "foo \n \t {|\n|}"
  24. output: [Text(text="foo \n \t "), TagOpenOpen(wiki_markup="{|"), Text(text="table"), TagCloseOpen(), Text(text="\n"), TagOpenClose(), Text(text="table"), TagCloseClose()]
  25. ---
  26. name: leading_characters_table
  27. label: Don't parse as a table when leading characters are not newline or whitespace.
  28. input: "foo \n foo \t {|\n|}"
  29. output: [Text(text="foo \n foo \t {|\n|}")]
  30. ---
  31. name: table_row_simple
  32. label: Simple table row.
  33. input: "{|\n |- \n|}"
  34. output: [TagOpenOpen(wiki_markup="{|"), Text(text="table"), TagCloseOpen(), Text(text="\n "), TagOpenOpen(wiki_markup="|-"), Text(text="tr"), TagCloseSelfclose(), Text(text=" \n"), TagOpenClose(), Text(text="table"), TagCloseClose()]
  35. ---
  36. name: table_cell_simple
  37. label: Simple table cell.
  38. input: "{|\n | foo \n|}"
  39. output: [TagOpenOpen(wiki_markup="{|"), Text(text="table"), TagCloseOpen(), Text(text="\n "), TagOpenOpen(wiki_markup="|"), Text(text="td"), TagCloseSelfclose(), Text(text=" foo \n"), TagOpenClose(), Text(text="table"), TagCloseClose()]
  40. ---
  41. name: table_cell_inline
  42. label: Multiple inline table cells.
  43. input: "{|\n | foo || bar || test \n|}"
  44. output: [TagOpenOpen(wiki_markup="{|"), Text(text="table"), TagCloseOpen(), Text(text="\n "), TagOpenOpen(wiki_markup="|"), Text(text="td"), TagCloseSelfclose(), Text(text=" foo "), TagOpenOpen(wiki_markup="||"), Text(text="td"), TagCloseSelfclose(), Text(text=" bar "),TagOpenOpen(wiki_markup="||"), Text(text="td"), TagCloseSelfclose(), Text(text=" test \n"), TagOpenClose(), Text(text="table"), TagCloseClose()]
  45. ---
  46. name: table_header_simple
  47. label: Simple header cell.
  48. input: "{|\n ! foo \n|}"
  49. output: [TagOpenOpen(wiki_markup="{|"), Text(text="table"), TagCloseOpen(), Text(text="\n "), TagOpenOpen(wiki_markup="!"), Text(text="th"), TagCloseSelfclose(), Text(text=" foo \n"), TagOpenClose(), Text(text="table"), TagCloseClose()]
  50. ---
  51. name: table_header_inline
  52. label: Multiple inline header cells.
  53. input: "{|\n ! foo || bar !! test \n|}"
  54. output: [TagOpenOpen(wiki_markup="{|"), Text(text="table"), TagCloseOpen(), Text(text="\n "), TagOpenOpen(wiki_markup="!"), Text(text="th"), TagCloseSelfclose(), Text(text=" foo "), TagOpenOpen(wiki_markup="||"), Text(text="th"), TagCloseSelfclose(), Text(text=" bar "),TagOpenOpen(wiki_markup="!!"), Text(text="th"), TagCloseSelfclose(), Text(text=" test \n"), TagOpenClose(), Text(text="table"), TagCloseClose()]
  55. ---
  56. name: nowiki_inside_table
  57. label: Nowiki handles pipe characters in tables.
  58. input: "{|\n | foo <nowiki>| |- {| |} || ! !!</nowiki> bar \n|}"
  59. output: [TagOpenOpen(wiki_markup="{|"), Text(text="table"), TagCloseOpen(), Text(text="\n "), TagOpenOpen(wiki_markup="|"), Text(text="td"), TagCloseSelfclose(), Text(text=" foo "), TagOpenOpen(), Text(text="nowiki"), TagCloseOpen(padding=""), Text(text="| |- {| |} || ! !!"), TagOpenClose(), Text(text="nowiki"), TagCloseClose(), Text(text=" bar \n"), TagOpenClose(), Text(text="table"), TagCloseClose()]
  60. ---
  61. name: table_text_outside_cell
  62. label: Parse text inside table but outside of a cell.
  63. input: "{|\n bar \n | foo \n|}"
  64. output: [TagOpenOpen(wiki_markup="{|"), Text(text="table"), TagCloseOpen(), Text(text="\n bar \n "), TagOpenOpen(wiki_markup="|"), Text(text="td"), TagCloseSelfclose(), Text(text=" foo \n"), TagOpenClose(), Text(text="table"), TagCloseClose()]
  65. ---
  66. name: no_table_cell_with_leading_characters
  67. label: Fail to create a table cell when there are leading non-whitespace characters.
  68. input: "{|\n bar | foo \n|}"
  69. output: [TagOpenOpen(wiki_markup="{|"), Text(text="table"), TagCloseOpen(), Text(text="\n bar | foo \n"), TagOpenClose(), Text(text="table"), TagCloseClose()]
  70. ---
  71. name: no_table_row_with_leading_characters
  72. label: Fail to create a table row when there are leading non-whitespace characters.
  73. input: "{|\n bar |- foo \n|}"
  74. output: [TagOpenOpen(wiki_markup="{|"), Text(text="table"), TagCloseOpen(), Text(text="\n bar |- foo \n"), TagOpenClose(), Text(text="table"), TagCloseClose()]
  75. ---
  76. name: template_inside_table_cell
  77. label: Template within table cell.
  78. input: "{|\n |{{foo\n|bar=baz}} \n|}"
  79. output: [TagOpenOpen(wiki_markup="{|"), Text(text="table"), TagCloseOpen(), Text(text="\n "), TagOpenOpen(wiki_markup="|"), Text(text="td"), TagCloseSelfclose(), TemplateOpen(), Text(text="foo\n"), TemplateParamSeparator(), Text(text="bar"), TemplateParamEquals(), Text(text="baz"), TemplateClose(), Text(text=" \n"), TagOpenClose(), Text(text="table"), TagCloseClose()]
  80. ---
  81. name: table_cell_attributes
  82. label: Parse table cell style attributes.
  83. input: "{| \n | name="foo bar"| test \n|}"
  84. output: [TagOpenOpen(wiki_markup="{|"), Text(text="table"), TagCloseOpen(), Text(text=" \n "), TagOpenOpen(wiki_markup="|"), Text(text="td"), TagAttrStart(pad_first=" ", pad_before_eq="", pad_after_eq=""), Text(text="name"), TagAttrEquals(), TagAttrQuote(char="\""), Text(text="foo bar"), TagCloseSelfclose(), Text(text=" test \n"), TagOpenClose(), Text(text="table"), TagCloseClose()]
  85. ---
  86. name: table_cell_attributes_quote_with_pipe
  87. label: Pipe inside an attribute quote should still be used as a style separator.
  88. input: "{| \n | name="foo|bar"| test \n|}"
  89. output: [TagOpenOpen(wiki_markup="{|"), Text(text="table"), TagCloseOpen(), Text(text=" \n "), TagOpenOpen(wiki_markup="|"), Text(text="td"), TagAttrStart(pad_first=" ", pad_before_eq="", pad_after_eq=""), Text(text="name"), TagAttrEquals(), TagAttrQuote(char="\""), Text(text="foo"), TagCloseSelfclose(), Text(text="bar\"| test \n"), TagOpenClose(), Text(text="table"), TagCloseClose()]
  90. ---
  91. name: table_cell_attributes_name_with_pipe
  92. label: Pipe inside an attribute name should still be used as a style separator.
  93. input: "{| \n | name|="foo bar"| test \n|}"
  94. output: [TagOpenOpen(wiki_markup="{|"), Text(text="table"), TagCloseOpen(), Text(text=" \n "), TagOpenOpen(wiki_markup="|"), Text(text="td"), TagAttrStart(pad_first=" ", pad_before_eq="", pad_after_eq=""), Text(text="name"), TagCloseSelfclose(), Text(text="=\"foo bar"| test \n"), TagOpenClose(), Text(text="table"), TagCloseClose()]
  95. ---
  96. name: table_cell_attributes_pipe_after_equals
  97. label: Pipe inside an attribute should still be used as a style separator after an equals.
  98. input: "{| \n | name=|"foo|bar"| test \n|}"
  99. output: [TagOpenOpen(wiki_markup="{|"), Text(text="table"), TagCloseOpen(), Text(text=" \n "), TagOpenOpen(wiki_markup="|"), Text(text="td"), TagAttrStart(pad_first=" ", pad_before_eq="", pad_after_eq=""), Text(text="name"), TagAttrEquals(), TagCloseSelfclose(), Text(text="\"foo|bar\"| test \n"), TagOpenClose(), Text(text="table"), TagCloseClose()]