sabrinajewson / cmarker.typ Goto Github PK
View Code? Open in Web Editor NEWTranspile CommonMark Markdown to Typst, from within Typst!
License: MIT License
Transpile CommonMark Markdown to Typst, from within Typst!
License: MIT License
It would be useful to support Markdown tables and have them be converted into Typst tables.
It would be useful to support TeX code blocks and have them be automatically rendered as Typst math equations. Currently, the only way to achieve this is writing out the equation in both TeX and Typst and using a combination of <!--typst-begin-exclude-->
and <!--raw-typst-->
.
$ cd $(mktemp -d)
$ curl -so img.png "https://placehold.co/600x400"
$ echo '#import "@preview/cmarker:0.1.0"' > test.typ
$ echo '#cmarker.render(read("test.md"))' >> test.typ
$ echo '![Some image](img.png)' > test.md
$ cat test.typ
#import "@preview/cmarker:0.1.0"
#cmarker.render(read("test.md"))
$ cat test.md
![Some image](img.png)
$ typst compile test.typ
error: file not found (searched at /home/user01/.cache/typst/packages/preview/cmarker/0.1.0/img.png)
┌─ @preview/cmarker:0.1.0/lib.typ:19:9
│
19 │ eval(rendered, mode: "markup", scope: (
│ ^^^^^^^^
help: error occurred in this call of function `image`
┌─ @preview/cmarker:0.1.0/lib.typ:21:25
│
21 │ image: (..args) => image(..args),
│ ^^^^^^^^^^^^^
help: error occurred in this call of function `render`
┌─ test.typ:2:1
│
2 │ #cmarker.render(read("test.md"))
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
This must be an oversight; would have expected the search to happen relative to the document path.
P.S. Extremely useful plugin. Thank you!
This is an unfortunate consequence of how eval
is used in typst.
When markdown is parsed with the pakage and contains images, the path to find the eval
is evaluated relative to the package file, NOT the main file.
When this package is used locally, this might not create any problem as the two files cmarker.typ
and main.typ
may well be in the same folder.
But for using the package using the package manager, this makes the code fails as the images are searched relative to whichever folder the package is stored. This issue extends to the web app as well.
To circumvent this, you need to defer the eval step and evaluate the converted typst string in the main.typ
file.
For example,
#import "@preview/cmarker:0.1.0":*
#let out = (render(show-source: true,read("simple.md")))
#eval(out.text,mode:"markup")
Will work for a simple markdown file that loads a single image but only calling the render
function will not.
Markdown has footnotes, and we could support them in cmarker. The main difficulty here is that the Markdown parser gives us footnotes in an out-of-band format, whereäs Typst expects them in an in-band format, and so our current single-pass approach would be insufficient. I think I would only like to parse the Markdown once, so the strategy I would choose is building a Vec<(usize, CowStr<'_>)>
of “places we need to insert a footnote” in our single pass, then add a second pass to fill them in.
I don’t want to embed a full HTML parser, but I think we can support some basic usage of HTML tags. In particular, GitHub supports:
<sub>xyz</sub>
: xyz<sup>xyz</sup>
: xyzA declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.