summaryrefslogtreecommitdiff
path: root/src/doc.rs
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2023-04-05 19:02:33 +0300
committerLars Wirzenius <liw@liw.fi>2023-04-08 16:56:17 +0300
commit96e20dcd5256e18bd5a0bad237af078bfdfcf694 (patch)
tree0c382e26a17b74a4c025f8bf67f6eeabf51194e3 /src/doc.rs
parentb4c998c713be9236e8c3e42ec64bd3ec9ac9bf27 (diff)
downloadsubplot-96e20dcd5256e18bd5a0bad237af078bfdfcf694.tar.gz
feat: drop use of Pandoc from doc.rs
Sponsored-by: author
Diffstat (limited to 'src/doc.rs')
-rw-r--r--src/doc.rs35
1 files changed, 18 insertions, 17 deletions
diff --git a/src/doc.rs b/src/doc.rs
index fa98a2f..459b0e7 100644
--- a/src/doc.rs
+++ b/src/doc.rs
@@ -1,6 +1,8 @@
use crate::bindings::CaptureType;
use crate::generate_test_program;
use crate::get_basedir_from;
+use crate::html::Element;
+use crate::html::HtmlPage;
use crate::md::Markdown;
use crate::EmbeddedFile;
use crate::EmbeddedFiles;
@@ -102,11 +104,6 @@ impl Document {
{
let meta = Metadata::from_yaml_metadata(basedir, yamlmeta, template)?;
trace!("metadata from YAML: {:#?}", meta);
- let mut issues = md.lint();
- if !issues.is_empty() {
- // Currently we can't really return more than one error so return one
- return Err(issues.remove(0));
- }
let files = md.embedded_files();
let doc = Document::new(subplot, md, meta, files, style);
trace!("Loaded from JSON OK");
@@ -114,10 +111,6 @@ impl Document {
}
/// Construct a Document from a named file.
- ///
- /// The file can be in any format Pandoc understands. This runs
- /// Pandoc to parse the file into an AST, so it can be a little
- /// slow.
pub fn from_file(
basedir: &Path,
filename: &Path,
@@ -144,12 +137,17 @@ impl Document {
Ok(doc)
}
- /// Return the AST of a Document, serialized as JSON.
- ///
- /// This is useful in a Pandoc filter, so that the filter can give
- /// it back to Pandoc for typesetting.
- pub fn ast(&self) -> Result<String, SubplotError> {
- self.md.to_json()
+ /// Return Document as an HTML page serialized into HTML text
+ pub fn to_html(&mut self, date: &str) -> String {
+ let mut head = Element::new(crate::html::ElementTag::Head);
+ let mut title = Element::new(crate::html::ElementTag::Title);
+ title.push_child(crate::html::Content::Text(self.meta().title().into()));
+ head.push_child(crate::html::Content::Elt(title));
+
+ self.md.set_date(date.into());
+
+ let page = HtmlPage::new(head, self.md.to_html());
+ page.serialize().unwrap() // FIXME
}
/// Return the document's metadata.
@@ -157,6 +155,11 @@ impl Document {
&self.meta
}
+ /// Set document date.
+ pub fn set_date(&mut self, date: String) {
+ self.meta.set_date(date);
+ }
+
/// Return all source filenames for the document.
///
/// The sources are any files that affect the output so that if
@@ -404,8 +407,6 @@ fn load_metadata_from_yaml_file(filename: &Path) -> Result<YamlMetadata, Subplot
}
/// Load a `Document` from a file.
-///
-/// This version uses Pandoc to parse the Markdown.
pub fn load_document<P>(
filename: P,
style: Style,