From 5986bc3651f2d24f23c68d6323f4b26a6aad4c21 Mon Sep 17 00:00:00 2001 From: Jarno Elovirta Date: Sun, 5 Nov 2023 18:45:35 +0200 Subject: [PATCH 1/8] Initial support for table block content Signed-off-by: Jarno Elovirta --- src/main/resources/ast2markdown.xsl | 52 +++++++++++++++++++ .../dita/markdown/AstToMarkdownTest.java | 5 +- src/test/resources/output/ast/table-block.xml | 1 + .../resources/output/markdown/table-block.md | 42 +++++++++++++++ 4 files changed, 99 insertions(+), 1 deletion(-) create mode 100644 src/test/resources/output/ast/table-block.xml create mode 100644 src/test/resources/output/markdown/table-block.md diff --git a/src/main/resources/ast2markdown.xsl b/src/main/resources/ast2markdown.xsl index dcae2f70..5e320bc8 100644 --- a/src/main/resources/ast2markdown.xsl +++ b/src/main/resources/ast2markdown.xsl @@ -219,6 +219,58 @@ + + <table> + + <thead> + + <tr> + + <th> + + + + + + + + + + + + </th> + + </tr> + + </thead> + + + <tbody> + + <tr> + + <td> + + + + + + + + + + + + </td> + + </tr> + + <tbody> + + </table> + + + diff --git a/src/test/java/com/elovirta/dita/markdown/AstToMarkdownTest.java b/src/test/java/com/elovirta/dita/markdown/AstToMarkdownTest.java index d06de9dc..46ef9d80 100644 --- a/src/test/java/com/elovirta/dita/markdown/AstToMarkdownTest.java +++ b/src/test/java/com/elovirta/dita/markdown/AstToMarkdownTest.java @@ -1,9 +1,11 @@ package com.elovirta.dita.markdown; import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import com.elovirta.dita.utils.ClasspathURIResolver; import java.io.*; +import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Paths; import javax.xml.transform.Transformer; @@ -55,6 +57,7 @@ public class AstToMarkdownTest { "reference", "short", "shortdesc", + "table-block", "table-width", "table", "task", @@ -71,7 +74,7 @@ public class AstToMarkdownTest { public void testAst(String name) throws Exception { final byte[] act = run("output/ast/" + name + ".xml"); final byte[] exp = read("output/markdown/" + name + ".md"); - assertArrayEquals(exp, act); + assertEquals(new String(exp, StandardCharsets.UTF_8), new String(act, StandardCharsets.UTF_8)); } private byte[] run(final String input) throws Exception { diff --git a/src/test/resources/output/ast/table-block.xml b/src/test/resources/output/ast/table-block.xml new file mode 100644 index 00000000..93abbba0 --- /dev/null +++ b/src/test/resources/output/ast/table-block.xml @@ -0,0 +1 @@ +
Table with block content
ABCA1A1B1B1C1C1A2B2C2
\ No newline at end of file diff --git a/src/test/resources/output/markdown/table-block.md b/src/test/resources/output/markdown/table-block.md new file mode 100644 index 00000000..c7a8a30d --- /dev/null +++ b/src/test/resources/output/markdown/table-block.md @@ -0,0 +1,42 @@ +# Table with block content {#tables} + +
+ +A + + +B + + +C +
+ +A1 + +A1 + + + +B1 + +B1 + + + +C1 + +C1 + +
+ +A2 + + + +B2 + + + +C2 + +
From 30fc0393ca153ceef34e4bdafa199b7ffb83810f Mon Sep 17 00:00:00 2001 From: Jarno Elovirta Date: Sun, 5 Nov 2023 20:32:20 +0200 Subject: [PATCH 2/8] Add DITA to AST to test table block Signed-off-by: Jarno Elovirta --- .../dita/markdown/AstToMarkdownTest.java | 1 - .../elovirta/dita/markdown/DitaToAstTest.java | 1 + src/test/resources/dita/table-block.dita | 51 +++++++++++++++++++ 3 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 src/test/resources/dita/table-block.dita diff --git a/src/test/java/com/elovirta/dita/markdown/AstToMarkdownTest.java b/src/test/java/com/elovirta/dita/markdown/AstToMarkdownTest.java index 46ef9d80..cd1ba9ee 100644 --- a/src/test/java/com/elovirta/dita/markdown/AstToMarkdownTest.java +++ b/src/test/java/com/elovirta/dita/markdown/AstToMarkdownTest.java @@ -1,6 +1,5 @@ package com.elovirta.dita.markdown; -import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; import com.elovirta.dita.utils.ClasspathURIResolver; diff --git a/src/test/java/com/elovirta/dita/markdown/DitaToAstTest.java b/src/test/java/com/elovirta/dita/markdown/DitaToAstTest.java index 6196ec04..61619f5e 100644 --- a/src/test/java/com/elovirta/dita/markdown/DitaToAstTest.java +++ b/src/test/java/com/elovirta/dita/markdown/DitaToAstTest.java @@ -77,6 +77,7 @@ public DitaToAstTest() { "reference", "short", "shortdesc", + "table-block", "table-width", "table", "task", diff --git a/src/test/resources/dita/table-block.dita b/src/test/resources/dita/table-block.dita new file mode 100644 index 00000000..028201e4 --- /dev/null +++ b/src/test/resources/dita/table-block.dita @@ -0,0 +1,51 @@ + + + Table with block content + + + + + + + + + A + B + C + + + + + +

A1

+

A1

+
+ +

B1

+

B1

+
+ +

C1

+

C1

+
+
+ + +

A2

+
+ +

B2

+
+ +

C2

+
+
+ + +
+ +
\ No newline at end of file From abef06452f56816b338c592e01b346ceb8e4e3af Mon Sep 17 00:00:00 2001 From: Jarno Elovirta Date: Sun, 5 Nov 2023 20:41:38 +0200 Subject: [PATCH 3/8] Add spanning to block table test Signed-off-by: Jarno Elovirta --- src/main/resources/ast2markdown.xsl | 50 +++++++++++++++++-- src/test/resources/dita/table-block.dita | 25 ++++++++-- src/test/resources/output/ast/table-block.xml | 2 +- .../resources/output/markdown/table-block.md | 24 +++++++-- 4 files changed, 88 insertions(+), 13 deletions(-) diff --git a/src/main/resources/ast2markdown.xsl b/src/main/resources/ast2markdown.xsl index 5e320bc8..29c073fa 100644 --- a/src/main/resources/ast2markdown.xsl +++ b/src/main/resources/ast2markdown.xsl @@ -222,11 +222,35 @@ <table> - <thead> + <thead + + + + =" + + " + + > - <tr> + <tr + + + + =" + + " + + > - <th> + <th + + + + =" + + " + + > @@ -247,9 +271,25 @@ <tbody> - <tr> + <tr + + + + =" + + " + + > - <td> + <td + + + + =" + + " + + > diff --git a/src/test/resources/dita/table-block.dita b/src/test/resources/dita/table-block.dita index 028201e4..08cc3156 100644 --- a/src/test/resources/dita/table-block.dita +++ b/src/test/resources/dita/table-block.dita @@ -34,18 +34,35 @@ - +

A2

- +

B2

- +

C2

+ + +

A3

+

B3

+
+ +

C3

+
+
+ + +

A2

+
+ +

B2

+
+
- \ No newline at end of file + diff --git a/src/test/resources/output/ast/table-block.xml b/src/test/resources/output/ast/table-block.xml index 93abbba0..9c338816 100644 --- a/src/test/resources/output/ast/table-block.xml +++ b/src/test/resources/output/ast/table-block.xml @@ -1 +1 @@ -
Table with block content
ABCA1A1B1B1C1C1A2B2C2
\ No newline at end of file +
Table with block content
ABCA1 A1B1 B1C1 C1A2B2C2A3 B3C3A2B2
\ No newline at end of file diff --git a/src/test/resources/output/markdown/table-block.md b/src/test/resources/output/markdown/table-block.md index c7a8a30d..a347a911 100644 --- a/src/test/resources/output/markdown/table-block.md +++ b/src/test/resources/output/markdown/table-block.md @@ -13,19 +13,19 @@ C A1 -A1 + A1 B1 -B1 + B1 C1 -C1 + C1 @@ -39,4 +39,22 @@ B2 C2 + + +A3 + + B3 + + + +C3 + + + +A2 + + + +B2 + From 2f1823090c45f5b5b11df306c7f7d72fcb20e2b7 Mon Sep 17 00:00:00 2001 From: Jarno Elovirta Date: Mon, 6 Nov 2023 21:18:08 +0200 Subject: [PATCH 4/8] Add align attribute to AST Signed-off-by: Jarno Elovirta --- src/main/resources/tables.xsl | 3 + src/test/resources/dita/table-block.dita | 8 +- src/test/resources/output/ast/ast.xml | 85 +++++----- src/test/resources/output/ast/table-block.xml | 2 +- src/test/resources/output/ast/table.xml | 160 +++++++++++++++++- .../resources/output/markdown/table-block.md | 18 +- 6 files changed, 223 insertions(+), 53 deletions(-) diff --git a/src/main/resources/tables.xsl b/src/main/resources/tables.xsl index e1211d9d..4bce9c9c 100644 --- a/src/main/resources/tables.xsl +++ b/src/main/resources/tables.xsl @@ -120,6 +120,9 @@ + + + diff --git a/src/test/resources/dita/table-block.dita b/src/test/resources/dita/table-block.dita index 08cc3156..f93daefd 100644 --- a/src/test/resources/dita/table-block.dita +++ b/src/test/resources/dita/table-block.dita @@ -54,11 +54,11 @@ - -

A2

+ +

A4

- -

B2

+ +

B4

diff --git a/src/test/resources/output/ast/ast.xml b/src/test/resources/output/ast/ast.xml index 02800e7f..e9f4f4d7 100644 --- a/src/test/resources/output/ast/ast.xml +++ b/src/test/resources/output/ast/ast.xml @@ -1,14 +1,14 @@ -
Test
Paragraph test and list list list list list list list list list list list list list - list list list list list list list list list list or code. This is a very long line. - This is a very long line. This is a very long line. This is a very long line. This is a very long line. This is - a very long line. This is a very long line. This is a very long line. This is a very long line. This is a very - long line. This is a very long line. + list list list list list list list list list list + or code. This is a very long line. This is a very long line. This is a very long line. This + is a very long line. This is a very long line. This is a very long line. This is a very long line. This is a + very long line. This is a very long line. This is a very long line. This is a very long line. + Paragraph with block content codeblock codeblock @@ -20,16 +20,20 @@ codeblock Asterisk \* bracket \[foo\]. - \\\`\*\_\{\}\[\]\(\)\>\#+-.!<> + \\\`\*\_\{\}\[\]\(\)\>\#+-.!<> Hyphen:
  • hyphen list list list list list list list list list list list list list list list list list list list - list list list list + list list list list +
  • - start with inline - elements + + start + with inline + elements + para
  • @@ -57,7 +61,8 @@ codeblock Asterix:
  • - inline bold normal + inline bold normal +
  • inline @@ -156,7 +161,8 @@ codeblock
    Example
    - Code example on for loop: + Code example on for loop: + for i in items: println(i) @@ -168,7 +174,8 @@ codeblock
    Images
    - An inline Alt. + An inline Alt. + Alt @@ -223,30 +230,30 @@ codeblock - Right - Left + Right + Left Default - Center + Center + 12 + 12 12 - 12 - 12 - 12 + 12 + 123 + 123 123 - 123 - 123 - 123 + 123 + 1 + 1 1 - 1 - 1 - 1 + 1 @@ -257,27 +264,29 @@ codeblock - First Header - Second Header Very long data entry Very long data entry Very long data entry Very long data - entry Very long data entry Very long data entry Very long data entry Very long data entry Very long data - entry - Third Header + First Header + Second Header Very long data entry Very long data entry Very long data entry + Very long data entry Very long data entry Very long data entry Very long data entry Very long data entry + Very long data entry + + Third Header - First row - Data - Very long data entry Very long data entry Very long data entry Very long data entry Very long - data entry Very long data entry Very long data entry Very long data entry Very long data entry Very long - data entry + First row + Data + Very long data entry Very long data entry Very long data entry Very long data + entry Very long data entry Very long data entry Very long data entry Very long data entry Very long data + entry Very long data entry + - Second row - + Second row + Cell - + Cell @@ -322,4 +331,4 @@ codeblock
    - + \ No newline at end of file diff --git a/src/test/resources/output/ast/table-block.xml b/src/test/resources/output/ast/table-block.xml index 9c338816..74952b08 100644 --- a/src/test/resources/output/ast/table-block.xml +++ b/src/test/resources/output/ast/table-block.xml @@ -1 +1 @@ -
    Table with block content
    ABCA1 A1B1 B1C1 C1A2B2C2A3 B3C3A2B2
    \ No newline at end of file +
    Table with block content
    ABCA1A1B1B1C1C1A2B2C2A3B3C3A4B4
    \ No newline at end of file diff --git a/src/test/resources/output/ast/table.xml b/src/test/resources/output/ast/table.xml index eddbdee5..2cce7ae9 100644 --- a/src/test/resources/output/ast/table.xml +++ b/src/test/resources/output/ast/table.xml @@ -1 +1,159 @@ -
    Tables
    RightLeftDefaultCenter121212121231231231231111
    First HeaderSecond HeaderThird HeaderFirst rowDataVery long data entrySecond rowCellCell
    Table 1. simple_table
    PHP Table:First HeaderSecond Header Very long data entry Very long data entry Very long data entry Very long data entry Very long data entry Very long data entry Very long data entry Very long data entry Very long data entryThird HeaderFirst rowDataVery long data entry Very long data entry Very long data entry Very long data entry Very long data entry Very long data entry Very long data entry Very long data entry Very long data entry Very long data entrySecond rowCellCell
    ABCA1B1C1A2B2A3A4C4
    ABCA5A6A7
    \ No newline at end of file + + +
    +
    Tables
    +
    + + + + + + + + Right + Left + Default + Center + + + + + 12 + 12 + 12 + 12 + + + 123 + 123 + 123 + 123 + + + 1 + 1 + 1 + 1 + + +
    + + + + + + + + First Header + Second Header + Third Header + + + + + First row + Data + Very long data entry + + + Second row + + Cell + + + Cell + + + +
    + Table 1. simple_table +
    + PHP Table: + + + + + + + First Header + Second Header Very long data entry Very long data entry Very long data entry Very + long data entry Very long data entry Very long data entry Very long data entry Very long data entry Very + long data entry + + Third Header + + + + + First row + Data + Very long data entry Very long data entry Very long data entry Very long data entry + Very long data entry Very long data entry Very long data entry Very long data entry Very long data entry + Very long data entry + + + + Second row + + Cell + + + Cell + + + +
    + + + + + + + A + B + C + + + + + A1 + B1 + C1 + + + A2 + B2 + + + A3 + + + A4 + C4 + + +
    + + + + + + + A + B + C + + + + + A5 + + + A6 + A7 + + +
    +
    +
    +
    \ No newline at end of file diff --git a/src/test/resources/output/markdown/table-block.md b/src/test/resources/output/markdown/table-block.md index a347a911..4d92cf47 100644 --- a/src/test/resources/output/markdown/table-block.md +++ b/src/test/resources/output/markdown/table-block.md @@ -13,29 +13,29 @@ C A1 - A1 +A1 B1 - B1 +B1 C1 - C1 +C1 - + A2 - + B2 - + C2 @@ -43,7 +43,7 @@ C2 A3 - B3 +B3 @@ -51,10 +51,10 @@ C3 -A2 +A4 -B2 +B4 From e96d35aafe3d51468d1b2431363229c25168f9f6 Mon Sep 17 00:00:00 2001 From: Jarno Elovirta Date: Thu, 9 Nov 2023 16:26:56 +0200 Subject: [PATCH 5/8] Add inline markup to tests Signed-off-by: Jarno Elovirta --- src/test/resources/dita/table-block.dita | 10 +++++----- src/test/resources/output/ast/table-block.xml | 2 +- .../resources/output/markdown/table-block.md | 16 ++++++++-------- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/test/resources/dita/table-block.dita b/src/test/resources/dita/table-block.dita index f93daefd..22b0588b 100644 --- a/src/test/resources/dita/table-block.dita +++ b/src/test/resources/dita/table-block.dita @@ -21,27 +21,27 @@ -

    A1

    +

    A1 bold

    A1

    B1

    -

    B1

    +

    bold B1

    -

    C1

    +

    C1

    C1

    -

    A2

    +

    A2 bold

    B2

    -

    C2

    +

    C2

    diff --git a/src/test/resources/output/ast/table-block.xml b/src/test/resources/output/ast/table-block.xml index 74952b08..e3686f42 100644 --- a/src/test/resources/output/ast/table-block.xml +++ b/src/test/resources/output/ast/table-block.xml @@ -1 +1 @@ -
    Table with block content
    ABCA1A1B1B1C1C1A2B2C2A3B3C3A4B4
    \ No newline at end of file +
    Table with block content
    ABCA1 bold A1B1 bold B1C1 C1A2 boldB2C2A3 B3C3A4B4
    \ No newline at end of file diff --git a/src/test/resources/output/markdown/table-block.md b/src/test/resources/output/markdown/table-block.md index 4d92cf47..db9471d9 100644 --- a/src/test/resources/output/markdown/table-block.md +++ b/src/test/resources/output/markdown/table-block.md @@ -11,25 +11,25 @@ B C -A1 +A1 **bold** -A1 + A1 B1 -B1 + **bold** B1 -C1 +**C1** -C1 + C1 -A2 +A2 **bold** @@ -37,13 +37,13 @@ B2 -C2 +**C2** A3 -B3 + B3 From 87942a60decd8ac0b75b6f26ea7e66c379af56b1 Mon Sep 17 00:00:00 2001 From: Jarno Elovirta Date: Sat, 23 Dec 2023 10:46:58 +0200 Subject: [PATCH 6/8] Use template to render HTML in Markdown Signed-off-by: Jarno Elovirta --- src/main/resources/ast2markdown.xsl | 165 +++++++++--------- .../resources/output/markdown/table-block.md | 3 +- 2 files changed, 80 insertions(+), 88 deletions(-) diff --git a/src/main/resources/ast2markdown.xsl b/src/main/resources/ast2markdown.xsl index 29c073fa..c6fc234a 100644 --- a/src/main/resources/ast2markdown.xsl +++ b/src/main/resources/ast2markdown.xsl @@ -219,96 +219,87 @@ - - <table> - - <thead - - - - =" - - " - - > - - <tr - - - - =" - - " - - > - - <th - - - - =" - - " - - > - - - - - - - - - - - - </th> - - </tr> - - </thead> + + < + + + + + =" + + " - - <tbody> - - <tr - - - - =" - - " + > + + </ + + > + + + + + + + + + + + + + + + + + + + + + + - > - - <td - - - - =" - - " - - > - - - - - - - - - - - - </td> + + + + + + + + + + + + - </tr> - - <tbody> - - </table> - + +
    + + + + + + + + + + + + +
    + + + + + + + + + + + + +
    +
    +
    diff --git a/src/test/resources/output/markdown/table-block.md b/src/test/resources/output/markdown/table-block.md index db9471d9..4c9a00df 100644 --- a/src/test/resources/output/markdown/table-block.md +++ b/src/test/resources/output/markdown/table-block.md @@ -57,4 +57,5 @@ A4 B4 - + + \ No newline at end of file From 664140aa482d7d4cf80300190ade3442be818699 Mon Sep 17 00:00:00 2001 From: Jarno Elovirta Date: Sun, 24 Dec 2023 12:03:31 +0200 Subject: [PATCH 7/8] Add space before td end tag Signed-off-by: Jarno Elovirta --- src/main/resources/ast2markdown.xsl | 48 ++++++++++++------- .../resources/output/markdown/table-block.md | 3 ++ 2 files changed, 35 insertions(+), 16 deletions(-) diff --git a/src/main/resources/ast2markdown.xsl b/src/main/resources/ast2markdown.xsl index c6fc234a..adc01ebc 100644 --- a/src/main/resources/ast2markdown.xsl +++ b/src/main/resources/ast2markdown.xsl @@ -255,15 +255,23 @@ - - - - + + + + + + - - - - + + + + + + + + + +
    @@ -281,15 +289,23 @@ - - - - + + + + + + - - - - + + + + + + + + + + diff --git a/src/test/resources/output/markdown/table-block.md b/src/test/resources/output/markdown/table-block.md index 4c9a00df..b938e954 100644 --- a/src/test/resources/output/markdown/table-block.md +++ b/src/test/resources/output/markdown/table-block.md @@ -3,12 +3,15 @@
    A + B + C +
    A1 **bold** From 02638919e2b2b1d700d1ccc6bc3bf40e6acb67c8 Mon Sep 17 00:00:00 2001 From: Jarno Elovirta Date: Mon, 25 Dec 2023 11:12:01 +0200 Subject: [PATCH 8/8] Support all AST block types Signed-off-by: Jarno Elovirta --- src/main/resources/ast2markdown.xsl | 2 +- src/test/resources/dita/table-block.dita | 6 ++++-- src/test/resources/output/ast/table-block.xml | 2 +- src/test/resources/output/markdown/table-block.md | 4 +++- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/main/resources/ast2markdown.xsl b/src/main/resources/ast2markdown.xsl index adc01ebc..5cebbd76 100644 --- a/src/main/resources/ast2markdown.xsl +++ b/src/main/resources/ast2markdown.xsl @@ -240,7 +240,7 @@ - + diff --git a/src/test/resources/dita/table-block.dita b/src/test/resources/dita/table-block.dita index 22b0588b..75aa2b24 100644 --- a/src/test/resources/dita/table-block.dita +++ b/src/test/resources/dita/table-block.dita @@ -55,10 +55,12 @@ -

    A4

    + A4
    -

    B4

    +
      +
    1. B4
    2. +
    diff --git a/src/test/resources/output/ast/table-block.xml b/src/test/resources/output/ast/table-block.xml index e3686f42..8710bf4b 100644 --- a/src/test/resources/output/ast/table-block.xml +++ b/src/test/resources/output/ast/table-block.xml @@ -1 +1 @@ -
    Table with block content
    ABCA1 bold A1B1 bold B1C1 C1A2 boldB2C2A3 B3C3A4B4
    \ No newline at end of file +
    Table with block content
    ABCA1 bold A1B1 bold B1C1 C1A2 boldB2C2A3 B3C3A4
  • B4
  • \ No newline at end of file diff --git a/src/test/resources/output/markdown/table-block.md b/src/test/resources/output/markdown/table-block.md index b938e954..43f8e09a 100644 --- a/src/test/resources/output/markdown/table-block.md +++ b/src/test/resources/output/markdown/table-block.md @@ -54,11 +54,13 @@ C3
    +``` A4 +``` -B4 +1. B4
    \ No newline at end of file