Merge pull request #11 from Trivernis/develop

HTML Metadata
pull/17/head v0.32.1
Trivernis 4 years ago committed by GitHub
commit d93fe6a57b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

430
Cargo.lock generated

File diff suppressed because it is too large Load Diff

@ -1,6 +1,6 @@
[package]
name = "snekdown"
version = "0.32.0"
version = "0.32.1"
authors = ["trivernis <trivernis@protonmail.com>"]
edition = "2018"
license-file = "LICENSE"

@ -162,6 +162,12 @@ Placeholders are always case insensitive.
Insert the table of contents
[[TOC]]
Insert the bibliography list
[[BIB]]
Insert the glossary
[[GLS]]
Insert the current date
[[date]]
@ -209,6 +215,17 @@ language = 'en'
# author of the document
author = 'author'
# Title of the document
title = 'title'
# A short description for the document preview
description = '''
Description
'''
# Keywords to find the document
keywords = ['HTML', 'Snekdown']
# features used in the document
[features]
@ -412,6 +429,7 @@ The format ~HTML is not considered a programming language by some definitions.
The first occurence of the glossary entry (`~HTML`) always uses the long form.
The second will always be the short form. The long form can be enforced by using two
(`~~HTML`) tildes.
The glossary list can be inserted with the `[[GLS]]` placeholder.
## Math

@ -1,5 +1,5 @@
use serde::export::fmt::{self, Display};
use std::error::Error;
use std::fmt::{self, Display};
use std::io;
pub type PdfRenderingResult<T> = Result<T, PdfRenderingError>;

@ -105,16 +105,51 @@ impl ToHtml for Document {
};
if self.is_root {
let language = self.config.lock().metadata.language.clone();
let metadata = self.config.lock().metadata.clone();
let style = minify(get_css_for_theme(writer.get_theme()).as_str());
writer.write("<!DOCTYPE html>".to_string())?;
writer.write("<html lang=\"".to_string())?;
writer.write_attribute(language)?;
writer.write_attribute(metadata.language)?;
writer.write("\"><head ".to_string())?;
writer.write(path)?;
writer.write("/>".to_string())?;
writer.write("<meta charset=\"UTF-8\">".to_string())?;
if let Some(author) = metadata.author {
writer.write("<meta name=\"author\" content=\"".to_string())?;
writer.write_attribute(author)?;
writer.write("\">".to_string())?;
}
if let Some(title) = metadata.title {
writer.write("<title>".to_string())?;
writer.write_escaped(title.clone())?;
writer.write("</title>".to_string())?;
writer.write("<meta name=\"title\" content=\"".to_string())?;
writer.write_attribute(title)?;
writer.write("\">".to_string())?;
}
if let Some(description) = metadata.description {
writer.write("<meta name=\"description\" content=\"".to_string())?;
writer.write_attribute(description)?;
writer.write("\">".to_string())?;
}
if !metadata.keywords.is_empty() {
writer.write("<meta name=\"keywords\" content=\"".to_string())?;
writer.write_attribute(
metadata
.keywords
.iter()
.fold("".to_string(), |a, b| format!("{}, {}", a, b))
.trim_start_matches(", ")
.to_string(),
)?;
writer.write("\">".to_string())?;
}
writer.write("<style>".to_string())?;
writer.write(style)?;
writer.write("</style>".to_string())?;

@ -4,6 +4,8 @@ use serde::{Deserialize, Serialize};
pub struct MetadataSettings {
pub title: Option<String>,
pub author: Option<String>,
pub description: Option<String>,
pub keywords: Vec<String>,
pub language: String,
}
@ -12,6 +14,8 @@ impl Default for MetadataSettings {
Self {
title: None,
author: None,
description: None,
keywords: Vec::new(),
language: "en".to_string(),
}
}

Loading…
Cancel
Save