From 3a82e64901ca3eb84881af8a612b8f52767e1327 Mon Sep 17 00:00:00 2001 From: Maciej Jur Date: Tue, 30 Apr 2024 23:43:22 +0200 Subject: [PATCH] fix: render bibliography as raw HTML --- src/html/misc.rs | 4 ++-- src/text/md.rs | 37 +++++++++++++++++-------------------- 2 files changed, 19 insertions(+), 22 deletions(-) diff --git a/src/html/misc.rs b/src/html/misc.rs index 17ae495..3fba7d3 100644 --- a/src/html/misc.rs +++ b/src/html/misc.rs @@ -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::text::md::Outline; @@ -36,7 +36,7 @@ pub fn show_bibliography(bib: Vec) -> impl Renderable { ol .bibliography { @for item in bib { li { - (item) + (Raw(item)) } } } diff --git a/src/text/md.rs b/src/text/md.rs index 473eb7a..5129339 100644 --- a/src/text/md.rs +++ b/src/text/md.rs @@ -1,6 +1,6 @@ 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 once_cell::sync::Lazy; use pulldown_cmark::{CodeBlockKind, Event, Options, Parser, Tag, TagEnd, TextMergeStream}; @@ -93,32 +93,29 @@ fn make_bib<'a, 'b>(stream: Vec>, lib: &'b Library) -> (Vec> let mut n = 0; let stream = stream.into_iter() .map(|event| match event { - Event::InlineMath(_) => { - let rf = match res.citations.get(n) { - Some(rf) => rf, - None => return event, + Event::InlineMath(name) => { + let mut buffer = String::from(""); + match res.citations.get(n) { + 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", ""); - let rf = format!("{}", rf); + buffer.push_str(""); n += 1; - Event::InlineHtml(rf.into()) + Event::InlineHtml(buffer.into()) }, _ => event }) .collect(); - let bib = match res.bibliography { - Some(ref bib) => { - let test = bib.items.iter() - .map(|x| x.content.to_string() - .replace("\u{1b}[0m", "") - .replace("\u{01b}[3mA", "") - ) - .collect::>(); - Some(test) - }, - None => None, - }; + let bib = res.bibliography.map(|bib| + bib.items.iter() + .map(|x| { + let mut buffer = String::new(); + x.content.write_buf(&mut buffer, BufWriteFormat::Html).unwrap(); + buffer + }) + .collect::>() + ); (stream, bib) }