Browse Source

Tables and rows now use newline as padding

Tables and rows use newlines as padding, partly because these characters
are pretty important to the integrity of the table. They might need
to be in the preceding whitespace of inner tags instead as padding after,
not sure.
tags/v0.4
David Winegar 10 years ago
parent
commit
ec08001871
5 changed files with 81 additions and 61 deletions
  1. +19
    -20
      mwparserfromhell/nodes/tag.py
  2. +1
    -0
      mwparserfromhell/parser/builder.py
  3. +18
    -14
      mwparserfromhell/parser/tokenizer.py
  4. +0
    -5
      tests/test_tag.py
  5. +43
    -22
      tests/tokenizer/tables.mwtest

+ 19
- 20
mwparserfromhell/nodes/tag.py View File

@@ -44,11 +44,10 @@ class Tag(Node):
self._contents = contents self._contents = contents
self._attrs = attrs if attrs else [] self._attrs = attrs if attrs else []
self._wiki_markup = wiki_markup self._wiki_markup = wiki_markup
if wiki_markup and not self_closing:
if closing_wiki_markup:
self._closing_wiki_markup = closing_wiki_markup
else:
self._closing_wiki_markup = wiki_markup
if closing_wiki_markup:
self._closing_wiki_markup = closing_wiki_markup
elif wiki_markup and not self_closing:
self._closing_wiki_markup = wiki_markup
else: else:
self._closing_wiki_markup = None self._closing_wiki_markup = None
self._self_closing = self_closing self._self_closing = self_closing
@@ -63,10 +62,12 @@ class Tag(Node):
def __unicode__(self): def __unicode__(self):
if self.wiki_markup: if self.wiki_markup:
attrs = "".join([str(attr) for attr in self.attributes]) if self.attributes else "" attrs = "".join([str(attr) for attr in self.attributes]) if self.attributes else ""
close = self.closing_wiki_markup if self.closing_wiki_markup else ""
padding = self.padding if self.padding else ""
if self.self_closing: if self.self_closing:
return self.wiki_markup
return self.wiki_markup + attrs + close + padding
else: else:
return self.wiki_markup + attrs + str(self.contents) + self.closing_wiki_markup
return self.wiki_markup + attrs + padding + str(self.contents) + close


result = ("</" if self.invalid else "<") + str(self.tag) result = ("</" if self.invalid else "<") + str(self.tag)
if self.attributes: if self.attributes:
@@ -81,10 +82,10 @@ class Tag(Node):
def __children__(self): def __children__(self):
if not self.wiki_markup: if not self.wiki_markup:
yield self.tag yield self.tag
for attr in self.attributes:
yield attr.name
if attr.value is not None:
yield attr.value
for attr in self.attributes:
yield attr.name
if attr.value is not None:
yield attr.value
if self.contents: if self.contents:
yield self.contents yield self.contents
if not self.self_closing and not self.wiki_markup and self.closing_tag: if not self.self_closing and not self.wiki_markup and self.closing_tag:
@@ -147,11 +148,12 @@ class Tag(Node):
"""The wikified version of the closing tag to show instead of HTML. """The wikified version of the closing tag to show instead of HTML.


If set to a value, this will be displayed instead of the close tag If set to a value, this will be displayed instead of the close tag
brackets. If tag is :attr:`self_closing` is ``True``, this is set to
``None`` and not displayed. If :attr:`wiki_markup` is set and this has
not been set, this is set to the value of :attr:`wiki_markup`. If this
has been set and :attr:`wiki_markup` is set to a ``False`` value, this
is set to ``None``.
brackets. If tag is :attr:`self_closing` is ``True`` and this is not
``None``, then it becomes the self-closing end tag. If
:attr:`wiki_markup` is set and this has not been set, this is set to the
value of :attr:`wiki_markup`. If this has been set and
:attr:`wiki_markup` is set to a ``False`` value, this is set to
``None``.
""" """
return self._closing_wiki_markup return self._closing_wiki_markup


@@ -209,16 +211,13 @@ class Tag(Node):
if not value or not self.closing_wiki_markup: if not value or not self.closing_wiki_markup:
self.closing_wiki_markup = str(value) if value else None self.closing_wiki_markup = str(value) if value else None



@closing_wiki_markup.setter @closing_wiki_markup.setter
def closing_wiki_markup(self, value): def closing_wiki_markup(self, value):
self._closing_wiki_markup = str(value) if value and not self.self_closing else None
self._closing_wiki_markup = str(value) if value else None


@self_closing.setter @self_closing.setter
def self_closing(self, value): def self_closing(self, value):
self._self_closing = bool(value) self._self_closing = bool(value)
if not bool(value):
self.closing_wiki_markup = None


@invalid.setter @invalid.setter
def invalid(self, value): def invalid(self, value):


+ 1
- 0
mwparserfromhell/parser/builder.py View File

@@ -264,6 +264,7 @@ class Builder(object):
self._push() self._push()
elif isinstance(token, close_tokens): elif isinstance(token, close_tokens):
if isinstance(token, tokens.TagCloseSelfclose): if isinstance(token, tokens.TagCloseSelfclose):
closing_wiki_markup = token.wiki_markup
tag = self._pop() tag = self._pop()
self_closing = True self_closing = True
padding = token.padding or "" padding = token.padding or ""


+ 18
- 14
mwparserfromhell/parser/tokenizer.py View File

@@ -1009,9 +1009,9 @@ class Tokenizer(object):
style = None style = None
try: try:
self._push(contexts.TABLE_OPEN) self._push(contexts.TABLE_OPEN)
style = self._parse_as_table_style("\n", break_on_table_end=True)
if len(style) == 0:
self._head = reset
(style, padding) = self._parse_as_table_style("\n", break_on_table_end=True)
# Have to do this in the case of inline tables
self._head += 1 if "\n" in padding else 0
table = self._parse(contexts.TABLE_OPEN) table = self._parse(contexts.TABLE_OPEN)
except BadRoute: except BadRoute:
# offset displacement done by _parse() # offset displacement done by _parse()
@@ -1022,7 +1022,7 @@ class Tokenizer(object):
self._emit_text("table") self._emit_text("table")
if style: if style:
self._emit_all(style) self._emit_all(style)
self._emit(tokens.TagCloseOpen())
self._emit(tokens.TagCloseOpen(padding=padding))
self._emit_all(table) self._emit_all(table)
self._emit(tokens.TagOpenClose(wiki_markup="|}")) self._emit(tokens.TagOpenClose(wiki_markup="|}"))
self._emit_text("table") self._emit_text("table")
@@ -1044,9 +1044,7 @@ class Tokenizer(object):
self._head += 2 self._head += 2
try: try:
self._push(contexts.TABLE_OPEN) self._push(contexts.TABLE_OPEN)
style = self._parse_as_table_style("\n")
if len(style) == 0:
self._head = reset + 2
(style, padding) = self._parse_as_table_style("\n")
except BadRoute: except BadRoute:
self._head = reset self._head = reset
raise raise
@@ -1055,9 +1053,7 @@ class Tokenizer(object):
self._emit_text("tr") self._emit_text("tr")
if style: if style:
self._emit_all(style) self._emit_all(style)
self._emit(tokens.TagCloseSelfclose())
# offset displacement done by _parse()
self._head -= 1
self._emit(tokens.TagCloseSelfclose(padding=padding))


