Skip to content

Commit

Permalink
Fix breaking into lines; table tests.
Browse files Browse the repository at this point in the history
Will add configuration and tune the table output next.
Maybe the html table conversion could be better too.
  • Loading branch information
lukstafi committed Jan 21, 2024
1 parent 8795d98 commit 3dfe5f0
Show file tree
Hide file tree
Showing 4 changed files with 299 additions and 15 deletions.
11 changes: 7 additions & 4 deletions src/printbox-md/PrintBox_md.ml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module Config = struct
}

let default = {
tables=`Html;
tables=`Text;
foldable_trees=false;
multiline_preformatted=Code_block;
one_line_preformatted=Code_quote;
Expand Down Expand Up @@ -79,9 +79,12 @@ end

let break_lines l =
let lines = List.concat_map (String.split_on_char '\n') l in
List.map (fun s ->
if s.[String.length s - 1] = '\r'
then String.sub s 0 (String.length s - 1) else s) lines
List.filter_map (fun s ->
let len = String.length s in
if len = 0 then None
else if s.[len - 1] = '\r' then Some (String.sub s 0 (len - 1))
else Some s)
lines

let pp_indented ~tab_width ~code_block ~code_quote ~infix out s =
let open Format in
Expand Down
147 changes: 142 additions & 5 deletions test/test_md.expected
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,20 @@ Test default:
> end of 5
> ```
>
- > child 6
- > > a │looooooooooooooooooooooooo<br>
> > │oonng<br>
> > ─────┼──────────────────────────<br>
> > bx │ ┌─┬─┐<br>
> > │ │x│y│<br>
> > │ ├─┼─┤<br>
> > │ │1│2│<br>
> > │ └─┴─┘<br>
> > ─────┼──────────────────────────<br>
> > │<br>
> > │ x │y<br>
> > ? │ ──┼──<br>
> > │ 10│20<br>
> > │

Test uniform unfolded:

Expand All @@ -44,7 +57,44 @@ Test uniform unfolded:
&nbsp;&nbsp;&nbsp;&nbsp;subbody 5<br>
&nbsp;&nbsp;&nbsp;&nbsp;one tab end of sub 5<br>
end of 5</span></span>
- <span style="border:thin solid">child 6</span>
- <span style="border:thin solid"><span style="border:thin solid"><div><br>
<table class="framed"><br>
<tr class=""><td class=""><span class="">a</span></td><br>
<td class=""><span class="">looooooooooooooooooooooooo<br>
oonng</span></td><br>
</tr><br>
<tr class=""><td class=""><span class="">bx</span></td><br>
<td class=""><br>
<div class="center"><br>
<div style="border:thin solid"><br>
<table class="framed"><br>
<tr class=""><td class=""><span class="">x</span></td><br>
<td class=""><span class="">y</span></td><br>
</tr><br>
<tr class=""><td class=""><span class="">1</span></td><br>
<td class=""><span class="">2</span></td><br>
</tr><br>
</table><br>
</div><br>
</div><br>
</td><br>
</tr><br>
<tr class=""><td class=""><span class="">?</span></td><br>
<td class=""><br>
<div class="center"><br>
<table class="framed"><br>
<tr class=""><td class=""><span class="">x</span></td><br>
<td class=""><span class="">y</span></td><br>
</tr><br>
<tr class=""><td class=""><span class="">10</span></td><br>
<td class=""><span class="">20</span></td><br>
</tr><br>
</table><br>
</div><br>
</td><br>
</tr><br>
</table><br>
</div></span></span>

Test foldable:
<details><summary><span style="border:thin solid">root</span></summary>
Expand Down Expand Up @@ -79,7 +129,20 @@ Test foldable:
> ```
>
> </details>
- > child 6
- > > a │looooooooooooooooooooooooo<br>
> > │oonng<br>
> > ─────┼──────────────────────────<br>
> > bx │ ┌─┬─┐<br>
> > │ │x│y│<br>
> > │ ├─┼─┤<br>
> > │ │1│2│<br>
> > │ └─┴─┘<br>
> > ─────┼──────────────────────────<br>
> > │<br>
> > │ x │y<br>
> > ? │ ──┼──<br>
> > │ 10│20<br>
> > │
</details>

Test uniform tab=2:
Expand Down Expand Up @@ -112,7 +175,44 @@ Test uniform tab=2:
&nbsp;&nbsp;one tab end of sub 5<br>
end of 5</span>
</details></span>
- <span style="border:thin solid">child 6</span>
- <span style="border:thin solid"><span style="border:thin solid"><div><br>
<table class="framed"><br>
<tr class=""><td class=""><span class="">a</span></td><br>
<td class=""><span class="">looooooooooooooooooooooooo<br>
oonng</span></td><br>
</tr><br>
<tr class=""><td class=""><span class="">bx</span></td><br>
<td class=""><br>
<div class="center"><br>
<div style="border:thin solid"><br>
<table class="framed"><br>
<tr class=""><td class=""><span class="">x</span></td><br>
<td class=""><span class="">y</span></td><br>
</tr><br>
<tr class=""><td class=""><span class="">1</span></td><br>
<td class=""><span class="">2</span></td><br>
</tr><br>
</table><br>
</div><br>
</div><br>
</td><br>
</tr><br>
<tr class=""><td class=""><span class="">?</span></td><br>
<td class=""><br>
<div class="center"><br>
<table class="framed"><br>
<tr class=""><td class=""><span class="">x</span></td><br>
<td class=""><span class="">y</span></td><br>
</tr><br>
<tr class=""><td class=""><span class="">10</span></td><br>
<td class=""><span class="">20</span></td><br>
</tr><br>
</table><br>
</div><br>
</td><br>
</tr><br>
</table><br>
</div></span></span>
</details>

Test single quote tab=2:
Expand Down Expand Up @@ -145,7 +245,44 @@ Test single quote tab=2:
&nbsp; &nbsp; `one tab end of sub 5`<br>
`end of 5`
</details></span>
- <span style="border:thin solid">child 6</span>
- <span style="border:thin solid"><span style="border:thin solid"><div><br>
<table class="framed"><br>
<tr class=""><td class=""><span class="">a</span></td><br>
<td class=""><span class="">looooooooooooooooooooooooo<br>
oonng</span></td><br>
</tr><br>
<tr class=""><td class=""><span class="">bx</span></td><br>
<td class=""><br>
<div class="center"><br>
<div style="border:thin solid"><br>
<table class="framed"><br>
<tr class=""><td class=""><span class="">x</span></td><br>
<td class=""><span class="">y</span></td><br>
</tr><br>
<tr class=""><td class=""><span class="">1</span></td><br>
<td class=""><span class="">2</span></td><br>
</tr><br>
</table><br>
</div><br>
</div><br>
</td><br>
</tr><br>
<tr class=""><td class=""><span class="">?</span></td><br>
<td class=""><br>
<div class="center"><br>
<table class="framed"><br>
<tr class=""><td class=""><span class="">x</span></td><br>
<td class=""><span class="">y</span></td><br>
</tr><br>
<tr class=""><td class=""><span class="">10</span></td><br>
<td class=""><span class="">20</span></td><br>
</tr><br>
</table><br>
</div><br>
</td><br>
</tr><br>
</table><br>
</div></span></span>
</details>

The end.
147 changes: 142 additions & 5 deletions test/test_md.expected.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,20 @@ Test default:
> end of 5
> ```
>
- > child 6
- > > a │looooooooooooooooooooooooo<br>
> > │oonng<br>
> > ─────┼──────────────────────────<br>
> > bx │ ┌─┬─┐<br>
> > │ │x│y│<br>
> > │ ├─┼─┤<br>
> > │ │1│2│<br>
> > │ └─┴─┘<br>
> > ─────┼──────────────────────────<br>
> > │<br>
> > │ x │y<br>
> > ? │ ──┼──<br>
> > │ 10│20<br>
> > │
Test uniform unfolded:
Expand All @@ -44,7 +57,44 @@ Test uniform unfolded:
&nbsp;&nbsp;&nbsp;&nbsp;subbody 5<br>
&nbsp;&nbsp;&nbsp;&nbsp;one tab end of sub 5<br>
end of 5</span></span>
- <span style="border:thin solid">child 6</span>
- <span style="border:thin solid"><span style="border:thin solid"><div><br>
<table class="framed"><br>
<tr class=""><td class=""><span class="">a</span></td><br>
<td class=""><span class="">looooooooooooooooooooooooo<br>
oonng</span></td><br>
</tr><br>
<tr class=""><td class=""><span class="">bx</span></td><br>
<td class=""><br>
<div class="center"><br>
<div style="border:thin solid"><br>
<table class="framed"><br>
<tr class=""><td class=""><span class="">x</span></td><br>
<td class=""><span class="">y</span></td><br>
</tr><br>
<tr class=""><td class=""><span class="">1</span></td><br>
<td class=""><span class="">2</span></td><br>
</tr><br>
</table><br>
</div><br>
</div><br>
</td><br>
</tr><br>
<tr class=""><td class=""><span class="">?</span></td><br>
<td class=""><br>
<div class="center"><br>
<table class="framed"><br>
<tr class=""><td class=""><span class="">x</span></td><br>
<td class=""><span class="">y</span></td><br>
</tr><br>
<tr class=""><td class=""><span class="">10</span></td><br>
<td class=""><span class="">20</span></td><br>
</tr><br>
</table><br>
</div><br>
</td><br>
</tr><br>
</table><br>
</div></span></span>
Test foldable:
<details><summary><span style="border:thin solid">root</span></summary>
Expand Down Expand Up @@ -79,7 +129,20 @@ Test foldable:
> ```
>
> </details>
- > child 6
- > > a │looooooooooooooooooooooooo<br>
> > │oonng<br>
> > ─────┼──────────────────────────<br>
> > bx │ ┌─┬─┐<br>
> > │ │x│y│<br>
> > │ ├─┼─┤<br>
> > │ │1│2│<br>
> > │ └─┴─┘<br>
> > ─────┼──────────────────────────<br>
> > │<br>
> > │ x │y<br>
> > ? │ ──┼──<br>
> > │ 10│20<br>
> > │
</details>
Test uniform tab=2:
Expand Down Expand Up @@ -112,7 +175,44 @@ Test uniform tab=2:
&nbsp;&nbsp;one tab end of sub 5<br>
end of 5</span>
</details></span>
- <span style="border:thin solid">child 6</span>
- <span style="border:thin solid"><span style="border:thin solid"><div><br>
<table class="framed"><br>
<tr class=""><td class=""><span class="">a</span></td><br>
<td class=""><span class="">looooooooooooooooooooooooo<br>
oonng</span></td><br>
</tr><br>
<tr class=""><td class=""><span class="">bx</span></td><br>
<td class=""><br>
<div class="center"><br>
<div style="border:thin solid"><br>
<table class="framed"><br>
<tr class=""><td class=""><span class="">x</span></td><br>
<td class=""><span class="">y</span></td><br>
</tr><br>
<tr class=""><td class=""><span class="">1</span></td><br>
<td class=""><span class="">2</span></td><br>
</tr><br>
</table><br>
</div><br>
</div><br>
</td><br>
</tr><br>
<tr class=""><td class=""><span class="">?</span></td><br>
<td class=""><br>
<div class="center"><br>
<table class="framed"><br>
<tr class=""><td class=""><span class="">x</span></td><br>
<td class=""><span class="">y</span></td><br>
</tr><br>
<tr class=""><td class=""><span class="">10</span></td><br>
<td class=""><span class="">20</span></td><br>
</tr><br>
</table><br>
</div><br>
</td><br>
</tr><br>
</table><br>
</div></span></span>
</details>
Test single quote tab=2:
Expand Down Expand Up @@ -145,7 +245,44 @@ Test single quote tab=2:
&nbsp; &nbsp; `one tab end of sub 5`<br>
`end of 5`
</details></span>
- <span style="border:thin solid">child 6</span>
- <span style="border:thin solid"><span style="border:thin solid"><div><br>
<table class="framed"><br>
<tr class=""><td class=""><span class="">a</span></td><br>
<td class=""><span class="">looooooooooooooooooooooooo<br>
oonng</span></td><br>
</tr><br>
<tr class=""><td class=""><span class="">bx</span></td><br>
<td class=""><br>
<div class="center"><br>
<div style="border:thin solid"><br>
<table class="framed"><br>
<tr class=""><td class=""><span class="">x</span></td><br>
<td class=""><span class="">y</span></td><br>
</tr><br>
<tr class=""><td class=""><span class="">1</span></td><br>
<td class=""><span class="">2</span></td><br>
</tr><br>
</table><br>
</div><br>
</div><br>
</td><br>
</tr><br>
<tr class=""><td class=""><span class="">?</span></td><br>
<td class=""><br>
<div class="center"><br>
<table class="framed"><br>
<tr class=""><td class=""><span class="">x</span></td><br>
<td class=""><span class="">y</span></td><br>
</tr><br>
<tr class=""><td class=""><span class="">10</span></td><br>
<td class=""><span class="">20</span></td><br>
</tr><br>
</table><br>
</div><br>
</td><br>
</tr><br>
</table><br>
</div></span></span>
</details>
The end.
Loading

0 comments on commit 3dfe5f0

Please sign in to comment.