fix: render bibliography as raw HTML

This commit is contained in:
Maciej Jur 2024-04-30 23:43:22 +02:00
parent 700a93a5ee
commit 3a82e64901
Signed by: kamov
GPG key ID: 191CBFF5F72ECAFD
2 changed files with 19 additions and 22 deletions

View file

@ -1,4 +1,4 @@
use hypertext::{html_elements, maud_move, GlobalAttributes, Renderable}; use hypertext::{html_elements, maud_move, GlobalAttributes, Raw, Renderable};
use crate::gen::{Sack, TreePage}; use crate::gen::{Sack, TreePage};
use crate::text::md::Outline; use crate::text::md::Outline;
@ -36,7 +36,7 @@ pub fn show_bibliography(bib: Vec<String>) -> impl Renderable {
ol .bibliography { ol .bibliography {
@for item in bib { @for item in bib {
li { li {
(item) (Raw(item))
} }
} }
} }

View file

@ -1,6 +1,6 @@
use std::collections::HashMap; use std::collections::HashMap;
use hayagriva::{archive::ArchivedStyle, citationberg::{IndependentStyle, Locale, Style}, BibliographyDriver, BibliographyRequest, CitationItem, CitationRequest, Library}; use hayagriva::{archive::ArchivedStyle, citationberg::{IndependentStyle, Locale, Style}, BibliographyDriver, BibliographyRequest, BufWriteFormat, CitationItem, CitationRequest, Library};
use hypertext::Renderable; use hypertext::Renderable;
use once_cell::sync::Lazy; use once_cell::sync::Lazy;
use pulldown_cmark::{CodeBlockKind, Event, Options, Parser, Tag, TagEnd, TextMergeStream}; use pulldown_cmark::{CodeBlockKind, Event, Options, Parser, Tag, TagEnd, TextMergeStream};
@ -93,32 +93,29 @@ fn make_bib<'a, 'b>(stream: Vec<Event<'a>>, lib: &'b Library) -> (Vec<Event<'a>>
let mut n = 0; let mut n = 0;
let stream = stream.into_iter() let stream = stream.into_iter()
.map(|event| match event { .map(|event| match event {
Event::InlineMath(_) => { Event::InlineMath(name) => {
let rf = match res.citations.get(n) { let mut buffer = String::from("<cite>");
Some(rf) => rf, match res.citations.get(n) {
None => return event, Some(rf) => rf.citation.write_buf(&mut buffer, BufWriteFormat::Html).unwrap(),
None => buffer.push_str(&name),
}; };
let rf = rf.citation.to_string().replace("\u{1b}[0m", ""); buffer.push_str("</cite>");
let rf = format!("<cite>{}</cite>", rf);
n += 1; n += 1;
Event::InlineHtml(rf.into()) Event::InlineHtml(buffer.into())
}, },
_ => event _ => event
}) })
.collect(); .collect();
let bib = match res.bibliography { let bib = res.bibliography.map(|bib|
Some(ref bib) => { bib.items.iter()
let test = bib.items.iter() .map(|x| {
.map(|x| x.content.to_string() let mut buffer = String::new();
.replace("\u{1b}[0m", "") x.content.write_buf(&mut buffer, BufWriteFormat::Html).unwrap();
.replace("\u{01b}[3mA", "") buffer
) })
.collect::<Vec<_>>(); .collect::<Vec<_>>()
Some(test) );
},
None => None,
};
(stream, bib) (stream, bib)
} }