def _handle_table_cell(self, markup, tag, line_context): def _handle_table_cell(self, markup, tag, line_context):
"""Parse as normal syntax unless we hit a style marker, then parse style """Parse as normal syntax unless we hit a style marker, then parse style
@@ -1082,7 +1078,7 @@ class Tokenizer(object):
self._head = reset + len(markup) self._head = reset + len(markup)
try: try:
self._push(table_context) self._push(table_context)
style = self._parse_as_table_style("|")
(style, padding) = self._parse_as_table_style("|")
# Don't parse the style separator # Don't parse the style separator
self._head += 1 self._head += 1
(cell_context, cell) = self._parse(table_context) (cell_context, cell) = self._parse(table_context)
@@ -1094,7 +1090,9 @@ class Tokenizer(object):
self._emit_text(tag) self._emit_text(tag)
if style: if style:
self._emit_all(style) self._emit_all(style)
self._emit(tokens.TagCloseSelfclose())
self._emit(tokens.TagCloseSelfclose(wiki_markup="|"))
else:
self._emit(tokens.TagCloseSelfclose())
self._emit_all(cell) self._emit_all(cell)
# keep header/cell line contexts # keep header/cell line contexts
self._context |= cell_context & (contexts.TABLE_TH_LINE | contexts.TABLE_TD_LINE) self._context |= cell_context & (contexts.TABLE_TH_LINE | contexts.TABLE_TD_LINE)
@@ -1122,9 +1120,15 @@ class Tokenizer(object):
elif this == end_token and can_exit: elif this == end_token and can_exit:
if data.context & (data.CX_ATTR_NAME | data.CX_ATTR_VALUE): if data.context & (data.CX_ATTR_NAME | data.CX_ATTR_VALUE):
self._push_tag_buffer(data) self._push_tag_buffer(data)
return self._pop()
if this.isspace():
data.padding_buffer["first"] += this
return (self._pop(), data.padding_buffer["first"])
elif break_on_table_end and this == "|" and next == "}": elif break_on_table_end and this == "|" and next == "}":
return self._pop()
if data.context & (data.CX_ATTR_NAME | data.CX_ATTR_VALUE):
self._push_tag_buffer(data)
if this.isspace():
data.padding_buffer["first"] += this
return (self._pop(), data.padding_buffer["first"])
else: else:
self._handle_tag_data(data, this) self._handle_tag_data(data, this)
self._head += 1 self._head += 1


+ 0
- 5
tests/test_tag.py View File

@@ -182,11 +182,6 @@ class TestTag(TreeEqualityTestCase):
self.assertEqual("{|\n|}", node) self.assertEqual("{|\n|}", node)
node.wiki_markup = False node.wiki_markup = False
self.assertFalse(node.closing_wiki_markup) self.assertFalse(node.closing_wiki_markup)
node.self_closing = True
node.wiki_markup = "{|"
self.assertIs(None, node.closing_wiki_markup)
node.wiki_markup = False
node.self_closing = False
self.assertEqual("<table>\n</table>", node) self.assertEqual("<table>\n</table>", node)


def test_self_closing(self): def test_self_closing(self):


+ 43
- 22
tests/tokenizer/tables.mwtest View File

@@ -1,14 +1,14 @@
name: empty_table name: empty_table
label: Parsing an empty table. label: Parsing an empty table.
input: "{|\n|}" input: "{|\n|}"
output: [TagOpenOpen(wiki_markup="{|"), Text(text="table"), TagCloseOpen(), Text(text="\n"), TagOpenClose(wiki_markup="|}"), Text(text="table"), TagCloseClose()]
output: [TagOpenOpen(wiki_markup="{|"), Text(text="table"), TagCloseOpen(padding="\n"), TagOpenClose(wiki_markup="|}"), Text(text="table"), TagCloseClose()]


--- ---


name: inline_table name: inline_table
label: Correctly handle tables with close on the same line. label: Correctly handle tables with close on the same line.
input: "{||}" input: "{||}"
output: [TagOpenOpen(wiki_markup="{|"), Text(text="table"), TagCloseOpen(), TagOpenClose(wiki_markup="|}"), Text(text="table"), TagCloseClose()]
output: [TagOpenOpen(wiki_markup="{|"), Text(text="table"), TagCloseOpen(padding=""), TagOpenClose(wiki_markup="|}"), Text(text="table"), TagCloseClose()]


--- ---


@@ -29,7 +29,7 @@ output: [Text(text="{| | ")]
name: leading_whitespace_table name: leading_whitespace_table
label: Handle leading whitespace for a table. label: Handle leading whitespace for a table.
input: "foo \n \t {|\n|}" input: "foo \n \t {|\n|}"
output: [Text(text="foo \n \t "), TagOpenOpen(wiki_markup="{|"), Text(text="table"), TagCloseOpen(), Text(text="\n"), TagOpenClose(wiki_markup="|}"), Text(text="table"), TagCloseClose()]
output: [Text(text="foo \n \t "), TagOpenOpen(wiki_markup="{|"), Text(text="table"), TagCloseOpen(padding="\n"), TagOpenClose(wiki_markup="|}"), Text(text="table"), TagCloseClose()]


--- ---


@@ -43,119 +43,133 @@ output: [Text(text="foo \n foo \t {|\n|}")]
name: table_row_simple name: table_row_simple
label: Simple table row. label: Simple table row.
input: "{|\n |- \n|}" input: "{|\n |- \n|}"
output: [TagOpenOpen(wiki_markup="{|"), Text(text="table"), TagCloseOpen(), Text(text="\n "), TagOpenOpen(wiki_markup="|-"), Text(text="tr"), TagCloseSelfclose(), Text(text=" \n"), TagOpenClose(wiki_markup="|}"), Text(text="table"), TagCloseClose()]
output: [TagOpenOpen(wiki_markup="{|"), Text(text="table"), TagCloseOpen(padding="\n"), Text(text=" "), TagOpenOpen(wiki_markup="|-"), Text(text="tr"), TagCloseSelfclose(padding=" \n"), TagOpenClose(wiki_markup="|}"), Text(text="table"), TagCloseClose()]


--- ---


name: table_cell_simple name: table_cell_simple
label: Simple table cell. label: Simple table cell.
input: "{|\n | foo \n|}" input: "{|\n | foo \n|}"
output: [TagOpenOpen(wiki_markup="{|"), Text(text="table"), TagCloseOpen(), Text(text="\n "), TagOpenOpen(wiki_markup="|"), Text(text="td"), TagCloseSelfclose(), Text(text=" foo \n"), TagOpenClose(wiki_markup="|}"), Text(text="table"), TagCloseClose()]
output: [TagOpenOpen(wiki_markup="{|"), Text(text="table"), TagCloseOpen(padding="\n"), Text(text=" "), TagOpenOpen(wiki_markup="|"), Text(text="td"), TagCloseSelfclose(), Text(text=" foo \n"), TagOpenClose(wiki_markup="|}"), Text(text="table"), TagCloseClose()]


--- ---


name: table_cell_inline name: table_cell_inline
label: Multiple inline table cells. label: Multiple inline table cells.
input: "{|\n | foo || bar || test \n|}" input: "{|\n | foo || bar || test \n|}"
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(wiki_markup="|}"), Text(text="table"), TagCloseClose()]
output: [TagOpenOpen(wiki_markup="{|"), Text(text="table"), TagCloseOpen(padding="\n"), Text(text=" "), 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(wiki_markup="|}"), Text(text="table"), TagCloseClose()]


--- ---


name: table_header_simple name: table_header_simple
label: Simple header cell. label: Simple header cell.
input: "{|\n ! foo \n|}" input: "{|\n ! foo \n|}"
output: [TagOpenOpen(wiki_markup="{|"), Text(text="table"), TagCloseOpen(), Text(text="\n "), TagOpenOpen(wiki_markup="!"), Text(text="th"), TagCloseSelfclose(), Text(text=" foo \n"), TagOpenClose(wiki_markup="|}"), Text(text="table"), TagCloseClose()]
output: [TagOpenOpen(wiki_markup="{|"), Text(text="table"), TagCloseOpen(padding="\n"), Text(text=" "), TagOpenOpen(wiki_markup="!"), Text(text="th"), TagCloseSelfclose(), Text(text=" foo \n"), TagOpenClose(wiki_markup="|}"), Text(text="table"), TagCloseClose()]


