Sort imports with the help of rustfmt.
This commit is contained in:
parent
2991b10598
commit
17759c3210
6 changed files with 28 additions and 14 deletions
|
|
@ -9,3 +9,5 @@ brace_style = "PreferSameLine"
|
||||||
blank_lines_upper_bound = 5
|
blank_lines_upper_bound = 5
|
||||||
combine_control_expr = false
|
combine_control_expr = false
|
||||||
wrap_comments = false
|
wrap_comments = false
|
||||||
|
group_imports = "StdExternalCrate"
|
||||||
|
imports_granularity = "Crate"
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
use htmlua_parser::serve::serve_content;
|
|
||||||
use std::env;
|
use std::env;
|
||||||
|
|
||||||
|
use htmlua_parser::serve::serve_content;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
println!("Content-Type: text/html\n");
|
println!("Content-Type: text/html\n");
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
|
use std::{fs, path::PathBuf};
|
||||||
|
|
||||||
use anyhow::{Context, Result};
|
use anyhow::{Context, Result};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::{fs, path::PathBuf};
|
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Serialize, Clone)]
|
#[derive(Debug, Deserialize, Serialize, Clone)]
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
|
pub mod config;
|
||||||
pub mod helpers;
|
pub mod helpers;
|
||||||
pub mod htmlua_stdlib;
|
pub mod htmlua_stdlib;
|
||||||
pub mod config;
|
|
||||||
pub mod render;
|
pub mod render;
|
||||||
pub mod serve;
|
pub mod serve;
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ use std::{
|
||||||
rc::Rc,
|
rc::Rc,
|
||||||
};
|
};
|
||||||
|
|
||||||
use anyhow::{anyhow, Result};
|
use anyhow::{Result, anyhow};
|
||||||
use kuchikiki::{NodeRef, traits::TendrilSink};
|
use kuchikiki::{NodeRef, traits::TendrilSink};
|
||||||
use markup5ever::{LocalName, Namespace, QualName};
|
use markup5ever::{LocalName, Namespace, QualName};
|
||||||
use mlua::{Lua, Table};
|
use mlua::{Lua, Table};
|
||||||
|
|
@ -182,19 +182,27 @@ pub fn process_syntax_highlighting(document: NodeRef) -> Result<NodeRef> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn generate_footnotes(document: NodeRef) -> Result<NodeRef> {
|
pub fn generate_footnotes(document: NodeRef) -> Result<NodeRef> {
|
||||||
let Ok(footnote_container) = document.select_first("footnotecontainer") else { return Ok(document) };
|
let Ok(footnote_container) = document.select_first("footnotecontainer") else {
|
||||||
|
return Ok(document);
|
||||||
|
};
|
||||||
|
|
||||||
let ctx_name = QualName::new(None, Namespace::from("http://www.w3.org/1999/xhtml"), LocalName::from("div"));
|
let ctx_name = QualName::new(None, Namespace::from("http://www.w3.org/1999/xhtml"), LocalName::from("div"));
|
||||||
for (i, footnote) in document.select("footnote").map_err(|()| anyhow!("Failed to get footnote"))?.enumerate() {
|
for (i, footnote) in document
|
||||||
|
.select("footnote")
|
||||||
|
.map_err(|()| anyhow!("Failed to get footnote"))?
|
||||||
|
.enumerate()
|
||||||
|
{
|
||||||
let i = i + 1;
|
let i = i + 1;
|
||||||
let fn_text = footnote.text_contents();
|
let fn_text = footnote.text_contents();
|
||||||
let sup_tag = kuchikiki::parse_fragment(ctx_name.clone(), Vec::new()).one(
|
let sup_tag = kuchikiki::parse_fragment(ctx_name.clone(), Vec::new())
|
||||||
format!("<a href=#ft-text-{i}><sup id=\"ft-sup-{i}\" title=\"{fn_text}\">{i}</sup></a>")
|
.one(format!("<a href=#ft-text-{i}><sup id=\"ft-sup-{i}\" title=\"{fn_text}\">{i}</sup></a>"))
|
||||||
).select_first("a").map_err(|()| anyhow!("parse err"))?;
|
.select_first("a")
|
||||||
|
.map_err(|()| anyhow!("parse err"))?;
|
||||||
footnote.as_node().insert_after(sup_tag.as_node().clone());
|
footnote.as_node().insert_after(sup_tag.as_node().clone());
|
||||||
let text_tag = kuchikiki::parse_fragment(ctx_name.clone(), Vec::new()).one(
|
let text_tag = kuchikiki::parse_fragment(ctx_name.clone(), Vec::new())
|
||||||
format!("<p id=\"ft-text-{i}\"><a href=#ft-sup-{i}>{i}:</a> {fn_text}</p>")
|
.one(format!("<p id=\"ft-text-{i}\"><a href=#ft-sup-{i}>{i}:</a> {fn_text}</p>"))
|
||||||
).select_first("p").map_err(|()| anyhow!("parse err"))?;
|
.select_first("p")
|
||||||
|
.map_err(|()| anyhow!("parse err"))?;
|
||||||
footnote_container.as_node().insert_before(text_tag.as_node().clone());
|
footnote_container.as_node().insert_before(text_tag.as_node().clone());
|
||||||
}
|
}
|
||||||
while let Ok(i) = document.select_first("footnote") {
|
while let Ok(i) = document.select_first("footnote") {
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,12 @@
|
||||||
|
use std::{path::Path, sync::OnceLock};
|
||||||
|
|
||||||
|
use anyhow::Result;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
config::Config,
|
config::Config,
|
||||||
helpers::read_doc_from_file,
|
helpers::read_doc_from_file,
|
||||||
render::{execute_lua, expand_template, process_markdown, process_syntax_highlighting},
|
render::{execute_lua, expand_template, process_markdown, process_syntax_highlighting},
|
||||||
};
|
};
|
||||||
use anyhow::Result;
|
|
||||||
use std::{path::Path, sync::OnceLock};
|
|
||||||
|
|
||||||
static CONFIG: OnceLock<Config> = OnceLock::new();
|
static CONFIG: OnceLock<Config> = OnceLock::new();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue