mirror of
https://github.com/lise-henry/crowbook
synced 2024-05-27 13:06:15 +02:00
Replace rustc-serialize dependency with base64
This commit is contained in:
parent
079388b663
commit
0ff64adee9
|
@ -54,7 +54,7 @@ yaml-rust = "0.4"
|
|||
mustache = "0.9"
|
||||
uuid = { version = "1", features = ["v4"] }
|
||||
walkdir = "2"
|
||||
rustc-serialize = "0.3"
|
||||
base64 = "0.21"
|
||||
rayon = "1.6"
|
||||
crowbook-text-processing = "^1.1.1"
|
||||
lazy_static = "1"
|
||||
|
|
|
@ -23,8 +23,7 @@ use crate::html::HtmlRenderer;
|
|||
use crate::parser::Parser;
|
||||
use crate::renderer::Renderer;
|
||||
use crate::token::Token;
|
||||
|
||||
use rustc_serialize::base64::{self, ToBase64};
|
||||
use crate::misc;
|
||||
|
||||
use std::convert::{AsMut, AsRef};
|
||||
use std::io;
|
||||
|
@ -333,12 +332,11 @@ return crowbook_return_variable.replace(/<\\/ul><ul>/g, '');\n",
|
|||
);
|
||||
}
|
||||
if self.html.highlight == Highlight::Js {
|
||||
let highlight_js = self
|
||||
let highlight_js = misc::u8_to_base64(&self
|
||||
.html
|
||||
.book
|
||||
.get_template("html.highlight.js")?
|
||||
.as_bytes()
|
||||
.to_base64(base64::STANDARD);
|
||||
.as_bytes());
|
||||
let highlight_js = format!("data:text/javascript;base64,{highlight_js}");
|
||||
mapbuilder = mapbuilder
|
||||
.insert_bool("highlight_code", true)
|
||||
|
|
|
@ -24,8 +24,7 @@ use crate::parser::Parser;
|
|||
use crate::renderer::Renderer;
|
||||
use crate::templates::img;
|
||||
use crate::token::Token;
|
||||
|
||||
use rustc_serialize::base64::{self, ToBase64};
|
||||
use crate::misc;
|
||||
|
||||
use std::convert::{AsMut, AsRef};
|
||||
use std::fmt::Write;
|
||||
|
@ -78,13 +77,13 @@ impl<'a> HtmlSingleRenderer<'a> {
|
|||
|
||||
/// Render books as a standalone HTML file
|
||||
pub fn render_book(&mut self) -> Result<String> {
|
||||
let menu_svg = img::MENU_SVG.to_base64(base64::STANDARD);
|
||||
let menu_svg = misc::u8_to_base64(&img::MENU_SVG);
|
||||
let menu_svg = format!("data:image/svg+xml;base64,{menu_svg}");
|
||||
|
||||
let book_svg = img::BOOK_SVG.to_base64(base64::STANDARD);
|
||||
let book_svg = misc::u8_to_base64(&img::BOOK_SVG);
|
||||
let book_svg = format!("data:image/svg+xml;base64,{book_svg}");
|
||||
|
||||
let pages_svg = img::PAGES_SVG.to_base64(base64::STANDARD);
|
||||
let pages_svg = misc::u8_to_base64(&img::PAGES_SVG);
|
||||
let pages_svg = format!("data:image/svg+xml;base64,{pages_svg}");
|
||||
|
||||
let mut content = String::new();
|
||||
|
@ -305,12 +304,11 @@ impl<'a> HtmlSingleRenderer<'a> {
|
|||
mapbuilder = mapbuilder.insert_str("toc", toc)
|
||||
}
|
||||
if self.html.highlight == Highlight::Js {
|
||||
let highlight_js = self
|
||||
let highlight_js = misc::u8_to_base64(&self
|
||||
.html
|
||||
.book
|
||||
.get_template("html.highlight.js")?
|
||||
.as_bytes()
|
||||
.to_base64(base64::STANDARD);
|
||||
.as_bytes());
|
||||
let highlight_js = format!("data:text/javascript;base64,{highlight_js}");
|
||||
mapbuilder = mapbuilder
|
||||
.insert_bool("highlight_code", true)
|
||||
|
|
|
@ -21,6 +21,8 @@ use crate::token::Token;
|
|||
|
||||
use std::io::Result;
|
||||
use std::path::{Path, PathBuf};
|
||||
use base64::Engine;
|
||||
|
||||
|
||||
/// Try to canonicalize a path using std::fs::canonicalize, and returns the
|
||||
/// unmodified path if it fails (e.g. if the path doesn't exist (yet))
|
||||
|
@ -59,3 +61,7 @@ pub fn insert_title(tokens: &mut Vec<Token>) {
|
|||
tokens.insert(0, Token::Header(1, vec![]));
|
||||
}
|
||||
|
||||
/// Convert to base 64
|
||||
pub fn u8_to_base64(s: &[u8]) -> String {
|
||||
base64::engine::general_purpose::STANDARD_NO_PAD.encode(s)
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
use crate::error::{Error, Result, Source};
|
||||
use crate::token::Token;
|
||||
use crate::misc;
|
||||
|
||||
use std::borrow::Cow;
|
||||
use std::collections::HashMap;
|
||||
|
@ -7,7 +8,6 @@ use std::fs;
|
|||
use std::io::Read;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use rustc_serialize::base64::{self, ToBase64};
|
||||
use walkdir::WalkDir;
|
||||
|
||||
/// Resource Handler.
|
||||
|
@ -134,7 +134,7 @@ impl ResourceHandler {
|
|||
);
|
||||
return Ok(file);
|
||||
}
|
||||
let base64 = content.to_base64(base64::STANDARD);
|
||||
let base64 = misc::u8_to_base64(&content);
|
||||
match mime_guess::from_path(file.as_ref()).first() {
|
||||
None => {
|
||||
error!(
|
||||
|
|
Loading…
Reference in New Issue