Skip to content

Commit

Permalink
Merge pull request #48 from lukstafi/main
Browse files Browse the repository at this point in the history
Add README.md for printbox-ext-plot; Reduce dependencies between packages
  • Loading branch information
c-cube authored Oct 1, 2024
2 parents 540e3db + f65297d commit 05e134f
Show file tree
Hide file tree
Showing 16 changed files with 567 additions and 226 deletions.
Binary file added docs/printbox-ext-plot-example_Map.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/printbox-ext-plot-example_half_moons.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/printbox-ext-plot-example_linear.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/printbox-ext-plot-example_nested.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 0 additions & 2 deletions dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
Adds html output handling to the printbox package.
Printbox allows to print nested boxes, lists, arrays, tables in several formats")
(depends (printbox (= :version))
(printbox-text (and (= :version) :with-test))
(odoc :with-test)
(tyxml (>= 4.3))
(mdx (and (>= 1.4) :with-test))))
Expand All @@ -44,7 +43,6 @@ Adds Markdown output handling to the printbox package, with fallback to text and
Printbox allows to print nested boxes, lists, arrays, tables in several formats")
(depends (printbox (= :version))
(printbox-text (and (= :version)))
(printbox-html (and (= :version)))
(odoc :with-test)
(mdx (and (>= 1.4) :with-test))))

Expand Down
1 change: 0 additions & 1 deletion printbox-html.opam
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ bug-reports: "https://github.com/c-cube/printbox/issues"
depends: [
"dune" {>= "3.0"}
"printbox" {= version}
"printbox-text" {= version & with-test}
"odoc" {with-test}
"tyxml" {>= "4.3"}
"mdx" {>= "1.4" & with-test}
Expand Down
1 change: 0 additions & 1 deletion printbox-md.opam
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ depends: [
"dune" {>= "3.0"}
"printbox" {= version}
"printbox-text" {= version}
"printbox-html" {= version}
"odoc" {with-test}
"mdx" {>= "1.4" & with-test}
"odoc" {with-doc}
Expand Down
290 changes: 290 additions & 0 deletions src/printbox-ext-plot/README.md

Large diffs are not rendered by default.

39 changes: 6 additions & 33 deletions src/printbox-md/PrintBox_md.ml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ module Config = struct
| Code_quote

type t = {
tables: [ `Text | `Html ];
vlists: [ `Line_break | `List | `As_table ];
hlists: [ `Minimal | `As_table ];
foldable_trees: bool;
Expand All @@ -20,7 +19,6 @@ module Config = struct

let default =
{
tables = `Text;
vlists = `List;
hlists = `Minimal;
foldable_trees = false;
Expand All @@ -32,7 +30,6 @@ module Config = struct

let uniform =
{
tables = `Html;
vlists = `Line_break;
hlists = `As_table;
foldable_trees = true;
Expand All @@ -42,8 +39,6 @@ module Config = struct
tab_width = 4;
}

let html_tables c = { c with tables = `Html }
let text_tables c = { c with tables = `Text }
let vlists x c = { c with vlists = x }
let hlists x c = { c with hlists = x }
let foldable_trees c = { c with foldable_trees = true }
Expand Down Expand Up @@ -386,16 +381,12 @@ let pp c out b =
if code_block then fprintf out "@,%s```@,%s" prefix prefix;
pp_print_string out sty_post
| B.Frame { sub = fb; _ } ->
(match c.Config.frames, c.Config.tables, no_block with
| `As_table, `Html, _ ->
(* Don't indent in case there's an embedded multiline preformatted text. *)
PrintBox_html.pp ~flush:false ~indent:false () out b;
if not no_md then fprintf out "@,%s@,%s" prefix prefix
| `As_table, `Text, _ ->
(match c.Config.frames, no_block with
| `As_table, _ ->
let style = B.Style.preformatted in
let l = break_lines [ PrintBox_text.to_string_with ~style:false b ] in
loop ~no_block ~no_md ~prefix (B.lines_with_style style l)
| _, _, true ->
| _, true ->
(* E.g. in a first Markdown table cell, "> " would mess up rendering. *)
fprintf out "[%a]"
(fun _out -> loop ~no_block ~no_md ~prefix:(prefix ^ " "))
Expand Down Expand Up @@ -487,28 +478,10 @@ let pp c out b =
row;
if i < n_rows - 1 then fprintf out "@,%s" prefix)
rows
| B.Grid (_, _) when c.Config.tables = `Html && String.length prefix = 0 ->
PrintBox_html.pp ~flush:false ~indent:(not no_block) () out b;
if not no_md then fprintf out "@,%s@,%s" prefix prefix
| B.Grid (_, _) ->
(match c.Config.tables with
| `Text ->
let style = B.Style.preformatted in
let l = break_lines [ PrintBox_text.to_string_with ~style:false b ] in
loop ~no_block ~no_md ~prefix (B.lines_with_style style l)
| `Html ->
let table =
PrintBox_html.(
if no_block then
to_string
else
to_string_indent)
b
in
let lines = break_lines [ table ] in
pp_print_list
~pp_sep:(fun out () -> if not no_block then fprintf out "@,%s" prefix)
pp_print_string out lines);
let style = B.Style.preformatted in
let l = break_lines [ PrintBox_text.to_string_with ~style:false b ] in
loop ~no_block ~no_md ~prefix (B.lines_with_style style l);
if not no_md then fprintf out "@,%s@,%s" prefix prefix
| B.Tree (_extra_indent, header, [||]) ->
loop ~no_block ~no_md ~prefix header
Expand Down
6 changes: 0 additions & 6 deletions src/printbox-md/PrintBox_md.mli
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,6 @@ module Config : sig
val uniform : t
(** The configuration that leads to more lightweight and uniform rendering. *)

val html_tables : t -> t
(** Output tables via {!PrintBox_html}. Already the case for the {!uniform} config. *)

val text_tables : t -> t
(** Output tables via {!PrintBox_text}. Already the case for the {!default} config. *)

val vlists : [ `Line_break | `List | `As_table ] -> t -> t
(** How to output {!PrintBox.vlist} boxes, i.e. single-column grids.
- [`Line_break]: when the {!PrintBox.vlist} has bars, it puts a quoted horizontal rule
Expand Down
65 changes: 20 additions & 45 deletions src/printbox-md/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,16 @@ The &nbsp; `` `Minimal `` &nbsp; style for horizontal boxes simply puts all entr

or if \`Bars are set, | by the | vertical dash.

<div>
<table class="framed">
<tr><td><div>It only works when<br/>all the elements fit</div></td>
<td><div>logically speaking,</div></td>
<td><div><b>on a single line.</b></div></td>
</tr>
</table>
</div>

```
It only works when │logically speaking,│on a single line.
all the elements fit│ │
```



<div>
<table class="non-framed">
<tr><td><div>Otherwise, the fallback behavior is as if</div></td>
<td><pre style="font-family: monospace">`As_table</pre></td>
<td><div>was used to configure horizontal boxes.</div></td>
</tr>
</table>
</div>

`` Otherwise, the fallback behavior is as if`As_tablewas used to configure horizontal boxes. ``



Expand Down Expand Up @@ -98,14 +89,6 @@ to separate the entries (here with style \`Line_break).

- inside Markdown.

- And suprisingly it works even better
- - when tables are configured
- <div><div style="border:thin solid"><div>to fallback on</div></div></div>


- HTML -- but it doesn't work on GitHub Preview.
- (GitHub ignores styles on \<div\> and \<span\> tags.)

### Trees

<a id="TreeAnchor" href="#TreeAnchor">Trees</a> &nbsp; are rendered as:
Expand Down Expand Up @@ -134,27 +117,19 @@ Header|cells |[must be] |bold.
Rows |[must be]|single |line.
[Only]|then |**we get**|a Markdown table.

<div>
<table class="framed">
<tr><td><div><b>Tables</b></div></td><td><div><b>that meet</b></div></td>
<td><div style="border:thin solid"><div><b>neither</b></div></div></td>
<td><div><b>of:</b></div></td>
</tr>
<tr>
<td>
<div style="border:thin solid"><div><b>Markdown's native</b></div></div>
</td><td><div>restrictions,</div></td><td><div>special cases:</div></td>
<td><pre style="font-family: monospace">hlist
vlist</pre></td>
</tr>
<tr><td><div>End up</div></td><td><div>as either</div></td>
<td><div>of the fallbacks:</div></td>
<td><pre style="font-family: monospace">printbox-text
printbox-html</pre>
</td>
</tr>
</table>
</div>

```
Tables │that meet │┌───────┐ │of:
│ ││neither│ │
│ │└───────┘ │
───────────────────┼─────────────┼──────────────┼─────────────
┌─────────────────┐│restrictions,│special cases:│hlist
│Markdown's native││ │ │vlist
└─────────────────┘│ │ │
───────────────────┼─────────────┼──────────────┼─────────────
End up │as │the fallback: │printbox-text
```




2 changes: 1 addition & 1 deletion src/printbox-md/dune
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
(wrapped false)
(modules PrintBox_md)
(flags :standard -w +a-3-4-44-29 -safe-string)
(libraries printbox printbox-text printbox-html))
(libraries printbox printbox-text))

(executable
(name readme)
Expand Down
29 changes: 6 additions & 23 deletions src/printbox-md/readme.ml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ let () =
let () =
print_endline
MD.(
to_string Config.(html_tables default)
to_string Config.default
@@ B.(
hlist ~bars:true
[
Expand All @@ -113,7 +113,7 @@ let () =
let () =
print_endline
MD.(
to_string Config.(html_tables @@ hlists `As_table default)
to_string Config.(hlists `As_table default)
@@ B.(
hlist ~bars:false
[
Expand Down Expand Up @@ -217,23 +217,6 @@ let () =
line "inside Markdown.";
]))

let () =
print_endline
MD.(
to_string Config.(html_tables @@ table_frames @@ vlists `List default)
@@ B.(
vlist ~bars:false
[
line "And suprisingly it works even better";
vlist ~bars:false
[
line "when tables are configured";
frame @@ line "to fallback on";
line "HTML -- but it doesn't work on GitHub Preview.";
];
line "(GitHub ignores styles on <div> and <span> tags.)";
]))

let () = print_endline {|### Trees
|}

Expand Down Expand Up @@ -311,7 +294,7 @@ let () =
let () =
print_endline
MD.(
to_string Config.(html_tables default)
to_string Config.default
@@ B.(
let bold = text_with_style Style.bold in
let code = text_with_style Style.preformatted in
Expand All @@ -331,8 +314,8 @@ let () =
];
[
line "End up";
line "as either";
line "of the fallbacks:";
code "printbox-text\nprintbox-html";
line "as";
line "the fallback:";
code "printbox-text";
];
]))
Loading

0 comments on commit 05e134f

Please sign in to comment.