Giter VIP home page Giter VIP logo

cmarker.typ's People

Contributors

sabrinajewson avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

cmarker.typ's Issues

Supporting TeX code blocks

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-->.

Image paths are treated relative to installation path

$ 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!

Note on the use of images

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.

Supporting Markdown footnotes

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.

Superscript and subscript HTML tags

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:

  • Subscript with <sub>xyz</sub>: xyz
  • Superscript with <sup>xyz</sup>: xyz

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.