--- ---


name: table_header_inline name: table_header_inline
label: Multiple inline header cells. label: Multiple inline header cells.
input: "{|\n ! foo || bar !! test \n|}" input: "{|\n ! foo || bar !! test \n|}"
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(wiki_markup="|}"), Text(text="table"), TagCloseClose()]
output: [TagOpenOpen(wiki_markup="{|"), Text(text="table"), TagCloseOpen(padding="\n"), Text(text=" "), 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(wiki_markup="|}"), Text(text="table"), TagCloseClose()]


--- ---


name: nowiki_inside_table name: nowiki_inside_table
label: Nowiki handles pipe characters in tables. label: Nowiki handles pipe characters in tables.
input: "{|\n | foo <nowiki>| |- {| |} || ! !!</nowiki> bar \n|}" input: "{|\n | foo <nowiki>| |- {| |} || ! !!</nowiki> bar \n|}"
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(wiki_markup="|}"), Text(text="table"), TagCloseClose()]
output: [TagOpenOpen(wiki_markup="{|"), Text(text="table"), TagCloseOpen(padding="\n"), Text(text=" "), 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(wiki_markup="|}"), Text(text="table"), TagCloseClose()]


--- ---


name: table_text_outside_cell name: table_text_outside_cell
label: Parse text inside table but outside of a cell. label: Parse text inside table but outside of a cell.
input: "{|\n bar \n | foo \n|}" input: "{|\n bar \n | foo \n|}"
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(wiki_markup="|}"), Text(text="table"), TagCloseClose()]
output: [TagOpenOpen(wiki_markup="{|"), Text(text="table"), TagCloseOpen(padding="\n"), Text(text=" bar \n "), TagOpenOpen(wiki_markup="|"), Text(text="td"), TagCloseSelfclose(), Text(text=" foo \n"), TagOpenClose(wiki_markup="|}"), Text(text="table"), TagCloseClose()]


--- ---


name: no_table_cell_with_leading_characters name: no_table_cell_with_leading_characters
label: Fail to create a table cell when there are leading non-whitespace characters. label: Fail to create a table cell when there are leading non-whitespace characters.
input: "{|\n bar | foo \n|}" input: "{|\n bar | foo \n|}"
output: [TagOpenOpen(wiki_markup="{|"), Text(text="table"), TagCloseOpen(), Text(text="\n bar | foo \n"), TagOpenClose(wiki_markup="|}"), Text(text="table"), TagCloseClose()]
output: [TagOpenOpen(wiki_markup="{|"), Text(text="table"), TagCloseOpen(padding="\n"), Text(text=" bar | foo \n"), TagOpenClose(wiki_markup="|}"), Text(text="table"), TagCloseClose()]


--- ---


name: no_table_row_with_leading_characters name: no_table_row_with_leading_characters
label: Fail to create a table row when there are leading non-whitespace characters. label: Fail to create a table row when there are leading non-whitespace characters.
input: "{|\n bar |- foo \n|}" input: "{|\n bar |- foo \n|}"
output: [TagOpenOpen(wiki_markup="{|"), Text(text="table"), TagCloseOpen(), Text(text="\n bar |- foo \n"), TagOpenClose(wiki_markup="|}"), Text(text="table"), TagCloseClose()]
output: [TagOpenOpen(wiki_markup="{|"), Text(text="table"), TagCloseOpen(padding="\n"), Text(text=" bar |- foo \n"), TagOpenClose(wiki_markup="|}"), Text(text="table"), TagCloseClose()]


--- ---


name: template_inside_table_cell name: template_inside_table_cell
label: Template within table cell. label: Template within table cell.
input: "{|\n |{{foo\n|bar=baz}} \n|}" input: "{|\n |{{foo\n|bar=baz}} \n|}"
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(wiki_markup="|}"), Text(text="table"), TagCloseClose()]
output: [TagOpenOpen(wiki_markup="{|"), Text(text="table"), TagCloseOpen(padding="\n"), Text(text=" "), 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(wiki_markup="|}"), Text(text="table"), TagCloseClose()]


--- ---


name: table_cell_attributes name: table_cell_attributes
label: Parse table cell style attributes. label: Parse table cell style attributes.
input: "{| \n | name="foo bar"| test \n|}" input: "{| \n | name="foo bar"| test \n|}"
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(wiki_markup="|}"), Text(text="table"), TagCloseClose()]
output: [TagOpenOpen(wiki_markup="{|"), Text(text="table"), TagCloseOpen(padding=" \n"), Text(text=" "), 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(wiki_markup="|"), Text(text=" test \n"), TagOpenClose(wiki_markup="|}"), Text(text="table"), TagCloseClose()]


--- ---


name: table_cell_attributes_quote_with_pipe name: table_cell_attributes_quote_with_pipe
label: Pipe inside an attribute quote should still be used as a style separator. label: Pipe inside an attribute quote should still be used as a style separator.
input: "{| \n | name="foo|bar"| test \n|}" input: "{| \n | name="foo|bar"| test \n|}"
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(wiki_markup="|}"), Text(text="table"), TagCloseClose()]
output: [TagOpenOpen(wiki_markup="{|"), Text(text="table"), TagCloseOpen(padding=" \n"), Text(text=" "), 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(wiki_markup="|"), Text(text="bar\"| test \n"), TagOpenClose(wiki_markup="|}"), Text(text="table"), TagCloseClose()]


--- ---


name: table_cell_attributes_name_with_pipe name: table_cell_attributes_name_with_pipe
label: Pipe inside an attribute name should still be used as a style separator. label: Pipe inside an attribute name should still be used as a style separator.
input: "{| \n | name|="foo bar"| test \n|}" input: "{| \n | name|="foo bar"| test \n|}"
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(wiki_markup="|}"), Text(text="table"), TagCloseClose()]
output: [TagOpenOpen(wiki_markup="{|"), Text(text="table"), TagCloseOpen(padding=" \n"), Text(text="" "), TagOpenOpen(wiki_markup="|"), Text(text="td"), TagAttrStart(pad_first=" ", pad_before_eq="", pad_after_eq=""), Text(text="name"), TagCloseSelfclose(wiki_markup="|"), Text(text="=\"foo bar\"| test \n"), TagOpenClose(wiki_markup="|}"), Text(text="table"), TagCloseClose()]


--- ---


name: table_cell_attributes_pipe_after_equals name: table_cell_attributes_pipe_after_equals
label: Pipe inside an attribute should still be used as a style separator after an equals. label: Pipe inside an attribute should still be used as a style separator after an equals.
input: "{| \n | name=|"foo|bar"| test \n|}" input: "{| \n | name=|"foo|bar"| test \n|}"
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(wiki_markup="|}"), Text(text="table"), TagCloseClose()]
output: [TagOpenOpen(wiki_markup="{|"), Text(text="table"), TagCloseOpen(padding=" \n"), Text(text=" "), TagOpenOpen(wiki_markup="|"), Text(text="td"), TagAttrStart(pad_first=" ", pad_before_eq="", pad_after_eq=""), Text(text="name"), TagAttrEquals(), TagCloseSelfclose(wiki_markup="|"), Text(text="\"foo|bar\"| test \n"), TagOpenClose(wiki_markup="|}"), Text(text="table"), TagCloseClose()]


--- ---


name: table_cell_attributes_templates name: table_cell_attributes_templates
label: Pipe inside attributes shouldn't be style separator. label: Pipe inside attributes shouldn't be style separator.
input: "{| \n | {{comment|template=baz}} | test \n|}" input: "{| \n | {{comment|template=baz}} | test \n|}"
output: [TagOpenOpen(wiki_markup="{|"), Text(text="table"), TagCloseOpen(), Text(text=" \n "), TagOpenOpen(wiki_markup="|"), Text(text="td"), TagAttrStart(pad_after_eq="", pad_first=" ", pad_before_eq=" "), TemplateOpen(), Text(text="comment"), TemplateParamSeparator(), Text(text="template"), TemplateParamEquals(), Text(text="baz"), TemplateClose(), TagCloseSelfclose(), Text(text=" test \n"), TagOpenClose(wiki_markup="|}"), Text(text="table"), TagCloseClose()]
output: [TagOpenOpen(wiki_markup="{|"), Text(text="table"), TagCloseOpen(padding=" \n"), Text(text=" "), TagOpenOpen(wiki_markup="|"), Text(text="td"), TagAttrStart(pad_after_eq="", pad_first=" ", pad_before_eq=" "), TemplateOpen(), Text(text="comment"), TemplateParamSeparator(), Text(text="template"), TemplateParamEquals(), Text(text="baz"), TemplateClose(), TagCloseSelfclose(wiki_markup="|"), Text(text=" test \n"), TagOpenClose(wiki_markup="|}"), Text(text="table"), TagCloseClose()]

---

name: header_cell_attributes
label: Parse header cell style attributes.
input: "{| \n ! name="foo bar"| test \n|}"
output: [TagOpenOpen(wiki_markup="{|"), Text(text="table"), TagCloseOpen(padding=" \n"), Text(text=" "), TagOpenOpen(wiki_markup="!"), Text(text="th"), TagAttrStart(pad_first=" ", pad_before_eq="", pad_after_eq=""), Text(text="name"), TagAttrEquals(), TagAttrQuote(char="\""), Text(text="foo bar"), TagCloseSelfclose(wiki_markup="|"), Text(text=" test \n"), TagOpenClose(wiki_markup="|}"), Text(text="table"), TagCloseClose()]

---

name: inline_cell_attributes
label: Parse cell style attributes of inline cells.
input: "{| \n ! name="foo bar" | test ||color="red"| markup!!foo | time \n|}"
output: [TagOpenOpen(wiki_markup="{|"), Text(text="table"), TagCloseOpen(padding=" \n"), Text(text=" "), TagOpenOpen(wiki_markup="!"), Text(text="th"), TagAttrStart(pad_after_eq="", pad_first=" ", pad_before_eq=""), Text(text="name"), TagAttrEquals(), TagAttrQuote(char="\""), Text(text="foo bar"), TagCloseSelfclose(wiki_markup="|"), Text(text=" test "), TagOpenOpen(wiki_markup="||"), Text(text="th"), TagAttrStart(pad_first="", pad_before_eq="", pad_after_eq=""), Text(text="color"), TagAttrEquals(), TagAttrQuote(char="\""), Text(text="red"), TagCloseSelfclose(wiki_markup="|"), Text(text=" markup"), TagOpenOpen(wiki_markup="!!"), Text(text="th"), TagAttrStart(pad_first="", pad_before_eq=" ", pad_after_eq=""), Text(text="foo"), TagCloseSelfclose(wiki_markup="|"), Text(text=" time \n"), TagOpenClose(wiki_markup="|}"), Text(text="table"), TagCloseClose()]


--- ---


