Skip to content

Commit 79fc1bb

Browse files
authored
Merge pull request #86 from panglesd/cmarkit-commonmark-output
Add commonmark output
2 parents 599d55a + eb4649b commit 79fc1bb

29 files changed

+987
-240
lines changed

CONTRIBUTING.md

+1
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,4 @@ TODO
8585

8686
Slipshow vendors a few modified dependencies. Currently it uses
8787
[git-vendor](https://github.com/brettlangdon/git-vendor).
88+

src/compiler/bin/compile.ml

+15-3
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,22 @@ let to_asset s =
5050
f "Could not read file: %s. Considering it as an URL. (%s)" s e);
5151
Remote s
5252

53-
let compile ~math_link ~slip_css_link ~slipshow_js_link ~input ~output ~watch
54-
~serve =
53+
let compile ~markdown_mode ~math_link ~slip_css_link ~slipshow_js_link ~input
54+
~output ~watch ~serve =
5555
let math_link = Option.map to_asset math_link in
5656
let slip_css_link = Option.map to_asset slip_css_link in
5757
let slipshow_js_link = Option.map to_asset slipshow_js_link in
58+
let markdown_compile () =
59+
let+ content = Io.read input in
60+
let md = Slipshow.convert_to_md content in
61+
match output with
62+
| `Stdout ->
63+
print_string md;
64+
Ok ()
65+
| `File output ->
66+
let* () = Io.write output md in
67+
()
68+
in
5869
let f () =
5970
let+ content = Io.read input in
6071
let html =
@@ -92,7 +103,8 @@ let compile ~math_link ~slip_css_link ~slipshow_js_link ~input ~output ~watch
92103
(* let () = print_endline s in *)
93104
Ok result
94105
in
95-
if serve then Serve.do_serve input f2
106+
if markdown_mode then markdown_compile ()
107+
else if serve then Serve.do_serve input f2
96108
else if watch then Serve.do_watch input f
97109
else
98110
let+ _html = f () in

src/compiler/bin/compile.mli

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
val compile :
2+
markdown_mode:bool ->
23
math_link:string option ->
34
slip_css_link:string option ->
45
slipshow_js_link:string option ->

src/compiler/bin/main.ml

+15-7
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@ let setup_log =
1111

