Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
ice1000 opened this issue Mar 30, 2024 · 3 comments · Fixed by #57
Closed

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

ice1000 opened this issue Mar 30, 2024 · 3 comments · Fixed by #57

Comments

@ice1000
Copy link
Contributor

ice1000 commented Mar 30, 2024

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 typst/typst#2196 (comment)

@ice1000
Copy link
Contributor Author

ice1000 commented Mar 30, 2024

It has type content...

@Myriad-Dreamin
Copy link
Owner

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
Copy link
Contributor Author

ice1000 commented Mar 30, 2024

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

ice1000 added a commit to ice1k/typst-book that referenced this issue Mar 31, 2024
ice1000 added a commit to ice1k/typst-book that referenced this issue Mar 31, 2024
ice1000 added a commit to ice1k/typst-book that referenced this issue Mar 31, 2024
Myriad-Dreamin pushed a commit that referenced this issue Mar 31, 2024
* fix #55: improve `plain-text`

* fix: store local variables for performance & readability
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants