Myriad-Dreamin / shiroa

shiroa is a simple tool for creating modern online books in pure typst.
https://myriad-dreamin.github.io/shiroa/
Apache License 2.0
204 stars 17 forks source link

Doesn't work for title who are solely content #55

Closed ice1000 closed 3 months ago

ice1000 commented 3 months ago

Say if I have a file like

= #smallcaps[114514]

This will make the following code from lib.typ crash:

error: type none has no method `trim`
    ┌─ C:\Users\ice10\git-repos\website\templates\page.typ:123:40
    │
123 │         let title = plain-text(it.body).trim();
    │                                         ^^^^

A similar function is provided in https://github.com/typst/typst/issues/2196#issuecomment-1728135476

ice1000 commented 3 months ago

It has type content...

Myriad-Dreamin commented 3 months ago

https://github.com/Myriad-Dreamin/typst-book/blob/30f19ab320fcbda6e2e9bbfb2abe474eea2de48f/contrib/typst/book/lib.typ#L136-L152

The "to_string" implementation is actually already in our template.


#let title = plain-text(it.body).trim();

🤔This is for making hash string labels (hashtags) for headings.

https://myriad-dreamin.github.io/typst-book/#label-Introduction
                                            ^^^^^^^^^^^^^^^^^^^

We can give up on providing hashtags if plain-text whatever returns none.

But I'm also interested in whether we can have a more robust approach to create hash strings, at least for simple content such as #smallcaps[114514].

ice1000 commented 3 months ago

But I'm also interested in whether we can have a more robust approach to create hash strings, at least for simple content such as #smallcaps[114514].

Yeah that would be great

The "to_string" implementation is actually already in our template.

But lib.typ will be overwritten by the compiler, so it's immutable in a sense