Skip to content

Commit

Permalink
Add test for AST to Markdown
Browse files Browse the repository at this point in the history
Signed-off-by: Jarno Elovirta <jarno@elovirta.com>
  • Loading branch information
jelovirt committed Nov 4, 2023
1 parent 7f092f9 commit 49c01fb
Show file tree
Hide file tree
Showing 65 changed files with 1,578 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
build/
src/main/resources/dita2markdown.xsl
src/main/resources/map2markdown-cover.xsl
out
/out
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ public Source resolve(String href, String base) throws TransformerException {
resource = res.getPath().substring(1);
}
final InputStream in = this.getClass().getClassLoader().getResourceAsStream(resource);
System.out.println("Resolved " + resource + ": " + in);
if (in != null) {
return new StreamSource(in, res.toString());
} else {
Expand Down
84 changes: 80 additions & 4 deletions src/test/java/com/elovirta/dita/markdown/AstToMarkdownTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;

public class AstToMarkdownTest {

Expand All @@ -25,13 +27,87 @@ private byte[] run(final String input) throws Exception {
final Transformer t = tf.newTransformer(new StreamSource(style, "classpath:///ast.xsl"));
t.transform(new StreamSource(ri), new StreamResult(o));
}
Files.write(
Paths.get(
"/Users/jelovirt/Work/github.com/jelovirt/org.lwdita/src/test/resources/out/" +
input.substring(4, input.indexOf(".")) +
".md"
),
o.toByteArray()
);
return o.toByteArray();
}

@Test
public void testAst() throws Exception {
final byte[] act = run("ast/ast.xml");
final byte[] exp = read("markdown/ast.md");
@ParameterizedTest
@ValueSource(
strings = {
"ast",
"codeblock",
"dita2abbreviation",
"dita2admonition",
"dita2ast",
"dita2body_attributes",
"dita2codeblock",
"dita2comment",
"dita2concept",
"dita2conkeyref",
"dita2conref",
"dita2dl",
"dita2entity",
"dita2escape",
"dita2footnote",
"dita2hdita",
"dita2header",
"dita2header_attributes",
"dita2html",
"dita2image-size",
"dita2image",
"dita2inline",
"dita2inline_extended",
"dita2jekyll",
"dita2keyref",
"dita2keys",
"dita2linebreak",
"dita2link",
"dita2missing_root_header",
"dita2missing_root_header_with_yaml",
"dita2multiple_top_level",
"dita2multiple_top_level_specialized",
"dita2note",
"dita2ol",
"dita2pandoc_header",
"dita2quote",
"dita2reference",
"dita2short",
"dita2shortdesc",
"dita2table-width",
"dita2table",
"dita2task",
"dita2taskOneStep",
"dita2taskTight",
"dita2testBOM",
"dita2testNoBOM",
"dita2topic",
"dita2ul",
"dita2unsupported_html",
"dita2yaml",
"dl",
"escape",
"header",
"header_attributes",
"image",
"inline",
"link",
"ol",
"pandoc_header",
"quote",
"table",
"ul",
}
)
public void testAst(String name) throws Exception {
final byte[] act = run("ast/" + name + ".xml");
final byte[] exp = read("out/" + name + ".md");
assertArrayEquals(exp, act);
}

Expand Down
163 changes: 163 additions & 0 deletions src/test/resources/out/ast.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
---
author: [Author One, Author Two]
source: Source
publisher: Publisher
permissions: Permissions
audience: Audience
category: Category
keyword: [Keyword1, Keyword2]
resourceid: [Resourceid1, Resourceid2]
---

# Test {#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.

None *emph \* \*\* \_ \_\_ __strong \* \*\* \_ \_\_ strong__ emph* none **strong \* \*\* \_ \_\_ _emph \* \*\* \_ \_\_ emph_ strong** none.

Asterisk \* bracket \[foo\].

\\\`\*\_\{\}\[\]\(\)&gt;\#+-.!&lt;&gt;&amp;

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
- **start** with *inline* **elements**

para

- list
- item
- four
- fifth
- sixth

Asterix:

- inline *bold* normal
- inline
- para

- inline
- para

para

- para

para

- mixed codeblock

```
codeblock
codeblock
```
- para
```
codeblock
codeblock
```
- para
Ordered:
1. ordered
2. list
3. item
1. nested
2. list
4. foo
5. foo
6. foo
7. foo
8. foo
9. foo
10. foo
11. foo
12. foo
13. foo
14. foo
15. foo
## Example { .section}
Code example on `for` loop:
```
for i in items:
println(i)

```
Fenced:
``` {#test__scala-example .scala}
items.foreach(println)
```

## Images {#images}

An inline ![Alt](test.jpg).

![Alt](test.jpg)

![Alt](test.jpg "Title")

### Key references {#key_references}

![]()

## Links {#links}

- [Markdown](test.md.xml)
- [DITA](topic.md.xml)
- [HTML](test.html)
- [External](http://www.example.com/test.html)
-

## Tables {#tables}

|Right|Left|Default|Center|
|----:|:---|-------|:----:|
|12|12|12|12|
|123|123|123|123|
|1|1|1|1|

|A|B|
|---|---|
|1|2|

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*|

## Definition list {#definition_list}

Apple
: Pomaceous fruit of plants of the genus Malus in the family Rosaceae.
Orange
: The fruit of an evergreen tree of the genus Citrus.

The fruit of an evergreen tree of the genus Citrus.

## Quote {#quote}

> This is email And so it this Again.
- List

> Quote in list
- Second list


17 changes: 17 additions & 0 deletions src/test/resources/out/codeblock.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Codeblock {#codeblock}

Code example on `for` loop:

```
for i in items:
println(i)
```

Fenced block:

``` {#codeblock__foreach-example .scala}
items.foreach(println)
```

4 changes: 4 additions & 0 deletions src/test/resources/out/dita2abbreviation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Abbreviation {#abbreviation}

The HTML specification is maintained by the W3C.

95 changes: 95 additions & 0 deletions src/test/resources/out/dita2admonition.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# Admonition {#admonition}

Block-Styled Side Content

**qualifier:**

Optional Title

block content

block content

No-Heading Content

**qualifier:**

block content

**qualifier:**

block content

Collapsible Block-Styled Side Content:

Collapsed by default

**qualifier:**

Optional Title

block content

Open by default

**qualifier:**

Optional Title

block content

**Note:**

block content

**Tip:**

block content

**Fastpath:**

block content

**Restriction:**

block content

**Important:**

block content

**Remember:**

block content

**Attention:**

block content

Caution:

block content

**Note:**

block content

Danger

block content

**Warning:**

block content

**Trouble:**

block content

1. List item

**Note:**

block content


Loading

0 comments on commit 49c01fb

Please sign in to comment.