From d2cc56a46a5a3c657429e8df5b93c82f3f9ed9fb Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Sun, 22 Jul 2012 22:09:15 -0700 Subject: Revised code for pipe tables. * All tables now require at least one body row. * Renamed from 'extra' to 'pipe' tables. * Moved functions from Parsing to Readers.Markdown. * Cleaned up code; revised to parse in one pass rather than parsing a raw string, splitting it, and parsing the components. * Allow pipe tables without pipes on the ends (as PHP Markdown Extra does). --- tests/extra-tables.markdown | 34 ---------------------- tests/extra-tables.native | 60 -------------------------------------- tests/pipe-tables.native | 70 +++++++++++++++++++++++++++++++++++++++++++++ tests/pipe-tables.txt | 42 +++++++++++++++++++++++++++ 4 files changed, 112 insertions(+), 94 deletions(-) delete mode 100644 tests/extra-tables.markdown delete mode 100644 tests/extra-tables.native create mode 100644 tests/pipe-tables.native create mode 100644 tests/pipe-tables.txt (limited to 'tests') diff --git a/tests/extra-tables.markdown b/tests/extra-tables.markdown deleted file mode 100644 index 69a18113b..000000000 --- a/tests/extra-tables.markdown +++ /dev/null @@ -1,34 +0,0 @@ -Simplest table without caption: - -| Default1 | Default2 | Default3 | -|----------|----------|----------| -|12|12|12| -|123|123|123| -|1|1|1| - -Simple table with caption: - -| Right | Left | Default | Center | -|------:|:-----|---------|:------:| -| 12 | 12 | 12 | 12 | -| 123 | 123 | 123 | 123 | -| 1 | 1 | 1 | 1 | - - : Demonstration of simple table syntax. - -Simple table without caption: - -| Right | Left | Center | -|------:|:-----|:------:| -|12|12|12| -|123|123|123| -|1|1|1| - - -Headerless table without caption: - -|------:|:-----|:------:| -|12|12|12| -|123|123|123| -|1|1|1| - diff --git a/tests/extra-tables.native b/tests/extra-tables.native deleted file mode 100644 index f9580a8cb..000000000 --- a/tests/extra-tables.native +++ /dev/null @@ -1,60 +0,0 @@ -[Para [Str "Simplest",Space,Str "table",Space,Str "without",Space,Str "caption",Str ":"] -,Table [] [AlignDefault,AlignDefault,AlignDefault] [0.0,0.0,0.0] - [[Plain [Str "Default1"]] - ,[Plain [Str "Default2"]] - ,[Plain [Str "Default3"]]] - [[[Plain [Str "12"]] - ,[Plain [Str "12"]] - ,[Plain [Str "12"]]] - ,[[Plain [Str "123"]] - ,[Plain [Str "123"]] - ,[Plain [Str "123"]]] - ,[[Plain [Str "1"]] - ,[Plain [Str "1"]] - ,[Plain [Str "1"]]]] -,Para [Str "Simple",Space,Str "table",Space,Str "with",Space,Str "caption",Str ":"] -,Table [Str "Demonstration",Space,Str "of",Space,Str "simple",Space,Str "table",Space,Str "syntax",Str "."] [AlignRight,AlignLeft,AlignDefault,AlignCenter] [0.0,0.0,0.0,0.0] - [[Plain [Str "Right"]] - ,[Plain [Str "Left"]] - ,[Plain [Str "Default"]] - ,[Plain [Str "Center"]]] - [[[Plain [Str "12"]] - ,[Plain [Str "12"]] - ,[Plain [Str "12"]] - ,[Plain [Str "12"]]] - ,[[Plain [Str "123"]] - ,[Plain [Str "123"]] - ,[Plain [Str "123"]] - ,[Plain [Str "123"]]] - ,[[Plain [Str "1"]] - ,[Plain [Str "1"]] - ,[Plain [Str "1"]] - ,[Plain [Str "1"]]]] -,Para [Str "Simple",Space,Str "table",Space,Str "without",Space,Str "caption",Str ":"] -,Table [] [AlignRight,AlignLeft,AlignCenter] [0.0,0.0,0.0] - [[Plain [Str "Right"]] - ,[Plain [Str "Left"]] - ,[Plain [Str "Center"]]] - [[[Plain [Str "12"]] - ,[Plain [Str "12"]] - ,[Plain [Str "12"]]] - ,[[Plain [Str "123"]] - ,[Plain [Str "123"]] - ,[Plain [Str "123"]]] - ,[[Plain [Str "1"]] - ,[Plain [Str "1"]] - ,[Plain [Str "1"]]]] -,Para [Str "Headerless",Space,Str "table",Space,Str "without",Space,Str "caption",Str ":"] -,Table [] [AlignRight,AlignLeft,AlignCenter] [0.0,0.0,0.0] - [[] - ,[] - ,[]] - [[[Plain [Str "12"]] - ,[Plain [Str "12"]] - ,[Plain [Str "12"]]] - ,[[Plain [Str "123"]] - ,[Plain [Str "123"]] - ,[Plain [Str "123"]]] - ,[[Plain [Str "1"]] - ,[Plain [Str "1"]] - ,[Plain [Str "1"]]]]] diff --git a/tests/pipe-tables.native b/tests/pipe-tables.native new file mode 100644 index 000000000..2826c7236 --- /dev/null +++ b/tests/pipe-tables.native @@ -0,0 +1,70 @@ +[Para [Str "Simplest",Space,Str "table",Space,Str "without",Space,Str "caption",Str ":"] +,Table [] [AlignDefault,AlignDefault,AlignDefault] [0.0,0.0,0.0] + [[Plain [Str "Default1"]] + ,[Plain [Str "Default2"]] + ,[Plain [Str "Default3"]]] + [[[Plain [Str "12"]] + ,[Plain [Str "12"]] + ,[Plain [Str "12"]]] + ,[[Plain [Str "123"]] + ,[Plain [Str "123"]] + ,[Plain [Str "123"]]] + ,[[Plain [Str "1"]] + ,[Plain [Str "1"]] + ,[Plain [Str "1"]]]] +,Para [Str "Simple",Space,Str "table",Space,Str "with",Space,Str "caption",Str ":"] +,Table [Str "Demonstration",Space,Str "of",Space,Str "simple",Space,Str "table",Space,Str "syntax",Str "."] [AlignRight,AlignLeft,AlignDefault,AlignCenter] [0.0,0.0,0.0,0.0] + [[Plain [Str "Right"]] + ,[Plain [Str "Left"]] + ,[Plain [Str "Default"]] + ,[Plain [Str "Center"]]] + [[[Plain [Str "12"]] + ,[Plain [Str "12"]] + ,[Plain [Str "12"]] + ,[Plain [Str "12"]]] + ,[[Plain [Str "123"]] + ,[Plain [Str "123"]] + ,[Plain [Str "123"]] + ,[Plain [Str "123"]]] + ,[[Plain [Str "1"]] + ,[Plain [Str "1"]] + ,[Plain [Str "1"]] + ,[Plain [Str "1"]]]] +,Para [Str "Simple",Space,Str "table",Space,Str "without",Space,Str "caption",Str ":"] +,Table [] [AlignRight,AlignLeft,AlignCenter] [0.0,0.0,0.0] + [[Plain [Str "Right"]] + ,[Plain [Str "Left"]] + ,[Plain [Str "Center"]]] + [[[Plain [Str "12"]] + ,[Plain [Str "12"]] + ,[Plain [Str "12"]]] + ,[[Plain [Str "123"]] + ,[Plain [Str "123"]] + ,[Plain [Str "123"]]] + ,[[Plain [Str "1"]] + ,[Plain [Str "1"]] + ,[Plain [Str "1"]]]] +,Para [Str "Headerless",Space,Str "table",Space,Str "without",Space,Str "caption",Str ":"] +,Table [] [AlignRight,AlignLeft,AlignCenter] [0.0,0.0,0.0] + [[] + ,[] + ,[]] + [[[Plain [Str "12"]] + ,[Plain [Str "12"]] + ,[Plain [Str "12"]]] + ,[[Plain [Str "123"]] + ,[Plain [Str "123"]] + ,[Plain [Str "123"]]] + ,[[Plain [Str "1"]] + ,[Plain [Str "1"]] + ,[Plain [Str "1"]]]] +,Para [Str "Table",Space,Str "without",Space,Str "sides",Str ":"] +,Table [] [AlignDefault,AlignRight] [0.0,0.0] + [[Plain [Str "Fruit"]] + ,[Plain [Str "Quantity"]]] + [[[Plain [Str "apple"]] + ,[Plain [Str "5"]]] + ,[[Plain [Str "orange"]] + ,[Plain [Str "17"]]] + ,[[Plain [Str "pear"]] + ,[Plain [Str "302"]]]]] diff --git a/tests/pipe-tables.txt b/tests/pipe-tables.txt new file mode 100644 index 000000000..929038ebb --- /dev/null +++ b/tests/pipe-tables.txt @@ -0,0 +1,42 @@ +Simplest table without caption: + +| Default1 | Default2 | Default3 | +|----------|----------|----------| +|12|12|12| +|123|123|123| +|1|1|1| + +Simple table with caption: + +| Right | Left | Default | Center | +|------:|:-----|---------|:------:| +| 12 | 12 | 12 | 12 | +| 123 | 123 | 123 | 123 | +| 1 | 1 | 1 | 1 | + + : Demonstration of simple table syntax. + +Simple table without caption: + +| Right | Left | Center | +|------:|:-----|:------:| +|12|12|12| +|123|123|123| +|1|1|1| + + +Headerless table without caption: + +|------:|:-----|:------:| +|12|12|12| +|123|123|123| +|1|1|1| + +Table without sides: + +Fruit |Quantity +------|-------: +apple | 5 +orange| 17 +pear | 302 + -- cgit v1.2.3