name: table_row_attributes name: table_row_attributes
label: Parse table row style attributes. label: Parse table row style attributes.
input: "{| \n |- name="foo bar"\n|}" input: "{| \n |- name="foo bar"\n|}"
output: [TagOpenOpen(wiki_markup="{|"), Text(text="table"), TagCloseOpen(), Text(text=" \n "), TagOpenOpen(wiki_markup="|-"), Text(text="tr"), TagAttrStart(pad_first=" ", pad_before_eq="", pad_after_eq=""), Text(text="name"), TagAttrEquals(), TagAttrQuote(char="\""), Text(text="foo bar"), TagCloseSelfclose(), Text(text="\n"), TagOpenClose(wiki_markup="|}"), Text(text="table"), TagCloseClose()]
output: [TagOpenOpen(wiki_markup="{|"), Text(text="table"), TagCloseOpen(padding=" \n"), Text(text=" "), TagOpenOpen(wiki_markup="|-"), Text(text="tr"), TagAttrStart(pad_first=" ", pad_before_eq="", pad_after_eq=""), Text(text="name"), TagAttrEquals(), TagAttrQuote(char="\""), Text(text="foo bar"), TagCloseSelfclose(padding="\n"), TagOpenClose(wiki_markup="|}"), Text(text="table"), TagCloseClose()]


--- ---


name: table_row_attributes_crazy_whitespace name: table_row_attributes_crazy_whitespace
label: Parse table row style attributes with different whitespace. label: Parse table row style attributes with different whitespace.
input: "{| \t \n |- \t name="foo bar"\n|}"
output: [TagOpenOpen(wiki_markup="{|"), Text(text="table"), TagCloseOpen(), Text(text=" \t \n "), TagOpenOpen(wiki_markup="|-"), Text(text="tr"), TagAttrStart(pad_first=" \t ", pad_before_eq="", pad_after_eq=""), Text(text="name"), TagAttrEquals(), TagAttrQuote(char="\""), Text(text="foo bar"), TagCloseSelfclose(), Text(text="\n"), TagOpenClose(wiki_markup="|}"), Text(text="table"), TagCloseClose()]
input: "{| \t \n |- \t name="foo bar" \t \n|}"
output: [TagOpenOpen(wiki_markup="{|"), Text(text="table"), TagCloseOpen(" \t \n"), Text(text=" "), TagOpenOpen(wiki_markup="|-"), Text(text="tr"), TagAttrStart(pad_first=" \t ", pad_before_eq="", pad_after_eq=""), Text(text="name"), TagAttrEquals(), TagAttrQuote(char="\""), Text(text="foo bar"), TagCloseSelfclose(padding=" \t \n"), TagOpenClose(wiki_markup="|}"), Text(text="table"), TagCloseClose()]




--- ---
@@ -163,4 +177,11 @@ output: [TagOpenOpen(wiki_markup="{|"), Text(text="table"), TagCloseOpen(), Text
name: table_attributes name: table_attributes
label: Parse table style attributes. label: Parse table style attributes.
input: "{| name="foo bar"\n|}" input: "{| name="foo bar"\n|}"
output: [TagOpenOpen(wiki_markup="{|"), Text(text="table"),TagAttrStart(pad_first=" ", pad_before_eq="", pad_after_eq=""), Text(text="name"), TagAttrEquals(), TagAttrQuote(char="\""), Text(text="foo bar"), TagCloseOpen(), Text(text="\n"), TagOpenClose(wiki_markup="|}"), Text(text="table"), TagCloseClose()]
output: [TagOpenOpen(wiki_markup="{|"), Text(text="table"), TagAttrStart(pad_first=" ", pad_before_eq="", pad_after_eq=""), Text(text="name"), TagAttrEquals(), TagAttrQuote(char="\""), Text(text="foo bar"), TagCloseOpen(padding="\n"), TagOpenClose(wiki_markup="|}"), Text(text="table"), TagCloseClose()]

---

name: inline_table_attributes
label: Correctly handle attributes in inline tables.
input: "{| foo="tee bar" |}"
output: [TagOpenOpen(wiki_markup="{|"), Text(text="table"),TagAttrStart(pad_first=" ", pad_before_eq="", pad_after_eq=""), Text(text="foo"), TagAttrEquals(), TagAttrQuote(char="\""), Text(text="tee bar"), TagCloseOpen(padding=" "), TagOpenClose(wiki_markup="|}"), Text(text="table"), TagCloseClose()]

Loading…
Cancel
Save