Skip to content

Commit

Permalink
[ re #30 ] Allow shonkier programs in pandoc divs
Browse files Browse the repository at this point in the history
  • Loading branch information
gallais committed Apr 10, 2020
1 parent ebc3a49 commit 672b949
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 6 deletions.
20 changes: 20 additions & 0 deletions examples/template.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,33 @@
globalEnv["primNumToString"]["."] = VPrim("primNumToString",[]);
globalEnv["primStringConcat"] = {};
globalEnv["primStringConcat"]["."] = VPrim("primStringConcat",[]);
globalEnv["printList"] = {};
globalEnv["printList"]["."] = VFun(null,{},[],[Clause([Value(Cell("x","xs"))],Cell(Atom("Div"),Cell(Cell(Stringy(""),Cell(Atom(""),Cell(Atom(""),Atom("")))),Cell(Cell(Atom("BulletList"),Cell(Cell(Cell(Atom("Plain"),Cell(Cell(Atom("Span"),Cell(Cell(Stringy(""),Cell(Atom(""),Cell(Atom(""),Atom("")))),Cell("x",Atom("")))),Atom(""))),Atom("")),Atom(""))),Cell(Cell(Atom("Div"),Cell(Cell(Cell(Stringy(""),Cell(Cell(Stringy("mary"),Atom("")),Cell(Atom(""),Atom("")))),Cell(Atom(""),Cell(Atom(""),Atom("")))),Cell(App(GVar(".","printList"),["xs"]),Atom("")))),Atom("")))))),Clause([Value(Atom(""))],Cell(Atom("Div"),Cell(Cell(Stringy(""),Cell(Atom(""),Cell(Atom(""),Atom("")))),Atom(""))))]);
</script>
</head>
<body>
<form method="post">
<div data-="">
<p>This is a paragraph which uses <span data-="">a template</span>.</p>
</div>
<p>And the following is generated by <em>recursively</em> printing a list <code>["Hello" "World"]</code> as an itemised list.</p>
<div data-="">
<ul>
<li><span data-="">Hello</span></li>
</ul>
<div data-="">
<div data-="">
<ul>
<li><span data-="">World</span></li>
</ul>
<div data-="">
<div data-="">

</div>
</div>
</div>
</div>
</div>
</form>
</body>
</html>
17 changes: 17 additions & 0 deletions examples/template.mary
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,20 @@ This is a paragraph which uses `x`{.mary}.
```{.mary}
foo("a template")
```

And the following is generated by *recursively* printing
a list `["Hello" "World"]` as an itemised list.

::: {mary="printList([x|xs])"}
* `x`{.mary}
```{.mary}
printList(xs)
```
:::

::: {mary="printList([])"}
:::

```{.mary}
printList(["Hello" "World"])
```
10 changes: 4 additions & 6 deletions src/Shonkier/Pandoc.hs
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,8 @@ instance ToRawTerm Block where
LineBlock ps -> toListy "LineBlock" ps
CodeBlock a@(b, cs, d) e
| "mary" `elem` cs
, Right v <- parseOnly identifier e
-> toAfter1Listy "Div" (a, filter ("mary" /=) cs, d)
[Var (Nothing, v) :: RawTerm]
, Right t <- parseOnly term e
-> toAfter1Listy "Div" (a, filter ("mary" /=) cs, d) [t]
| otherwise
-> toTakes2 "Code" a e
CodeBlock a b -> toTakes2 "CodeBlock" a b
Expand All @@ -95,9 +94,8 @@ instance ToRawTerm Inline where
SmallCaps is -> toListy "SmallCaps" is
Code a@(b, cs, d) e
| "mary" `elem` cs
, Right v <- parseOnly identifier e
-> toAfter1Listy "Span" (b, filter ("mary" /=) cs, d)
[Var (Nothing, v) :: RawTerm]
, Right t <- parseOnly term e
-> toAfter1Listy "Span" (b, filter ("mary" /=) cs, d) [t]
| otherwise
-> toTakes2 "Code" a e
SoftBreak -> Atom "SoftBreak"
Expand Down

0 comments on commit 672b949

Please sign in to comment.