Open kamoshi opened 2 months ago
Note that you can also iterate over the ElemChildren
yourself, the ANSI escapes are just a default. A direct-to-HTML feature might still be nice.
I took a look at the code, and I found that you can format HTML like this (via ElemChildren
):
let mut buffer = String::new();
x.content.write_buf(&mut buffer, BufWriteFormat::Html).unwrap();
buffer
Result string looks like this:
Makino S and Tsutsui M 2008 <span style="font-style: italic;">A dictionary of advanced Japanese grammar</span> (Japan Times)
One different issue I found along the way is that the BibliographyItem
is marked as pub
, but it isn't exported from the package, so it can't be accessed in the documentation, even though you can use it in code as library consumer. It's also missing documentation in code.
Oh, I completely missed that HTML is already implemented. I also noticed the problem with the re-export and had opened https://github.com/typst/hayagriva/issues/157 for it.
Hey, I'm trying to use hayagriva as a library to parse and render citations and bibliography on a HTML website. Generally it works quite well, but when rendering the data the library includes ANSI escape codes in the output by default. This isn't a major problem, because I can for example do something like
.replace("\u{1b}[0m", "")
to strip them, but this is less than ideal.For example given this bibliography
When rendering this entry as a String I get:
[\u{1b}[0m1\u{1b}[0m]\u{1b}[0m
\u{1b}[0mMakino S\u{1b}[0m and \u{1b}[0mTsutsui M\u{1b}[0m \u{1b}[0m2008\u{1b}[0m \u{1b}[0m\u{1b}[3mA dictionary of advanced Japanese grammar\u{1b}[0m (\u{1b}[0mJapan Times\u{1b}[0m)\u{1b}[0m
Ideally (HTML) these would be something along the lines of:
[1]
Makino S and Tsutsui M 2008 <i>A dictionary of advanced Japanese grammar</i> (Japan Times)
If this currently can't be accomplished, it could potentially be added as an alternative API to the default
ToString
, if it can then it would be useful to add the way to accomplish this to the documentation.This is how I am currently processing the bibliography: