Adopt and apply nightly rustfmt configuration

This commit is contained in:
Juno Takano 2026-02-16 16:17:10 -03:00
commit d7d034757a
45 changed files with 431 additions and 474 deletions

View file

@ -1,27 +1,33 @@
unstable_features = true
match_block_trailing_comma = true
max_width = 80
reorder_imports = false
reorder_modules = false
use_field_init_shorthand = true
use_try_shorthand = true
inline_attribute_width = 40
skip_macro_invocations = ["concat"]
# not stabilized yet
# blank_lines_lower_bound = 1
# where_single_line = true
# overflow_delimited_expr = true
# normalize_doc_attributes = true
# normalize_comments = true
# inline_attribute_width = 40
# imports_granularity = "Crate"
# hex_literal_case = "Lower"
# group_imports = "StdExternalCrate"
# format_strings = true
# force_multiline_blocks = true
# error_on_unformatted = true
# error_on_line_overflow = true
# condense_wildcard_suffixes = true
# doc_comment_code_block_width = 70
# format_code_in_doc_comments = true
# wrap_comments = true
imports_granularity = "Crate"
group_imports = "StdExternalCrate"
fn_single_line = true
match_block_trailing_comma = true
use_field_init_shorthand = true
use_try_shorthand = true
hex_literal_case = "Lower"
where_single_line = true
condense_wildcard_suffixes = true
combine_control_expr = false
empty_item_single_line = true
reorder_impl_items = true
trailing_semicolon = false
wrap_comments = true
normalize_comments = true
normalize_doc_attributes = true
format_code_in_doc_comments = true
doc_comment_code_block_width = 70
error_on_unformatted = true
error_on_line_overflow = true
ignore = [
"tests/mocks",
]

View file

@ -1,24 +1,24 @@
use std::{collections::HashMap, path::PathBuf};
use serde::{Serialize, Deserialize};
pub use edge::Edge;
pub use meta::{Config, Meta};
pub use node::Node;
use serde::{Deserialize, Serialize};
use crate::syntax::{
command::Arguments,
content::{
self,
parser::{flatten, Token, token::Anchor},
use crate::{
prelude::*,
syntax::{
command::Arguments,
content::{
self,
parser::{Token, flatten, token::Anchor},
},
},
};
use crate::prelude::*;
pub use {
node::Node,
edge::Edge,
meta::{Meta, Config},
};
pub mod node;
pub mod edge;
pub mod meta;
pub mod node;
#[derive(Serialize, Deserialize, Clone, Default, PartialEq, Eq, Debug)]
pub struct Graph {
@ -399,7 +399,7 @@ impl Graph {
} else {
log!(
VERBOSE,
"Chasing candidate for query {query}, collapsed {collapsed_query}"
"Chasing candidate: query {query}, collapsed {collapsed_query}"
);
}

View file

@ -1,4 +1,4 @@
use serde::{Serialize, Deserialize};
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Clone, Default, PartialEq, Eq, Debug)]
pub struct Edge {

View file

@ -1,6 +1,6 @@
use crate::prelude::*;
use serde::{Deserialize, Serialize};
use serde::{Serialize, Deserialize};
use crate::prelude::*;
#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, Debug)]
pub struct Meta {
@ -105,15 +105,9 @@ impl Default for Config {
}
// See: https://github.com/serde-rs/serde/issues/368
fn mktrue() -> bool {
true
}
fn mkfalse() -> bool {
false
}
fn mk8() -> u16 {
8
}
fn mktrue() -> bool { true }
fn mkfalse() -> bool { false }
fn mk8() -> u16 { 8 }
#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, Debug)]
pub struct Version {
@ -314,9 +308,8 @@ impl std::fmt::Display for VersionErrorCause {
#[cfg(test)]
mod tests {
use crate::graph::Graph;
use super::*;
use crate::graph::Graph;
#[test]
fn empty_footer_text() {

View file

@ -1,6 +1,6 @@
use std::collections::HashMap;
use serde::{Serialize, Deserialize};
use serde::{Deserialize, Serialize};
use super::edge::Edge;
@ -118,7 +118,9 @@ mod tests {
assert_eq!(
format!("{node}"),
format!(
"Node 404 [title:'Not Found' text:15l summary:{} redirect:{redirect}]",
"Node 404 [title:'Not Found' \
text:15l summary:{} \
redirect:{redirect}]",
summary.len(),
)
);

View file

@ -1,16 +1,17 @@
use std::{sync, time};
pub mod prelude {
pub use crate::log;
pub use crate::tlog;
pub use crate::log::Level::*;
pub use crate::log::now;
pub use crate::{
log,
log::{Level::*, now},
tlog,
};
}
pub mod graph;
pub mod log;
pub mod router;
pub mod syntax;
pub mod log;
pub static ONSET: sync::LazyLock<time::Instant> =
sync::LazyLock::new(time::Instant::now);

View file

@ -32,7 +32,7 @@ impl Data {
let path = make_display_path(captured_path, &env_level);
let is_silent = env_level <= Level::SILENT;
let message_level_is_within_env_level = message_level <= env_level;
let level_within_env_level = message_level <= env_level;
let excluded_in_code =
!EXCLUSIONS.iter().all(|&s| !trace_string.contains(s));
let excluded_by_env =
@ -41,7 +41,7 @@ impl Data {
filter.is_empty() || captured_path.contains(&filter);
let should_log = !is_silent
&& message_level_is_within_env_level
&& level_within_env_level
&& !excluded_in_code
&& !excluded_by_env
&& matches_filter;
@ -51,7 +51,7 @@ impl Data {
eprintln!(
"Log decision for message from {path}: {should_log} given\n\
is_silent: {is_silent} (expected false)\n\
message_level_is_within_env_level: {message_level_is_within_env_level}\n\
level_within_env_level: {level_within_env_level}\n\
excluded_in_code: {excluded_in_code} (expected false)\n\
excluded_by_env: {excluded_by_env} (expected false)\n\
matches_filter: {matches_filter}\n\
@ -118,9 +118,7 @@ macro_rules! tlog {
}};
}
pub fn now() -> Instant {
Instant::now()
}
pub fn now() -> Instant { Instant::now() }
#[allow(clippy::print_stderr)]
pub fn elog(function: &str, message: &str) {
@ -211,9 +209,7 @@ pub fn wrap(s: &str) -> String {
}
}
fn escape(s: &str) -> String {
s.escape_debug().collect()
}
fn escape(s: &str) -> String { s.escape_debug().collect() }
symbolize(&quote(&escape(s)))
}

View file

@ -3,13 +3,13 @@ use axum::{Router, routing::get};
use crate::graph::Graph;
mod handlers {
pub mod graph;
pub mod template;
pub mod raw;
pub mod navigation;
pub mod fixed;
pub mod error;
pub mod fixed;
pub mod graph;
pub mod mime;
pub mod navigation;
pub mod raw;
pub mod template;
}
#[derive(Clone)]
@ -49,11 +49,6 @@ pub fn new(graph: Graph) -> Router {
#[cfg(test)]
mod tests {
use crate::{
graph::{Graph, Config, Meta},
};
use super::*;
use axum::{
body::Body,
http::{Request, StatusCode},
@ -61,6 +56,9 @@ mod tests {
};
use tower::ServiceExt as _;
use super::*;
use crate::graph::{Config, Graph, Meta};
async fn request(uri: &str, config: Option<&Config>) -> Response<Body> {
let default_graph = Graph::load();
let graph = Graph {

View file

@ -68,10 +68,8 @@ pub async fn not_found(State(state): State<GlobalState>) -> Response<Body> {
#[cfg(test)]
mod tests {
use axum::{
http::{StatusCode},
extract::State,
};
use axum::{extract::State, http::StatusCode};
use super::*;
#[tokio::test]

View file

@ -1,16 +1,13 @@
use axum::{
body::Body,
extract::{Path, State},
http::{HeaderValue, Response, StatusCode, header},
{
body::Body,
extract::{Path, State},
},
};
use crate::prelude::*;
use crate::{
graph::{Format, Graph, SerialErrorCause},
router::{GlobalState, handlers},
router::handlers::mime::Mime,
prelude::*,
router::{GlobalState, handlers, handlers::mime::Mime},
};
pub async fn file(

View file

@ -1,7 +1,8 @@
use axum::{
extract::State,
response::IntoResponse as _,
{body::Body, extract::Path, http::Response, response::Redirect},
body::Body,
extract::{Path, State},
http::Response,
response::{IntoResponse as _, Redirect},
};
use crate::{
@ -49,13 +50,10 @@ pub async fn node(
#[cfg(test)]
mod tests {
use axum::{
http::{HeaderName, StatusCode},
};
use crate::graph::{Format, Graph};
use axum::http::{HeaderName, StatusCode};
use super::*;
use crate::graph::{Format, Graph};
async fn wrap_node(query: &str) -> Response<Body> {
let state = GlobalState {

View file

@ -1,4 +1,6 @@
use axum::{Form, body::Body, extract::State, http::Response, response::Redirect};
use axum::{
Form, body::Body, extract::State, http::Response, response::Redirect,
};
use crate::{
prelude::*,
@ -58,9 +60,9 @@ pub struct Query {
#[cfg(test)]
mod tests {
use axum::http::StatusCode;
use crate::graph::Graph;
use super::*;
use crate::graph::Graph;
async fn wrap_page(path: &str) -> Response<Body> {
let state = GlobalState {

View file

@ -1,6 +1,6 @@
use axum::{
body::Body,
http::{header, HeaderValue, Response, StatusCode},
http::{HeaderValue, Response, StatusCode, header},
};
use crate::prelude::*;

View file

@ -1,6 +1,6 @@
use axum::{
body::Body,
http::{header, Response, StatusCode},
http::{Response, StatusCode, header},
};
use crate::{
@ -135,9 +135,8 @@ fn emergency_wrap(error: &tera::Error) -> String {
#[cfg(test)]
mod tests {
use crate::graph::Graph;
use super::*;
use crate::graph::Graph;
#[test]
fn by_filename_forced_error() {

View file

@ -1,6 +1,6 @@
use std::mem::discriminant;
use parser::{Token, Lexeme};
use parser::{Lexeme, Token};
use crate::graph::Graph;
@ -43,9 +43,7 @@ impl TokenOutput {
}
}
pub fn parse(text: &str, graph: &Graph) -> String {
parser::read(text, graph)
}
pub fn parse(text: &str, graph: &Graph) -> String { parser::read(text, graph) }
pub fn rich_parse(text: &str, graph: &Graph) -> TokenOutput {
parser::rich_read(text, graph)
@ -53,9 +51,8 @@ pub fn rich_parse(text: &str, graph: &Graph) -> TokenOutput {
#[cfg(test)]
mod tests {
use crate::syntax::content::parser::token::{Bold, Oblique};
use super::*;
use crate::syntax::content::parser::token::{Bold, Oblique};
#[test]
fn only() {

View file

@ -1,15 +1,18 @@
use crate::{prelude::*, graph::Graph, syntax::content::TokenOutput};
use context::{Block, Inline};
pub use lexeme::Lexeme;
use lexer::{LEXMAP, lex};
pub use {lexeme::Lexeme, token::Token, state::State};
pub use state::State;
pub use token::Token;
use crate::{graph::Graph, prelude::*, syntax::content::TokenOutput};
pub mod token;
pub mod lexer;
pub mod lexeme;
pub mod segment;
pub mod context;
pub mod lexeme;
pub mod lexer;
pub mod point;
pub mod segment;
pub mod state;
pub mod token;
fn parse(tokens: &[Token]) -> String {
tokens.iter().map(Token::render).collect::<String>()
@ -46,16 +49,10 @@ pub fn flatten(input: &str, graph: &Graph) -> String {
#[cfg(test)]
mod tests {
use crate::{
graph::Graph,
syntax::content::parser::{token::header::Level},
};
use super::*;
use crate::{graph::Graph, syntax::content::parser::token::header::Level};
fn read_noconfig(input: &str) -> String {
read(input, &Graph::default())
}
fn read_noconfig(input: &str) -> String { read(input, &Graph::default()) }
#[test]
fn empty_render_is_empty() {
@ -65,7 +62,10 @@ mod tests {
#[test]
fn mixed_sample() {
let en = "`this |test|` tries ## to |brea|k|: things";
let html = r#"<p><code>this |test|</code> tries ## to <a class="detached" title="" href="/node/k">brea</a>: things</p>"#;
let html = concat!(
r#"<p><code>this |test|</code> tries ## to <a "#,
r#"class="detached" title="" href="/node/k">brea</a>: things</p>"#,
);
assert_eq!(read_noconfig(en), html);
}

View file

@ -3,9 +3,9 @@ use crate::syntax::content::parser::{
token::{Header, Paragraph, PreFormat, Verse},
};
pub mod anchor;
pub mod block;
pub mod inline;
pub mod anchor;
pub mod list;
pub mod quote;
pub mod table;
@ -68,7 +68,7 @@ pub fn close(state: &State, tokens: &mut Vec<Token>) {
#[cfg(test)]
mod tests {
use crate::syntax::content::parser::{context::Block, State};
use crate::syntax::content::parser::{State, context::Block};
#[test]
#[should_panic(expected = "End of input with open list")]

View file

@ -1,7 +1,7 @@
use crate::{
prelude::*,
syntax::content::parser::{context::Inline, Lexeme, State, Token},
graph::Graph,
prelude::*,
syntax::content::parser::{Lexeme, State, Token, context::Inline},
};
/// Handles open anchor contexts until an anchor token is fully parsed.
@ -162,11 +162,9 @@ fn push(
#[cfg(test)]
mod tests {
use crate::{syntax::content::parser, graph::Graph};
use crate::{graph::Graph, syntax::content::parser};
fn read(input: &str) -> String {
parser::read(input, &Graph::default())
}
fn read(input: &str) -> String { parser::read(input, &Graph::default()) }
#[test]
fn flanking() {
@ -188,7 +186,10 @@ mod tests {
fn flanking_with_trailing_comma_and_space() {
assert_eq!(
read("|Node|, at"),
r#"<p><a class="detached" title="" href="/node/Node">Node</a>, at</p>"#
concat!(
r#"<p><a class="detached" title="" "#,
r#"href="/node/Node">Node</a>, at</p>"#,
)
);
}
@ -204,7 +205,8 @@ mod tests {
fn needless_three_pipe_anchor() {
assert_eq!(
read("|Node|Destination|"),
r#"<p><a class="detached" title="" href="/node/Destination">Node</a></p>"#
concat!(r#"<p><a class="detached" title="" "#,
r#"href="/node/Destination">Node</a></p>"#)
);
}
@ -212,7 +214,10 @@ mod tests {
fn nonleading_second_pipe() {
assert_eq!(
read("Go to Node|Destination|, here"),
r#"<p>Go to <a class="detached" title="" href="/node/Destination">Node</a>, here</p>"#,
concat!(
r#"<p>Go to <a class="detached" title="" "#,
r#"href="/node/Destination">Node</a>, here</p>"#
),
);
}
@ -220,7 +225,9 @@ mod tests {
fn anchor_to_node_s() {
assert_eq!(
read("The |letter s|s|'s node: |s|!"),
r#"<p>The <a class="detached" title="" href="/node/s">letter s</a>'s node: <a class="detached" title="" href="/node/s">s</a>!</p>"#
concat!(r#"<p>The <a class="detached" title="" "#,
r#"href="/node/s">letter s</a>'s node: "#,
r#"<a class="detached" title="" href="/node/s">s</a>!</p>"#)
);
}
@ -228,7 +235,10 @@ mod tests {
fn nonleading_plural_anchor() {
assert_eq!(
read("The flower|s bloomed"),
r#"<p>The <a class="detached" title="" href="/node/flower">flowers</a> bloomed</p>"#
concat!(
r#"<p>The <a class="detached" title="" "#,
r#"href="/node/flower">flowers</a> bloomed</p>"#,
)
);
}
@ -236,7 +246,9 @@ mod tests {
fn leading_plural_anchor() {
assert_eq!(
read("Interfaces are |element|s of |system|s."),
r#"<p>Interfaces are <a class="detached" title="" href="/node/element">elements</a> of <a class="detached" title="" href="/node/system">systems</a>.</p>"#
concat!(r#"<p>Interfaces are <a class="detached" title="" "#,
r#"href="/node/element">elements</a> of <a class="detached" "#,
r#"title="" href="/node/system">systems</a>.</p>"#)
);
}
@ -244,7 +256,11 @@ mod tests {
fn leading_multiword_anchor() {
assert_eq!(
read("interactions are |basic elements| of systems"),
r#"<p>interactions are <a class="detached" title="" href="/node/basic elements">basic elements</a> of systems</p>"#
concat!(
r#"<p>interactions are <a class="detached" title="""#,
r#" href="/node/basic elements">basic elements</a> "#,
r#"of systems</p>"#,
),
);
}
@ -252,7 +268,9 @@ mod tests {
fn explicit_end_of_destination() {
assert_eq!(
read("interactions are |basic elements|BasicElements| of systems"),
r#"<p>interactions are <a class="detached" title="" href="/node/BasicElements">basic elements</a> of systems</p>"#
concat!(r#"<p>interactions are <a class="detached" title="" "#,
r#"href="/node/BasicElements">basic elements</a> of "#,
r#"systems</p>"#)
);
}
@ -260,7 +278,11 @@ mod tests {
fn explicit_end_of_external_destination() {
assert_eq!(
read("this |anchor example|https://example.com| is external"),
r#"<p>this <a class="external" title="" href="https://example.com">anchor example</a> is external</p>"#
concat!(
r#"<p>this <a class="external" title="" "#,
r#"href="https://example.com">anchor example</a> is "#,
r#"external</p>"#
)
);
}
@ -276,7 +298,10 @@ mod tests {
fn external_anchor_destination_at_eoi() {
assert_eq!(
read("a b|https://example.com"),
r#"<p>a <a class="external" title="" href="https://example.com">b</a></p>"#
concat!(
r#"<p>a <a class="external" title="" "#,
r#"href="https://example.com">b</a></p>"#,
)
);
}
@ -284,7 +309,10 @@ mod tests {
fn nonleading_plural_anchor_at_eoi() {
assert_eq!(
read("element|s"),
r#"<p><a class="detached" title="" href="/node/element">elements</a></p>"#
concat!(
r#"<p><a class="detached" title="" "#,
r#"href="/node/element">elements</a></p>"#,
)
);
}
@ -292,17 +320,22 @@ mod tests {
fn leading_plural_anchor_at_eoi() {
assert_eq!(
read("|element|s"),
r#"<p><a class="detached" title="" href="/node/element">elements</a></p>"#
concat!(
r#"<p><a class="detached" title="" "#,
r#"href="/node/element">elements</a></p>"#,
)
);
}
#[test]
fn http_external_anchor() {
assert_eq!(
read(
"a |false dichotomy|https://en.wikipedia.org/wiki/False_dilemma|."
read("a |false dichotomy|https://wikipedia.org/False_dilemma|."),
concat!(
r#"<p>a <a class="external" title="" "#,
r#"href="https://wikipedia.org/False_dilemma">"#,
r#"false dichotomy</a>.</p>"#,
),
r#"<p>a <a class="external" title="" href="https://en.wikipedia.org/wiki/False_dilemma">false dichotomy</a>.</p>"#
);
}
@ -315,7 +348,8 @@ mod tests {
"at rustup.rs",
)),
concat!(
r#"<p><a class="external" title="" href="https://rustup.rs/">Rust toolchain</a>"#,
r#"<p><a class="external" title="" "#,
r#"href="https://rustup.rs/">Rust toolchain</a>"#,
"\n",
"at rustup.rs</p>",
)
@ -326,7 +360,11 @@ mod tests {
fn http_external_anchor_leading_no_third_then_space() {
assert_eq!(
read("|Rust toolchain|https://rustup.rs/ at rustup.rs"),
r#"<p><a class="external" title="" href="https://rustup.rs/">Rust toolchain</a> at rustup.rs</p>"#
concat!(
r#"<p><a class="external" title="" "#,
r#"href="https://rustup.rs/">Rust toolchain</a> "#,
r#"at rustup.rs</p>"#,
),
);
}
@ -334,7 +372,10 @@ mod tests {
fn http_external_anchor_leading_no_third_then_eoi() {
assert_eq!(
read("|Rust toolchain|https://rustup.rs/"),
r#"<p><a class="external" title="" href="https://rustup.rs/">Rust toolchain</a></p>"#
concat!(
r#"<p><a class="external" title="" "#,
r#"href="https://rustup.rs/">Rust toolchain</a></p>"#,
)
);
}
@ -344,7 +385,10 @@ mod tests {
read("\n|SomeAnchor|\n"),
concat!(
"\n",
r#"<p><a class="detached" title="" href="/node/SomeAnchor">SomeAnchor</a></p>"#
concat!(
r#"<p><a class="detached" title="" "#,
r#"href="/node/SomeAnchor">SomeAnchor</a></p>"#,
)
),
);
}
@ -354,9 +398,11 @@ mod tests {
assert_eq!(
read("|SomeAnchor|\n|SomeOtherAnchor|\n"),
concat!(
r#"<p><a class="detached" title="" href="/node/SomeAnchor">SomeAnchor</a>"#,
r#"<p><a class="detached" title="" "#,
r#"href="/node/SomeAnchor">SomeAnchor</a>"#,
"\n",
r#"<a class="detached" title="" href="/node/SomeOtherAnchor">SomeOtherAnchor</a></p>"#
r#"<a class="detached" title="" "#,
r#"href="/node/SomeOtherAnchor">SomeOtherAnchor</a></p>"#,
)
);
}
@ -366,10 +412,12 @@ mod tests {
assert_eq!(
read("|SomeAnchor|\n\n|SomeOtherAnchor|\n"),
concat!(
r#"<p><a class="detached" title="" href="/node/SomeAnchor">SomeAnchor</a></p>"#,
r#"<p><a class="detached" title="" "#,
r#"href="/node/SomeAnchor">SomeAnchor</a></p>"#,
"\n",
"\n",
r#"<p><a class="detached" title="" href="/node/SomeOtherAnchor">SomeOtherAnchor</a></p>"#
r#"<p><a class="detached" title="" "#,
r#"href="/node/SomeOtherAnchor">SomeOtherAnchor</a></p>"#,
),
);
}
@ -378,7 +426,10 @@ mod tests {
fn trailing_anchor() {
assert_eq!(
read("see acks|acks"),
r#"<p>see <a class="detached" title="" href="/node/acks">acks</a></p>"#
concat!(
r#"<p>see <a class="detached" title="" "#,
r#"href="/node/acks">acks</a></p>"#,
)
);
}
@ -388,8 +439,9 @@ mod tests {
read("\nsee acks|acks\n"),
concat!(
"\n",
r#"<p>see <a class="detached" title="" href="/node/acks">acks</a></p>"#
)
r#"<p>see <a class="detached" title="" "#,
r#"href="/node/acks">acks</a></p>"#,
),
);
}
@ -417,7 +469,10 @@ mod tests {
fn anchor_with_trailing_single_quote() {
assert_eq!(
read("the |lion|'s mouth"),
r#"<p>the <a class="detached" title="" href="/node/lion">lion</a>'s mouth</p>"#,
concat!(
r#"<p>the <a class="detached" title="" "#,
r#"href="/node/lion">lion</a>'s mouth</p>"#,
)
);
}
@ -425,7 +480,10 @@ mod tests {
fn anchor_with_trailing_double_quote() {
assert_eq!(
read(r#"the "|real|" motive"#),
r#"<p>the "<a class="detached" title="" href="/node/real">real</a>" motive</p>"#,
concat!(
r#"<p>the "<a class="detached" title="" "#,
r#"href="/node/real">real</a>" motive</p>"#,
)
);
}
@ -433,7 +491,10 @@ mod tests {
fn anchor_with_trailing_parenthesis() {
assert_eq!(
read("this (though |true|) was questioned"),
r#"<p>this (though <a class="detached" title="" href="/node/true">true</a>) was questioned</p>"#,
concat!(
r#"<p>this (though <a class="detached" title="" "#,
r#"href="/node/true">true</a>) was questioned</p>"#,
)
);
}
@ -441,7 +502,10 @@ mod tests {
fn anchor_with_leading_single_quote() {
assert_eq!(
read("the 'real|Reality' motive"),
r#"<p>the '<a class="detached" title="" href="/node/Reality">real</a>' motive</p>"#,
concat!(
r#"<p>the '<a class="detached" title="" "#,
r#"href="/node/Reality">real</a>' motive</p>"#,
)
);
}
@ -449,7 +513,10 @@ mod tests {
fn anchor_with_leading_double_quote() {
assert_eq!(
read(r#"the "real|Reality" motive"#),
r#"<p>the "<a class="detached" title="" href="/node/Reality">real</a>" motive</p>"#,
concat!(
r#"<p>the "<a class="detached" title="" "#,
r#"href="/node/Reality">real</a>" motive</p>"#,
)
);
}
@ -457,7 +524,10 @@ mod tests {
fn anchor_with_leading_parenthesis() {
assert_eq!(
read("her (last|Surname) name"),
r#"<p>her (<a class="detached" title="" href="/node/Surname">last</a>) name</p>"#,
concat!(
r#"<p>her (<a class="detached" title="" "#,
r#"href="/node/Surname">last</a>) name</p>"#,
)
);
}
@ -465,7 +535,10 @@ mod tests {
fn anchor_with_internal_apostrophe() {
assert_eq!(
read("the |lion's mouth|album was released"),
r#"<p>the <a class="detached" title="" href="/node/album">lion's mouth</a> was released</p>"#
concat!(
r#"<p>the <a class="detached" title="" "#,
r#"href="/node/album">lion's mouth</a> was released</p>"#,
)
);
}
@ -473,7 +546,10 @@ mod tests {
fn nonleading_anchor_with_internal_apostrophe() {
assert_eq!(
read("they decided to stay at Jane's|YellowHouse that night"),
r#"<p>they decided to stay at <a class="detached" title="" href="/node/YellowHouse">Jane's</a> that night</p>"#
concat!(
r#"<p>they decided to stay at <a class="detached" title="" "#,
r#"href="/node/YellowHouse">Jane's</a> that night</p>"#,
)
);
}
@ -481,7 +557,10 @@ mod tests {
fn nonleading_anchor_with_internal_apostrophe_at_eoi() {
assert_eq!(
read("they decided to stay at Jane's|YellowHouse"),
r#"<p>they decided to stay at <a class="detached" title="" href="/node/YellowHouse">Jane's</a></p>"#
concat!(
r#"<p>they decided to stay at <a class="detached" "#,
r#"title="" href="/node/YellowHouse">Jane's</a></p>"#,
)
);
}
@ -489,7 +568,10 @@ mod tests {
fn nonleading_anchor_with_internal_apostrophe_at_soi() {
assert_eq!(
read("Jane's|YellowHouse that night"),
r#"<p><a class="detached" title="" href="/node/YellowHouse">Jane's</a> that night</p>"#
concat!(
r#"<p><a class="detached" title="" "#,
r#"href="/node/YellowHouse">Jane's</a> that night</p>"#,
)
);
}
@ -497,7 +579,10 @@ mod tests {
fn anchor_with_internal_double_quotes() {
assert_eq!(
read(r#"the |"real"|Truth motive"#),
r#"<p>the <a class="detached" title="" href="/node/Truth">"real"</a> motive</p>"#,
concat!(
r#"<p>the <a class="detached" title="" "#,
r#"href="/node/Truth">"real"</a> motive</p>"#,
)
);
}
@ -505,7 +590,10 @@ mod tests {
fn anchor_with_internal_double_quotes_wrapping_spaced_words() {
assert_eq!(
read(r#"the |"bare reality"|Ideology they believed"#),
r#"<p>the <a class="detached" title="" href="/node/Ideology">"bare reality"</a> they believed</p>"#,
concat!(
r#"<p>the <a class="detached" title="" "#,
r#"href="/node/Ideology">"bare reality"</a> they believed</p>"#,
)
);
}
@ -513,7 +601,10 @@ mod tests {
fn anchor_with_internal_parenthesis() {
assert_eq!(
read("her |last (name)|Surname was Amad"),
r#"<p>her <a class="detached" title="" href="/node/Surname">last (name)</a> was Amad</p>"#,
concat!(
r#"<p>her <a class="detached" title="" "#,
r#"href="/node/Surname">last (name)</a> was Amad</p>"#,
)
);
}
@ -521,7 +612,11 @@ mod tests {
fn anchor_with_internal_parenthesis_wrapping_spaced_words() {
assert_eq!(
read("this |truth (though questionable) was fine|Absurd to them "),
r#"<p>this <a class="detached" title="" href="/node/Absurd">truth (though questionable) was fine</a> to them</p>"#
concat!(
r#"<p>this <a class="detached" title="" "#,
r#"href="/node/Absurd">truth (though questionable) was "#,
r#"fine</a> to them</p>"#,
)
);
}
}

View file

@ -8,7 +8,7 @@ use crate::{
parser::{
Block, Lexeme, State, Token,
token::{
Header, List, LineBreak, Literal, Paragraph, PreFormat, Quote,
Header, LineBreak, List, Literal, Paragraph, PreFormat, Quote,
Table, Verse,
},
},
@ -124,16 +124,14 @@ pub fn parse(
mod tests {
use crate::{
syntax::content::parser::{
self, Block, Token, context, State,
token::{Header, header::Level, PreFormat},
},
graph::Graph,
syntax::content::parser::{
self, Block, State, Token, context,
token::{Header, PreFormat, header::Level},
},
};
fn read(input: &str) -> String {
parser::read(input, &Graph::default())
}
fn read(input: &str) -> String { parser::read(input, &Graph::default()) }
#[test]
fn pre() {

View file

@ -1,17 +1,16 @@
use std::{iter::Peekable, slice::Iter};
use crate::{
graph::Graph,
prelude::*,
syntax::content::{
Parseable as _,
parser::{
Lexeme, State,
Inline, Lexeme, State, Token, context,
state::AnchorBuffer,
Inline, context, Token,
token::{Anchor, Code, Literal},
},
},
graph::Graph,
};
pub fn parse(

View file

@ -1,11 +1,11 @@
use std::{iter::Peekable, slice::Iter};
use crate::{
graph::Graph,
prelude::*,
syntax::content::parser::{
context::Block, Token, Lexeme, State, state, token::Item, format,
Lexeme, State, Token, context::Block, format, state, token::Item,
},
graph::Graph,
};
/// Handles open list contexts until a list is fully parsed.
@ -88,13 +88,11 @@ pub fn parse(
#[cfg(test)]
mod tests {
use crate::{
syntax::content::parser::{self, context::list::parse, Lexeme, State},
graph::Graph,
syntax::content::parser::{self, Lexeme, State, context::list::parse},
};
fn read(input: &str) -> String {
parser::read(input, &Graph::default())
}
fn read(input: &str) -> String { parser::read(input, &Graph::default()) }
#[test]
fn unordered_list() {

View file

@ -117,11 +117,9 @@ pub fn parse(
#[cfg(test)]
mod tests {
use crate::{syntax::content::parser, graph::Graph};
use crate::{graph::Graph, syntax::content::parser};
fn read(input: &str) -> String {
parser::read(input, &Graph::default())
}
fn read(input: &str) -> String { parser::read(input, &Graph::default()) }
fn read_loaded(input: &str) -> String {
parser::read(input, &Graph::load())
@ -250,11 +248,13 @@ mod tests {
"<table>", "\n",
" <tr>", "\n",
" <td>a</td>", "\n",
r#" <td><a class="detached" title="" href="/node/Node">Node</a></td>"#, "\n",
r#" <td><a class="detached" title="" "#,
r#"href="/node/Node">Node</a></td>"#, "\n",
" <td>c</td>", "\n",
" </tr>", "\n",
"</table>", "\n",
));
)
);
}
#[test]
@ -270,11 +270,14 @@ mod tests {
"<table>", "\n",
" <tr>", "\n",
" <td>a</td>", "\n",
r#" <td><a class="attached" title="A node is defined in your graph file starting with a table header of the form:" href="/node/Node">Node</a></td>"#, "\n",
r#" <td><a class="attached" title="A node is defined "#,
r#"in your graph file starting with a table header of the "#,
r#"form:" href="/node/Node">Node</a></td>"#, "\n",
" <td>c</td>", "\n",
" </tr>", "\n",
"</table>", "\n",
));
)
);
}
#[test]

View file

@ -1,6 +1,6 @@
use std::fmt;
use crate::{syntax::content::parser::segment::delimiter::Delimiters};
use crate::syntax::content::parser::segment::delimiter::Delimiters;
#[derive(Clone, Debug, Default)]
pub struct Lexeme {
@ -22,25 +22,15 @@ impl Lexeme {
}
}
pub fn text(&self) -> String {
self.text.clone()
}
pub fn text(&self) -> String { self.text.clone() }
pub fn next(&self) -> String {
self.next.clone()
}
pub fn next(&self) -> String { self.next.clone() }
pub fn last(&self) -> bool {
self.last
}
pub fn last(&self) -> bool { self.last }
pub fn first(&self) -> bool {
self.first
}
pub fn first(&self) -> bool { self.first }
pub fn mutate_text(&mut self, new: &str) {
self.text = new.to_string();
}
pub fn mutate_text(&mut self, new: &str) { self.text = new.to_string(); }
pub fn as_char(&self) -> Option<char> {
if self.text.chars().count() == 1 {
@ -141,9 +131,7 @@ impl Lexeme {
.is_some_and(|c| delimiters.is_delimiter(c))
}
pub fn next_first_char(&self) -> Option<char> {
self.next.chars().nth(0)
}
pub fn next_first_char(&self) -> Option<char> { self.next.chars().nth(0) }
pub fn match_first_char(&self, query: char) -> bool {
self.text.chars().nth(0).is_some_and(|c| c == query)

View file

@ -1,13 +1,14 @@
use crate::{
prelude::*,
graph::Graph,
prelude::*,
syntax::content::{
TokenOutput, Parseable as _, LexMap,
LexMap, Parseable as _, TokenOutput,
parser::{
context,
lexeme::Lexeme,
token::{Token, LineBreak, Literal},
point, segment,
state::State,
segment, context, point,
token::{LineBreak, Literal, Token},
},
},
};

View file

@ -58,17 +58,18 @@ pub fn parse(
#[cfg(test)]
mod tests {
use crate::{syntax::content::parser, graph::Graph};
use crate::{graph::Graph, syntax::content::parser};
fn read(input: &str) -> String {
parser::read(input, &Graph::default())
}
fn read(input: &str) -> String { parser::read(input, &Graph::default()) }
#[test]
fn oblique_anchor() {
assert_eq!(
read("w _|S|_ w"),
r#"<p>w <em><a class="detached" title="" href="/node/S">S</a></em> w</p>"#
concat!(
r#"<p>w <em><a class="detached" title="" "#,
r#"href="/node/S">S</a></em> w</p>"#,
)
);
}
@ -76,7 +77,8 @@ mod tests {
fn oblique_anchor_with_trailing_comma() {
assert_eq!(
read("w _|S|_, w"),
r#"<p>w <em><a class="detached" title="" href="/node/S">S</a></em>, w</p>"#
concat!(r#"<p>w <em><a class="detached" title="" "#,
r#"href="/node/S">S</a></em>, w</p>"#)
);
}
@ -84,9 +86,17 @@ mod tests {
fn oblique() {
assert_eq!(
read(
"_|this anchor is oblique|o as are these literals_ but not these _just these_, not this _and these with an |anc80r| again_"
"_|this anchor is oblique|o as are these literals_ but not \
these _just these_, not this _and these with an |anc80r| \
again_"
),
r#"<p><em><a class="detached" title="" href="/node/o">this anchor is oblique</a> as are these literals</em> but not these <em>just these</em>, not this <em>and these with an <a class="detached" title="" href="/node/anc80r">anc80r</a> again</em></p>"#
concat!(
r#"<p><em><a class="detached" title="" href="/node/o">"#,
r#"this anchor is oblique</a> as are these literals</em> "#,
r#"but not these <em>just these</em>, not this <em>and these "#,
r#"with an <a class="detached" title="" "#,
r#"href="/node/anc80r">anc80r</a> again</em></p>"#,
)
);
}

View file

@ -1,6 +1,4 @@
pub fn segment(text: &str) -> Vec<String> {
delimiter::atomize(text)
}
pub fn segment(text: &str) -> Vec<String> { delimiter::atomize(text) }
pub mod delimiter {
@ -146,7 +144,8 @@ pub mod delimiter {
fn atomize_flankign_sentence() {
assert_eq!(
atomize(
"about_colors: the colors _amber_, _orange_ and _yellow mustard_ to `jane_bishop@mail.com`."
"about_colors: the colors _amber_, _orange_ and \
_yellow mustard_ to `jane_bishop@mail.com`."
),
vec![
"about_colors",
@ -188,7 +187,8 @@ pub mod delimiter {
#[test]
fn atomize_words() {
let actual = atomize(
" justification for the actions of those who hold authority inevitably dwindles ",
" justification for the actions of those who hold \
authority inevitably dwindles ",
);
let expected = vec![
" ",
@ -285,7 +285,8 @@ pub mod delimiter {
#[test]
fn atomize_pipes_and_ticks() {
let actual = atomize(
"every other |time| as `it could or |perhaps somehow|then or now| it was` perceived",
"every other |time| as `it could or |perhaps somehow|then or \
now| it was` perceived",
);
let expected = vec![
"every",

View file

@ -101,24 +101,24 @@ mod tests {
#[test]
fn anchor_buffer_display_with_text_set() {
let mut buffer = AnchorBuffer::default();
buffer.text = String::from("mX8Z7yWmsK");
buffer.text = String::from("mX8Z7sK");
println!("{buffer:#?}");
println!("{buffer}");
assert_eq!(
format!("{buffer}"),
r#"AnchorBuffer [text: "mX8Z7yWmsK"] >> Anchor <empty> -> <unknown>"#
r#"AnchorBuffer [text: "mX8Z7sK"] >> Anchor <empty> -> <unknown>"#
);
}
#[test]
fn anchor_buffer_display_with_destination_set() {
let mut buffer = AnchorBuffer::default();
buffer.destination = String::from("VP2aqGngAq");
buffer.destination = String::from("VP2gAq");
println!("{buffer:#?}");
println!("{buffer}");
assert_eq!(
format!("{buffer}"),
r#"AnchorBuffer [, dest: "VP2aqGngAq"] >> Anchor <empty> -> <unknown>"#
r#"AnchorBuffer [, dest: "VP2gAq"] >> Anchor <empty> -> <unknown>"#
);
}
@ -131,7 +131,10 @@ mod tests {
println!("{buffer}");
assert_eq!(
format!("{buffer}"),
r#"AnchorBuffer [text: "ECJrzgkBHg", dest: "9dy6gQ2g3E"] >> Anchor <empty> -> <unknown>"#
concat!(
r#"AnchorBuffer [text: "ECJrzgkBHg", dest: "9dy6gQ2g3E"] "#,
r#">> Anchor <empty> -> <unknown>"#,
)
);
}
}

View file

@ -1,4 +1,4 @@
use crate::syntax::content::{Parseable as _};
use crate::syntax::content::Parseable as _;
pub mod anchor;
pub mod bold;
@ -18,12 +18,23 @@ pub mod table;
pub mod underline;
pub mod verse;
pub use {
anchor::Anchor, bold::Bold, checkbox::CheckBox, code::Code, header::Header,
item::Item, linebreak::LineBreak, list::List, literal::Literal,
oblique::Oblique, paragraph::Paragraph, preformat::PreFormat, quote::Quote,
strike::Strike, table::Table, underline::Underline, verse::Verse,
};
pub use anchor::Anchor;
pub use bold::Bold;
pub use checkbox::CheckBox;
pub use code::Code;
pub use header::Header;
pub use item::Item;
pub use linebreak::LineBreak;
pub use list::List;
pub use literal::Literal;
pub use oblique::Oblique;
pub use paragraph::Paragraph;
pub use preformat::PreFormat;
pub use quote::Quote;
pub use strike::Strike;
pub use table::Table;
pub use underline::Underline;
pub use verse::Verse;
#[derive(Debug, Eq, PartialEq, Clone)]
pub enum Token {

View file

@ -1,6 +1,6 @@
use crate::{
syntax::content::{Parseable, parser::Lexeme},
graph::Node,
syntax::content::{Parseable, parser::Lexeme},
};
#[derive(Default, Debug, Clone, Eq, PartialEq)]
@ -15,58 +15,36 @@ pub struct Anchor {
}
impl Anchor {
pub fn text(&self) -> String {
self.text.clone()
}
pub fn text(&self) -> String { self.text.clone() }
pub fn set_text(&mut self, text: &str) {
self.text = String::from(text);
}
pub fn set_text(&mut self, text: &str) { self.text = String::from(text); }
pub fn text_push(&mut self, text: &str) {
self.text.push_str(text);
}
pub fn text_push(&mut self, text: &str) { self.text.push_str(text); }
pub fn destination(&self) -> Option<String> {
self.destination.clone()
}
pub fn destination(&self) -> Option<String> { self.destination.clone() }
pub fn set_destination(&mut self, destination: Option<&str>) {
self.destination = destination.map(str::to_string);
self.route();
}
pub fn balanced(&self) -> bool {
self.balanced
}
pub fn balanced(&self) -> bool { self.balanced }
pub fn set_balanced(&mut self, balanced: bool) {
self.balanced = balanced;
}
pub fn set_balanced(&mut self, balanced: bool) { self.balanced = balanced; }
pub fn external(&self) -> bool {
self.external
}
pub fn external(&self) -> bool { self.external }
pub fn set_external(&mut self, external: bool) {
self.external = external;
}
pub fn set_external(&mut self, external: bool) { self.external = external; }
pub fn set_leading(&mut self, leading: bool) {
self.leading = leading;
}
pub fn set_leading(&mut self, leading: bool) { self.leading = leading; }
pub fn node(&self) -> Option<Node> {
self.node.clone()
}
pub fn node(&self) -> Option<Node> { self.node.clone() }
pub fn set_node(&mut self, node: &Node) {
self.node = Some(node.to_owned());
}
pub fn node_id(&self) -> Option<String> {
self.node_id.clone()
}
pub fn node_id(&self) -> Option<String> { self.node_id.clone() }
pub fn set_node_id(&mut self, id: &str) {
self.node_id = Some(id.to_owned());
@ -105,7 +83,8 @@ impl Parseable for Anchor {
fn render(&self) -> String {
let Some(destination) = &self.destination else {
panic!(
"Attempt to render anchor {self:#?} without knowing its destination."
"Attempt to render anchor {self:#?} without knowing \
its destination."
)
};
@ -131,9 +110,7 @@ impl Parseable for Anchor {
)
}
fn flatten(&self) -> String {
self.text.clone()
}
fn flatten(&self) -> String { self.text.clone() }
}
impl std::fmt::Display for Anchor {
@ -177,9 +154,8 @@ impl std::fmt::Display for Anchor {
#[cfg(test)]
mod tests {
use crate::syntax::content::parser::Token;
use super::*;
use crate::syntax::content::parser::Token;
#[test]
fn render_anchor() {
@ -188,7 +164,10 @@ mod tests {
anchor.set_destination(Some("AnchorDest"));
assert_eq!(
anchor.render(),
r#"<a class="detached" title="" href="/node/AnchorDest">AnchorText</a>"#
concat!(
r#"<a class="detached" title="" "#,
r#"href="/node/AnchorDest">AnchorText</a>"#,
)
);
}
@ -196,9 +175,7 @@ mod tests {
#[should_panic(
expected = "Attempt to lex an anchor directly from a lexeme"
)]
fn lex() {
Anchor::lex(&Lexeme::default());
}
fn lex() { Anchor::lex(&Lexeme::default()); }
#[test]
#[should_panic(expected = "without knowing its destination")]

View file

@ -1,6 +1,4 @@
use crate::{
syntax::content::{Parseable, Lexeme},
};
use crate::syntax::content::{Lexeme, Parseable};
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct Bold {
@ -8,15 +6,11 @@ pub struct Bold {
}
impl Bold {
pub fn new(open: bool) -> Bold {
Bold { open }
}
pub fn new(open: bool) -> Bold { Bold { open } }
}
impl Parseable for Bold {
fn probe(lexeme: &Lexeme) -> bool {
lexeme.text() == "*"
}
fn probe(lexeme: &Lexeme) -> bool { lexeme.text() == "*" }
fn lex(_lexeme: &Lexeme) -> Bold {
panic!("Attempt to lex a bold tag directly from a lexeme")
@ -30,9 +24,7 @@ impl Parseable for Bold {
}
}
fn flatten(&self) -> String {
String::default()
}
fn flatten(&self) -> String { String::default() }
}
impl std::fmt::Display for Bold {
@ -44,9 +36,8 @@ impl std::fmt::Display for Bold {
#[cfg(test)]
mod tests {
use crate::syntax::content::parser::Token;
use super::*;
use crate::syntax::content::parser::Token;
#[test]
fn render() {
@ -61,9 +52,7 @@ mod tests {
#[should_panic(
expected = "Attempt to lex a bold tag directly from a lexeme"
)]
fn lex() {
Bold::lex(&Lexeme::default());
}
fn lex() { Bold::lex(&Lexeme::default()); }
#[test]
fn token_display() {

View file

@ -1,6 +1,4 @@
use crate::{
syntax::content::{Parseable, Lexeme},
};
use crate::syntax::content::{Lexeme, Parseable};
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct CheckBox {
@ -8,9 +6,7 @@ pub struct CheckBox {
}
impl CheckBox {
pub fn new(checked: bool) -> CheckBox {
CheckBox { checked }
}
pub fn new(checked: bool) -> CheckBox { CheckBox { checked } }
}
impl Parseable for CheckBox {
@ -34,9 +30,7 @@ impl Parseable for CheckBox {
format!(r#"<input type="checkbox"{toggle}/>"#)
}
fn flatten(&self) -> String {
String::default()
}
fn flatten(&self) -> String { String::default() }
}
impl std::fmt::Display for CheckBox {
@ -48,9 +42,8 @@ impl std::fmt::Display for CheckBox {
#[cfg(test)]
mod tests {
use crate::syntax::content::parser::Token;
use super::*;
use crate::syntax::content::parser::Token;
#[test]
fn render() {

View file

@ -1,6 +1,4 @@
use crate::{
syntax::content::{Parseable, Lexeme},
};
use crate::syntax::content::{Lexeme, Parseable};
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct Code {
@ -8,15 +6,11 @@ pub struct Code {
}
impl Code {
pub fn new(open: bool) -> Code {
Code { open }
}
pub fn new(open: bool) -> Code { Code { open } }
}
impl Parseable for Code {
fn probe(lexeme: &Lexeme) -> bool {
lexeme.text() == "`"
}
fn probe(lexeme: &Lexeme) -> bool { lexeme.text() == "`" }
fn lex(_lexeme: &Lexeme) -> Code {
panic!("Attempt to lex a code tag directly from a lexeme")
@ -30,9 +24,7 @@ impl Parseable for Code {
}
}
fn flatten(&self) -> String {
String::default()
}
fn flatten(&self) -> String { String::default() }
}
impl std::fmt::Display for Code {
@ -44,9 +36,8 @@ impl std::fmt::Display for Code {
#[cfg(test)]
mod tests {
use crate::syntax::content::parser::Token;
use super::*;
use crate::syntax::content::parser::Token;
#[test]
fn render() {
@ -61,9 +52,7 @@ mod tests {
#[should_panic(
expected = "Attempt to lex a code tag directly from a lexeme"
)]
fn lex() {
Code::lex(&Lexeme::default());
}
fn lex() { Code::lex(&Lexeme::default()); }
#[test]
fn token_display() {

View file

@ -1,15 +1,14 @@
use std::{
collections::{HashMap, hash_map::Entry},
fmt::Display,
};
use crate::{
prelude::*,
graph::Config,
syntax::content::{Parseable, Lexeme},
prelude::*,
syntax::content::{Lexeme, Parseable},
};
use std::fmt::Display;
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct Header {
open: Option<bool>,
@ -113,9 +112,7 @@ impl Parseable for Header {
}
}
fn flatten(&self) -> String {
String::default()
}
fn flatten(&self) -> String { String::default() }
}
impl std::fmt::Display for Header {
@ -195,9 +192,8 @@ impl Display for Level {
#[cfg(test)]
mod tests {
use crate::syntax::content::parser::Token;
use super::*;
use crate::syntax::content::parser::Token;
#[test]
fn make_id() {

View file

@ -1,4 +1,4 @@
use crate::syntax::content::{Parseable, Lexeme};
use crate::syntax::content::{Lexeme, Parseable};
#[derive(Default, Debug, Clone, Eq, PartialEq)]
pub struct Item {
@ -7,9 +7,7 @@ pub struct Item {
}
impl Parseable for Item {
fn probe(_: &Lexeme) -> bool {
false
}
fn probe(_: &Lexeme) -> bool { false }
fn lex(_: &Lexeme) -> Item {
panic!("Attempt to lex an item directly from a lexeme")
@ -19,9 +17,7 @@ impl Parseable for Item {
panic!("Items should only be rendered by a list's render method")
}
fn flatten(&self) -> String {
String::default()
}
fn flatten(&self) -> String { String::default() }
}
impl Item {
@ -50,9 +46,8 @@ impl std::fmt::Display for Item {
#[cfg(test)]
mod tests {
use crate::syntax::content::parser::Token;
use super::*;
use crate::syntax::content::parser::Token;
#[test]
#[should_panic(

View file

@ -1,6 +1,4 @@
use crate::{
syntax::content::{Parseable, parser::Lexeme},
};
use crate::syntax::content::{Parseable, parser::Lexeme};
#[derive(Default, Debug, Clone, Eq, PartialEq)]
pub struct LineBreak {}
@ -10,17 +8,11 @@ impl Parseable for LineBreak {
lexeme.match_char('<') && lexeme.match_next_char('\n')
}
fn lex(_lexeme: &Lexeme) -> LineBreak {
LineBreak {}
}
fn lex(_lexeme: &Lexeme) -> LineBreak { LineBreak {} }
fn render(&self) -> String {
String::from("<br>")
}
fn render(&self) -> String { String::from("<br>") }
fn flatten(&self) -> String {
String::from('\n')
}
fn flatten(&self) -> String { String::from('\n') }
}
impl std::fmt::Display for LineBreak {
@ -31,9 +23,8 @@ impl std::fmt::Display for LineBreak {
#[cfg(test)]
mod tests {
use crate::syntax::content::parser::Token;
use super::*;
use crate::syntax::content::parser::Token;
#[test]
fn token_display() {

View file

@ -27,8 +27,8 @@ impl Parseable for List {
/// - Strict division is performed but related panics are unreachable given
/// the guarantees described in `List::scale_indent`
/// - Saturates subtractions from indent levels at zero. This is not
/// unreachable, but a difference of zero is a no-op considering it
/// would cause an iteration of zero times (over an empty range).
/// unreachable, but a difference of zero is a no-op considering it would
/// cause an iteration of zero times (over an empty range).
fn render(&self) -> String {
let tag = if self.ordered { "ol" } else { "ul" };
let mut output = String::new();
@ -122,9 +122,8 @@ impl std::fmt::Display for List {
#[cfg(test)]
mod tests {
use crate::syntax::content::parser::Token;
use super::*;
use crate::syntax::content::parser::Token;
#[test]
fn render_flat_list() {

View file

@ -16,13 +16,9 @@ impl Parseable for Literal {
}
}
fn render(&self) -> String {
self.text.clone()
}
fn render(&self) -> String { self.text.clone() }
fn flatten(&self) -> String {
self.text.clone()
}
fn flatten(&self) -> String { self.text.clone() }
}
impl std::fmt::Display for Literal {
@ -33,9 +29,8 @@ impl std::fmt::Display for Literal {
#[cfg(test)]
mod tests {
use crate::syntax::content::parser::Token;
use super::*;
use crate::syntax::content::parser::Token;
#[test]
fn token_display() {

View file

@ -1,6 +1,4 @@
use crate::{
syntax::content::{Parseable, Lexeme},
};
use crate::syntax::content::{Lexeme, Parseable};
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct Oblique {
@ -8,15 +6,11 @@ pub struct Oblique {
}
impl Oblique {
pub fn new(open: bool) -> Oblique {
Oblique { open }
}
pub fn new(open: bool) -> Oblique { Oblique { open } }
}
impl Parseable for Oblique {
fn probe(lexeme: &Lexeme) -> bool {
lexeme.text() == "_"
}
fn probe(lexeme: &Lexeme) -> bool { lexeme.text() == "_" }
fn lex(_lexeme: &Lexeme) -> Oblique {
panic!("Attempt to lex an oblique tag directly from a lexeme")
@ -30,9 +24,7 @@ impl Parseable for Oblique {
}
}
fn flatten(&self) -> String {
String::default()
}
fn flatten(&self) -> String { String::default() }
}
impl std::fmt::Display for Oblique {
@ -44,9 +36,8 @@ impl std::fmt::Display for Oblique {
#[cfg(test)]
mod tests {
use crate::syntax::content::parser::Token;
use super::*;
use crate::syntax::content::parser::Token;
#[test]
fn render() {
@ -61,9 +52,7 @@ mod tests {
#[should_panic(
expected = "Attempt to lex an oblique tag directly from a lexeme"
)]
fn lex() {
Oblique::lex(&Lexeme::default());
}
fn lex() { Oblique::lex(&Lexeme::default()); }
#[test]
fn token_display() {

View file

@ -6,9 +6,7 @@ pub struct Paragraph {
}
impl Paragraph {
pub fn new(open: bool) -> Paragraph {
Paragraph { open: Some(open) }
}
pub fn new(open: bool) -> Paragraph { Paragraph { open: Some(open) } }
pub fn probe_end(lexeme: &Lexeme) -> bool {
lexeme.match_char('\n') && lexeme.match_next_char('\n')
@ -21,9 +19,7 @@ impl Parseable for Paragraph {
!lexeme.is_whitespace()
}
fn lex(_lexeme: &Lexeme) -> Paragraph {
Paragraph { open: None }
}
fn lex(_lexeme: &Lexeme) -> Paragraph { Paragraph { open: None } }
fn render(&self) -> String {
if let Some(open) = self.open {
@ -39,9 +35,7 @@ impl Parseable for Paragraph {
}
}
fn flatten(&self) -> String {
String::default()
}
fn flatten(&self) -> String { String::default() }
}
impl std::fmt::Display for Paragraph {
@ -62,9 +56,8 @@ impl std::fmt::Display for Paragraph {
#[cfg(test)]
mod tests {
use crate::syntax::content::parser::Token;
use super::*;
use crate::syntax::content::parser::Token;
#[test]
fn lex() {
@ -73,9 +66,8 @@ mod tests {
}
#[test]
#[should_panic(
expected = "Attempt to render a paragraph tag while open state is unknown"
)]
#[should_panic(expected = "Attempt to render a paragraph tag while \
open state is unknown")]
fn render_state_unknown() {
let p = Paragraph::lex(&Lexeme::default());
drop(p.render());

View file

@ -1,6 +1,4 @@
use crate::{
syntax::content::{Parseable, Lexeme},
};
use crate::syntax::content::{Lexeme, Parseable};
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct PreFormat {
@ -8,9 +6,7 @@ pub struct PreFormat {
}
impl PreFormat {
pub fn new(open: bool) -> PreFormat {
PreFormat { open: Some(open) }
}
pub fn new(open: bool) -> PreFormat { PreFormat { open: Some(open) } }
}
impl std::fmt::Display for PreFormat {
@ -29,9 +25,7 @@ impl Parseable for PreFormat {
lexeme.match_first_char('`') && (lexeme.next() == "\n" || lexeme.last())
}
fn lex(_lexeme: &Lexeme) -> PreFormat {
PreFormat { open: None }
}
fn lex(_lexeme: &Lexeme) -> PreFormat { PreFormat { open: None } }
fn render(&self) -> String {
if let Some(o) = self.open {
@ -47,16 +41,13 @@ impl Parseable for PreFormat {
}
}
fn flatten(&self) -> String {
String::default()
}
fn flatten(&self) -> String { String::default() }
}
#[cfg(test)]
mod tests {
use crate::syntax::content::parser::Token;
use super::*;
use crate::syntax::content::parser::Token;
#[test]
fn lex() {
@ -68,9 +59,8 @@ mod tests {
}
#[test]
#[should_panic(
expected = "Attempt to render a preformat tag while open state is unknown"
)]
#[should_panic(expected = "Attempt to render a preformat tag while \
open state is unknown")]
fn render() {
let from_empty_lexeme = PreFormat::lex(&Lexeme::default());
from_empty_lexeme.render();

View file

@ -26,9 +26,7 @@ impl Parseable for Quote {
lexeme.match_char('>') && lexeme.match_next_char(' ')
}
fn lex(_lexeme: &Lexeme) -> Quote {
Quote::default()
}
fn lex(_lexeme: &Lexeme) -> Quote { Quote::default() }
fn render(&self) -> String {
let opening = if let Some(url) = &self.url {
@ -49,9 +47,7 @@ impl Parseable for Quote {
format!("\n{opening}\n{content}\n</blockquote>\n")
}
fn flatten(&self) -> String {
String::default()
}
fn flatten(&self) -> String { String::default() }
}
impl std::fmt::Display for Quote {

View file

@ -1,6 +1,4 @@
use crate::{
syntax::content::{Parseable, Lexeme},
};
use crate::syntax::content::{Lexeme, Parseable};
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct Strike {
@ -8,9 +6,7 @@ pub struct Strike {
}
impl Strike {
pub fn new(open: bool) -> Strike {
Strike { open }
}
pub fn new(open: bool) -> Strike { Strike { open } }
}
impl Parseable for Strike {
@ -27,9 +23,7 @@ impl Parseable for Strike {
String::from(tag)
}
fn flatten(&self) -> String {
String::default()
}
fn flatten(&self) -> String { String::default() }
}
impl std::fmt::Display for Strike {
@ -41,9 +35,8 @@ impl std::fmt::Display for Strike {
#[cfg(test)]
mod tests {
use crate::syntax::content::parser::Token;
use super::*;
use crate::syntax::content::parser::Token;
#[test]
fn render() {
@ -58,9 +51,7 @@ mod tests {
#[should_panic(
expected = "Attempt to lex a strike tag directly from a lexeme"
)]
fn lex() {
Strike::lex(&Lexeme::default());
}
fn lex() { Strike::lex(&Lexeme::default()); }
#[test]
fn token_display() {

View file

@ -15,9 +15,7 @@ impl Table {
self.headers.push(header.trim().to_string());
}
pub fn add_row(&mut self, row: Vec<String>) {
self.contents.push(row);
}
pub fn add_row(&mut self, row: Vec<String>) { self.contents.push(row); }
pub fn add_cell(&mut self, content: &str) {
if let Some(last) = self.contents.last_mut() {
@ -37,13 +35,9 @@ impl Table {
}
impl Parseable for Table {
fn probe(lexeme: &Lexeme) -> bool {
lexeme.match_char_sequence('%', '\n')
}
fn probe(lexeme: &Lexeme) -> bool { lexeme.match_char_sequence('%', '\n') }
fn lex(_lexeme: &Lexeme) -> Table {
Table::default()
}
fn lex(_lexeme: &Lexeme) -> Table { Table::default() }
fn render(&self) -> String {
let mut xml = String::from("\n<table>\n");
@ -73,9 +67,7 @@ impl Parseable for Table {
xml
}
fn flatten(&self) -> String {
String::default()
}
fn flatten(&self) -> String { String::default() }
}
impl std::fmt::Display for Table {

View file

@ -1,6 +1,4 @@
use crate::{
syntax::content::{Parseable, Lexeme},
};
use crate::syntax::content::{Lexeme, Parseable};
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct Underline {
@ -8,9 +6,7 @@ pub struct Underline {
}
impl Underline {
pub fn new(open: bool) -> Underline {
Underline { open }
}
pub fn new(open: bool) -> Underline { Underline { open } }
}
impl Parseable for Underline {
@ -30,9 +26,7 @@ impl Parseable for Underline {
}
}
fn flatten(&self) -> String {
String::default()
}
fn flatten(&self) -> String { String::default() }
}
impl std::fmt::Display for Underline {
@ -44,9 +38,8 @@ impl std::fmt::Display for Underline {
#[cfg(test)]
mod tests {
use crate::syntax::content::parser::Token;
use super::*;
use crate::syntax::content::parser::Token;
#[test]
fn render() {
@ -61,9 +54,7 @@ mod tests {
#[should_panic(
expected = "Attempt to lex an underline tag directly from a lexeme"
)]
fn lex() {
Underline::lex(&Lexeme::default());
}
fn lex() { Underline::lex(&Lexeme::default()); }
#[test]
fn token_display() {

View file

@ -43,9 +43,7 @@ impl Parseable for Verse {
}
}
fn flatten(&self) -> String {
String::default()
}
fn flatten(&self) -> String { String::default() }
}
impl std::fmt::Display for Verse {