1212
let compile =
1313
let compile input output math_link slip_css_link slipshow_js_link watch serve
14-
() =
14+
markdown_mode () =
1515
let input = match input with "-" -> `Stdin | s -> `File (Fpath.v s) in
1616
let output_of_input input =
17-
match input with
18-
| `File input -> `File (Fpath.set_ext "html" input)
19-
| `Stdin -> `Stdout
17+
match (input, markdown_mode) with
18+
| `File input, false -> `File (Fpath.set_ext "html" input)
19+
| `File input, true -> `File (Fpath.set_ext "noattrs.md" input)
20+
| `Stdin, _ -> `Stdout
2021
in
2122
let output =
2223
match output with
@@ -26,7 +27,7 @@ let compile =
2627
in
2728
match
2829
Compile.compile ~input ~output ~math_link ~slip_css_link ~slipshow_js_link
29-
~watch ~serve
30+
~watch ~serve ~markdown_mode
3031
with
3132
| Ok () -> Ok ()
3233
| Error (`Msg s) -> Error s
@@ -50,7 +51,7 @@ let compile =
5051
in
5152
let slip_css_link =
5253
let doc =
53-
"Where to find the slipshow javascript file. Optional. When absent, use \
54+
"Where to find the slipshow css file. Optional. When absent, use \
5455
slipshow.%%VERSION%%, embedded in this binary. If URL is an absolute \
5556
URL, links to it, otherwise the content is embedded in the html file."
5657
in
@@ -71,6 +72,13 @@ let compile =
7172
in
7273
Arg.(value & pos 0 string "-" & info [] ~doc ~docv:"FILE.md")
7374
in
75+
let markdown_output =
76+
let doc =
77+
"Outputs a markdown file with valid (GFM) syntax, by stripping the \
78+
attributes. Useful for printing for instance."
79+
in
80+
Arg.(value & flag & info [ "markdown-output" ] ~doc ~docv:"FILE.md")
81+
in
7482
let watch =
7583
let doc = "Watch" in
7684
Arg.(value & flag & info [ "watch" ] ~doc ~docv:"")
@@ -81,7 +89,7 @@ let compile =
8189
in
8290
Term.(
8391
const compile $ input $ output $ math_link $ slip_css_link
84-
$ slipshow_js_link $ watch $ serve $ setup_log)
92+
$ slipshow_js_link $ watch $ serve $ markdown_output $ setup_log)
8593

8694
let compile_cmd =
8795
let doc = "Compile a markdown file into a slipshow presentation" in

src/compiler/lib/mappings.ml

+20
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,23 @@ let of_cmarkit resolve_images =
6565
| x -> Some x
6666
in
6767
Ast.Mapper.make ~block ~inline ~attrs ()
68+
69+
let to_cmarkit =
70+
let block m = function
71+
| Ast.Div ((bq, _), meta) ->
72+
let b =
73+
match Mapper.map_block m bq with None -> Block.empty | Some b -> b
74+
in
75+
Mapper.ret (Block.Blocks ([ b ], meta))
76+
| Ast.SlipScript _ -> Mapper.delete
77+
| _ -> Mapper.default
78+
in
79+
let inline _i = function _ -> Mapper.default in
80+
let attrs = function
81+
| `Kv (("up", m), v) -> Some (`Kv (("up-at-unpause", m), v))
82+
| `Kv (("center", m), v) -> Some (`Kv (("center-at-unpause", m), v))
83+
| `Kv (("down", m), v) -> Some (`Kv (("down-at-unpause", m), v))
84+
| `Kv (("exec", m), v) -> Some (`Kv (("exec-at-unpause", m), v))
85+
| x -> Some x
86+
in
87+
Ast.Mapper.make ~block ~inline ~attrs ()

src/compiler/lib/slipshow.ml

+7
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,13 @@ let string_to_delayed s =
9292
let s = s |> Base64.decode |> Result.get_ok in
9393
Marshal.from_string s 0
9494

95+
let convert_to_md content =
96+
let md = Cmarkit.Doc.of_string ~heading_auto_ids:true ~strict:false content in
97+
let resolve_images = fun x -> Remote x in
98+
let sd = Cmarkit.Mapper.map_doc (Mappings.of_cmarkit resolve_images) md in
99+
let sd = Cmarkit.Mapper.map_doc Mappings.to_cmarkit sd in
100+
Cmarkit_commonmark.of_doc ~include_attributes:false sd
101+
95102
let delayed ?math_link ?slip_css_link ?slipshow_js_link
96103
?(resolve_images = fun x -> Remote x) s =
97104
let md = Cmarkit.Doc.of_string ~heading_auto_ids:true ~strict:false s in

src/compiler/lib/slipshow.mli

+2
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,5 @@ val convert :
2929
?resolve_images:(string -> asset) ->
3030
string ->
3131
string
32+
33+
val convert_to_md : string -> string

test/compiler/dune

-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,4 @@
22
(name slipshow))
33

44
(cram
5-
(enabled_if false)
65
(deps %{bin:slipshow}))

test/compiler/simple.t/run.t

+16-16
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ We can compile the file using the slip_of_mark binary
44

55
$ cat file.html | grep "<body>" -A 10
66
<body>
7-
8-
<!-- This is the presentation -->
9-
<slip-slipshow>
10-
<slip-slip immediate-enter>
11-
<slip-body>
12-
<h1 id="a-title"><a class="anchor" aria-hidden="true" href="#a-title"></a><span>A title</span></h1>
7+
<div id="slipshow-content">
8+
<svg id="slipshow-drawing" style="overflow:visible; position: absolute; z-index:1000"></svg>
9+
<div class="slip-rescaler">
10+
<div class="slip">
11+
<div class="slip-body">
12+
<h1 id="a-title"><a class="anchor" aria-hidden="true" href="#a-title"></a><span>A title</span></h1>
1313
<div pause></div>
14-
<p><span>A word </span><span id="id" emph-at-unpause step><span>and</span></span><span> some other words.</span></p>
14+
<p><span>A word </span><span id="id" step emph-at-unpause>and</span><span> some other words.</span></p>
1515
<div pause></div>
1616
<h2 id="subtitle"><a class="anchor" aria-hidden="true" href="#subtitle"></a><span>subtitle</span></h2>
1717

@@ -41,16 +41,16 @@ If we do not pass an input file, it gets its value from stdin
4141

4242
$ cat file.html | grep "<body>" -A 10
4343
<body>
44-
45-
<!-- This is the presentation -->
46-
<slip-slipshow>
47-
<slip-slip immediate-enter>
48-
<slip-body>
49-
<h1 id="title"><a class="anchor" aria-hidden="true" href="#title"></a><span>Title</span></h1>
44+
<div id="slipshow-content">
45+
<svg id="slipshow-drawing" style="overflow:visible; position: absolute; z-index:1000"></svg>
46+
<div class="slip-rescaler">
47+
<div class="slip">
48+
<div class="slip-body">
49+
<h1 id="title"><a class="anchor" aria-hidden="true" href="#title"></a><span>Title</span></h1>
5050
<p><span>Paragraph</span></p>
5151

52-
</slip-body>
53-
</slip-slip>
52+
</div>
53+
</div>
5454

5555
If we give neither the input nor the output, stdin and stdout are used:
5656

@@ -100,4 +100,4 @@ Images
100100
101101
$ slipshow file_with_image.md
102102
$ cat file_with_image.html | grep image | grep base64
103-
<p><span>A paragraph with an </span><img src="data:;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAIAAAACUFjqAAABg2lDQ1BJQ0MgcHJvZmlsZQAAKJF9kT1Iw0AcxV9bpaIVB4OIOGSoTnZREcdahSJUCLVCqw4ml35Bk4YkxcVRcC04+LFYdXBx1tXBVRAEP0BcXZwUXaTE/yWFFjEeHPfj3b3H3Tsg2KgwzeqKA5pum+lkQszmVsXwK/ogIIIhCDKzjDlJSsF3fN0jwNe7GM/yP/fn6FfzFgMCInGcGaZNvEE8s2kbnPeJBVaSVeJz4gmTLkj8yHXF4zfORZeDPFMwM+l5YoFYLHaw0sGsZGrE08RRVdMpP5j1WOW8xVmr1FjrnvyFkby+ssx1mqNIYhFLkCBCQQ1lVGAjRqtOioU07Sd8/COuXyKXQq4yGDkWUIUG2fWD/8Hvbq3C1KSXFEkA3S+O8zEGhHeBZt1xvo8dp3kChJ6BK73trzaA2U/S620tegQMbAMX121N2QMud4DhJ0M2ZVcK0QwWCsD7GX1TDhi8BXrXvN5a+zh9ADLUVeoGODgExouUve7z7p7O3v490+rvB2/RcqXOpP/kAAAACXBIWXMAAC4jAAAuIwF4pT92AAAAB3RJTUUH5wsUDBghqFYBIAAAABl0RVh0Q29tbWVudABDcmVhdGVkIHdpdGggR0lNUFeBDhcAAACeSURBVBjTbY4xCoQwFEQny1aWCVFPkEKTK4SAeATv5wE8gjew+wpewV/aB9xC1Cz4qhkeDIPjYhzHruuGYTgScCciUkp571P9wYVzLsYopUTCd55nAHmen31dV2YuigIAM6OqKmPM6YQQAO4KQEzTtO87AGttWZZZlvV9T0QhhKZpnmvbthlj6rp+v/bKo5dlYea2bf98Oq61JqJ0/AfIKIeErZAqOwAAAABJRU5ErkJggg==" alt="image" ></p>
103+
<p><span>A paragraph with an </span><img src="data:;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAIAAAACUFjqAAABg2lDQ1BJQ0MgcHJvZmlsZQAAKJF9kT1Iw0AcxV9bpaIVB4OIOGSoTnZREcdahSJUCLVCqw4ml35Bk4YkxcVRcC04+LFYdXBx1tXBVRAEP0BcXZwUXaTE/yWFFjEeHPfj3b3H3Tsg2KgwzeqKA5pum+lkQszmVsXwK/ogIIIhCDKzjDlJSsF3fN0jwNe7GM/yP/fn6FfzFgMCInGcGaZNvEE8s2kbnPeJBVaSVeJz4gmTLkj8yHXF4zfORZeDPFMwM+l5YoFYLHaw0sGsZGrE08RRVdMpP5j1WOW8xVmr1FjrnvyFkby+ssx1mqNIYhFLkCBCQQ1lVGAjRqtOioU07Sd8/COuXyKXQq4yGDkWUIUG2fWD/8Hvbq3C1KSXFEkA3S+O8zEGhHeBZt1xvo8dp3kChJ6BK73trzaA2U/S620tegQMbAMX121N2QMud4DhJ0M2ZVcK0QwWCsD7GX1TDhi8BXrXvN5a+zh9ADLUVeoGODgExouUve7z7p7O3v490+rvB2/RcqXOpP/kAAAACXBIWXMAAC4jAAAuIwF4pT92AAAAB3RJTUUH5wsUDBghqFYBIAAAABl0RVh0Q29tbWVudABDcmVhdGVkIHdpdGggR0lNUFeBDhcAAACeSURBVBjTbY4xCoQwFEQny1aWCVFPkEKTK4SAeATv5wE8gjew+wpewV/aB9xC1Cz4qhkeDIPjYhzHruuGYTgScCciUkp571P9wYVzLsYopUTCd55nAHmen31dV2YuigIAM6OqKmPM6YQQAO4KQEzTtO87AGttWZZZlvV9T0QhhKZpnmvbthlj6rp+v/bKo5dlYea2bf98Oq61JqJ0/AfIKIeErZAqOwAAAABJRU5ErkJggg==" alt="image" ></p>

test/compiler/to_commonmark.t/file.md

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# A title
2+
3+
{pause}
4+
5+
A word and{#id step emph-at-unpause} some other words.
6+
7+
{pause}
8+
9+
## subtitle
10+
11+
{pause}
12+
> Blibli.
13+
> Some other content
14+
15+
{pause blockquote}
16+
> Blibli.
17+
> Some other content
18+
19+
20+
[emph]: {style="color: red"}
21+
22+
And {pause} [standalone][emph] inlines2

test/compiler/to_commonmark.t/run.t

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
We can compile the file using the slip_of_mark binary
2+
3+
$ slipshow --markdown-output file.md
4+
5+
$ cat file.noattrs.md
6+
# A title
7+
8+
9+
A word and some other words.
10+
11+
12+
## subtitle
13+
14+
Blibli.
15+
Some other content
16+
17+
> Blibli.
18+
> Some other content
19+
20+
21+
22+
And [standalone][emph] inlines2

vendor/github.com/panglesd/cmarkit/B0.ml

+3-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)