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 unstable_features = true
match_block_trailing_comma = true
max_width = 80 max_width = 80
reorder_imports = false inline_attribute_width = 40
reorder_modules = false
use_field_init_shorthand = true
use_try_shorthand = true
skip_macro_invocations = ["concat"] skip_macro_invocations = ["concat"]
# not stabilized yet imports_granularity = "Crate"
# blank_lines_lower_bound = 1 group_imports = "StdExternalCrate"
# where_single_line = true
# overflow_delimited_expr = true fn_single_line = true
# normalize_doc_attributes = true match_block_trailing_comma = true
# normalize_comments = true use_field_init_shorthand = true
# inline_attribute_width = 40 use_try_shorthand = true
# imports_granularity = "Crate" hex_literal_case = "Lower"
# hex_literal_case = "Lower" where_single_line = true
# group_imports = "StdExternalCrate" condense_wildcard_suffixes = true
# format_strings = true combine_control_expr = false
# force_multiline_blocks = true empty_item_single_line = true
# error_on_unformatted = true reorder_impl_items = true
# error_on_line_overflow = true trailing_semicolon = false
# condense_wildcard_suffixes = true
# doc_comment_code_block_width = 70 wrap_comments = true
# format_code_in_doc_comments = true normalize_comments = true
# wrap_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 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::{ use crate::{
command::Arguments, prelude::*,
content::{ syntax::{
self, command::Arguments,
parser::{flatten, Token, token::Anchor}, 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 edge;
pub mod meta; pub mod meta;
pub mod node;
#[derive(Serialize, Deserialize, Clone, Default, PartialEq, Eq, Debug)] #[derive(Serialize, Deserialize, Clone, Default, PartialEq, Eq, Debug)]
pub struct Graph { pub struct Graph {
@ -399,7 +399,7 @@ impl Graph {
} else { } else {
log!( log!(
VERBOSE, 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)] #[derive(Serialize, Deserialize, Clone, Default, PartialEq, Eq, Debug)]
pub struct Edge { 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)] #[derive(Serialize, Deserialize, Clone, PartialEq, Eq, Debug)]
pub struct Meta { pub struct Meta {
@ -105,15 +105,9 @@ impl Default for Config {
} }
// See: https://github.com/serde-rs/serde/issues/368 // See: https://github.com/serde-rs/serde/issues/368
fn mktrue() -> bool { fn mktrue() -> bool { true }
true fn mkfalse() -> bool { false }
} fn mk8() -> u16 { 8 }
fn mkfalse() -> bool {
false
}
fn mk8() -> u16 {
8
}
#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, Debug)] #[derive(Serialize, Deserialize, Clone, PartialEq, Eq, Debug)]
pub struct Version { pub struct Version {
@ -314,9 +308,8 @@ impl std::fmt::Display for VersionErrorCause {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use crate::graph::Graph;
use super::*; use super::*;
use crate::graph::Graph;
#[test] #[test]
fn empty_footer_text() { fn empty_footer_text() {

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -1,7 +1,7 @@
use crate::{ use crate::{
prelude::*,
syntax::content::parser::{context::Inline, Lexeme, State, Token},
graph::Graph, graph::Graph,
prelude::*,
syntax::content::parser::{Lexeme, State, Token, context::Inline},
}; };
/// Handles open anchor contexts until an anchor token is fully parsed. /// Handles open anchor contexts until an anchor token is fully parsed.
@ -162,11 +162,9 @@ fn push(
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use crate::{syntax::content::parser, graph::Graph}; use crate::{graph::Graph, syntax::content::parser};
fn read(input: &str) -> String { fn read(input: &str) -> String { parser::read(input, &Graph::default()) }
parser::read(input, &Graph::default())
}
#[test] #[test]
fn flanking() { fn flanking() {
@ -188,7 +186,10 @@ mod tests {
fn flanking_with_trailing_comma_and_space() { fn flanking_with_trailing_comma_and_space() {
assert_eq!( assert_eq!(
read("|Node|, at"), 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() { fn needless_three_pipe_anchor() {
assert_eq!( assert_eq!(
read("|Node|Destination|"), 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() { fn nonleading_second_pipe() {
assert_eq!( assert_eq!(
read("Go to Node|Destination|, here"), 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() { fn anchor_to_node_s() {
assert_eq!( assert_eq!(
read("The |letter s|s|'s node: |s|!"), 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() { fn nonleading_plural_anchor() {
assert_eq!( assert_eq!(
read("The flower|s bloomed"), 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() { fn leading_plural_anchor() {
assert_eq!( assert_eq!(
read("Interfaces are |element|s of |system|s."), 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() { fn leading_multiword_anchor() {
assert_eq!( assert_eq!(
read("interactions are |basic elements| of systems"), 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() { fn explicit_end_of_destination() {
assert_eq!( assert_eq!(
read("interactions are |basic elements|BasicElements| of systems"), 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() { fn explicit_end_of_external_destination() {
assert_eq!( assert_eq!(
read("this |anchor example|https://example.com| is external"), 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() { fn external_anchor_destination_at_eoi() {
assert_eq!( assert_eq!(
read("a b|https://example.com"), 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() { fn nonleading_plural_anchor_at_eoi() {
assert_eq!( assert_eq!(
read("element|s"), 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() { fn leading_plural_anchor_at_eoi() {
assert_eq!( assert_eq!(
read("|element|s"), 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] #[test]
fn http_external_anchor() { fn http_external_anchor() {
assert_eq!( assert_eq!(
read( read("a |false dichotomy|https://wikipedia.org/False_dilemma|."),
"a |false dichotomy|https://en.wikipedia.org/wiki/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", "at rustup.rs",
)), )),
concat!( 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", "\n",
"at rustup.rs</p>", "at rustup.rs</p>",
) )
@ -326,7 +360,11 @@ mod tests {
fn http_external_anchor_leading_no_third_then_space() { fn http_external_anchor_leading_no_third_then_space() {
assert_eq!( assert_eq!(
read("|Rust toolchain|https://rustup.rs/ at rustup.rs"), 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() { fn http_external_anchor_leading_no_third_then_eoi() {
assert_eq!( assert_eq!(
read("|Rust toolchain|https://rustup.rs/"), 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"), read("\n|SomeAnchor|\n"),
concat!( concat!(
"\n", "\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!( assert_eq!(
read("|SomeAnchor|\n|SomeOtherAnchor|\n"), read("|SomeAnchor|\n|SomeOtherAnchor|\n"),
concat!( 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", "\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!( assert_eq!(
read("|SomeAnchor|\n\n|SomeOtherAnchor|\n"), read("|SomeAnchor|\n\n|SomeOtherAnchor|\n"),
concat!( 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",
"\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() { fn trailing_anchor() {
assert_eq!( assert_eq!(
read("see acks|acks"), 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"), read("\nsee acks|acks\n"),
concat!( concat!(
"\n", "\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() { fn anchor_with_trailing_single_quote() {
assert_eq!( assert_eq!(
read("the |lion|'s mouth"), 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() { fn anchor_with_trailing_double_quote() {
assert_eq!( assert_eq!(
read(r#"the "|real|" motive"#), 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() { fn anchor_with_trailing_parenthesis() {
assert_eq!( assert_eq!(
read("this (though |true|) was questioned"), 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() { fn anchor_with_leading_single_quote() {
assert_eq!( assert_eq!(
read("the 'real|Reality' motive"), 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() { fn anchor_with_leading_double_quote() {
assert_eq!( assert_eq!(
read(r#"the "real|Reality" motive"#), 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() { fn anchor_with_leading_parenthesis() {
assert_eq!( assert_eq!(
read("her (last|Surname) name"), 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() { fn anchor_with_internal_apostrophe() {
assert_eq!( assert_eq!(
read("the |lion's mouth|album was released"), 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() { fn nonleading_anchor_with_internal_apostrophe() {
assert_eq!( assert_eq!(
read("they decided to stay at Jane's|YellowHouse that night"), 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() { fn nonleading_anchor_with_internal_apostrophe_at_eoi() {
assert_eq!( assert_eq!(
read("they decided to stay at Jane's|YellowHouse"), 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() { fn nonleading_anchor_with_internal_apostrophe_at_soi() {
assert_eq!( assert_eq!(
read("Jane's|YellowHouse that night"), 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() { fn anchor_with_internal_double_quotes() {
assert_eq!( assert_eq!(
read(r#"the |"real"|Truth motive"#), 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() { fn anchor_with_internal_double_quotes_wrapping_spaced_words() {
assert_eq!( assert_eq!(
read(r#"the |"bare reality"|Ideology they believed"#), 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() { fn anchor_with_internal_parenthesis() {
assert_eq!( assert_eq!(
read("her |last (name)|Surname was Amad"), 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() { fn anchor_with_internal_parenthesis_wrapping_spaced_words() {
assert_eq!( assert_eq!(
read("this |truth (though questionable) was fine|Absurd to them "), 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::{ parser::{
Block, Lexeme, State, Token, Block, Lexeme, State, Token,
token::{ token::{
Header, List, LineBreak, Literal, Paragraph, PreFormat, Quote, Header, LineBreak, List, Literal, Paragraph, PreFormat, Quote,
Table, Verse, Table, Verse,
}, },
}, },
@ -124,16 +124,14 @@ pub fn parse(
mod tests { mod tests {
use crate::{ use crate::{
syntax::content::parser::{
self, Block, Token, context, State,
token::{Header, header::Level, PreFormat},
},
graph::Graph, graph::Graph,
syntax::content::parser::{
self, Block, State, Token, context,
token::{Header, PreFormat, header::Level},
},
}; };
fn read(input: &str) -> String { fn read(input: &str) -> String { parser::read(input, &Graph::default()) }
parser::read(input, &Graph::default())
}
#[test] #[test]
fn pre() { fn pre() {

View file

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

View file

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

View file

@ -117,11 +117,9 @@ pub fn parse(
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use crate::{syntax::content::parser, graph::Graph}; use crate::{graph::Graph, syntax::content::parser};
fn read(input: &str) -> String { fn read(input: &str) -> String { parser::read(input, &Graph::default()) }
parser::read(input, &Graph::default())
}
fn read_loaded(input: &str) -> String { fn read_loaded(input: &str) -> String {
parser::read(input, &Graph::load()) parser::read(input, &Graph::load())
@ -250,11 +248,13 @@ mod tests {
"<table>", "\n", "<table>", "\n",
" <tr>", "\n", " <tr>", "\n",
" <td>a</td>", "\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", " <td>c</td>", "\n",
" </tr>", "\n", " </tr>", "\n",
"</table>", "\n", "</table>", "\n",
)); )
);
} }
#[test] #[test]
@ -270,11 +270,14 @@ mod tests {
"<table>", "\n", "<table>", "\n",
" <tr>", "\n", " <tr>", "\n",
" <td>a</td>", "\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", " <td>c</td>", "\n",
" </tr>", "\n", " </tr>", "\n",
"</table>", "\n", "</table>", "\n",
)); )
);
} }
#[test] #[test]

View file

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

View file

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

View file

@ -58,17 +58,18 @@ pub fn parse(
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use crate::{syntax::content::parser, graph::Graph}; use crate::{graph::Graph, syntax::content::parser};
fn read(input: &str) -> String { fn read(input: &str) -> String { parser::read(input, &Graph::default()) }
parser::read(input, &Graph::default())
}
#[test] #[test]
fn oblique_anchor() { fn oblique_anchor() {
assert_eq!( assert_eq!(
read("w _|S|_ w"), 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() { fn oblique_anchor_with_trailing_comma() {
assert_eq!( assert_eq!(
read("w _|S|_, w"), 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() { fn oblique() {
assert_eq!( assert_eq!(
read( 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> { pub fn segment(text: &str) -> Vec<String> { delimiter::atomize(text) }
delimiter::atomize(text)
}
pub mod delimiter { pub mod delimiter {
@ -146,7 +144,8 @@ pub mod delimiter {
fn atomize_flankign_sentence() { fn atomize_flankign_sentence() {
assert_eq!( assert_eq!(
atomize( 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![ vec![
"about_colors", "about_colors",
@ -188,7 +187,8 @@ pub mod delimiter {
#[test] #[test]
fn atomize_words() { fn atomize_words() {
let actual = atomize( 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![ let expected = vec![
" ", " ",
@ -285,7 +285,8 @@ pub mod delimiter {
#[test] #[test]
fn atomize_pipes_and_ticks() { fn atomize_pipes_and_ticks() {
let actual = atomize( 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![ let expected = vec![
"every", "every",

View file

@ -101,24 +101,24 @@ mod tests {
#[test] #[test]
fn anchor_buffer_display_with_text_set() { fn anchor_buffer_display_with_text_set() {
let mut buffer = AnchorBuffer::default(); let mut buffer = AnchorBuffer::default();
buffer.text = String::from("mX8Z7yWmsK"); buffer.text = String::from("mX8Z7sK");
println!("{buffer:#?}"); println!("{buffer:#?}");
println!("{buffer}"); println!("{buffer}");
assert_eq!( assert_eq!(
format!("{buffer}"), format!("{buffer}"),
r#"AnchorBuffer [text: "mX8Z7yWmsK"] >> Anchor <empty> -> <unknown>"# r#"AnchorBuffer [text: "mX8Z7sK"] >> Anchor <empty> -> <unknown>"#
); );
} }
#[test] #[test]
fn anchor_buffer_display_with_destination_set() { fn anchor_buffer_display_with_destination_set() {
let mut buffer = AnchorBuffer::default(); let mut buffer = AnchorBuffer::default();
buffer.destination = String::from("VP2aqGngAq"); buffer.destination = String::from("VP2gAq");
println!("{buffer:#?}"); println!("{buffer:#?}");
println!("{buffer}"); println!("{buffer}");
assert_eq!( assert_eq!(
format!("{buffer}"), format!("{buffer}"),
r#"AnchorBuffer [, dest: "VP2aqGngAq"] >> Anchor <empty> -> <unknown>"# r#"AnchorBuffer [, dest: "VP2gAq"] >> Anchor <empty> -> <unknown>"#
); );
} }
@ -131,7 +131,10 @@ mod tests {
println!("{buffer}"); println!("{buffer}");
assert_eq!( assert_eq!(
format!("{buffer}"), 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 anchor;
pub mod bold; pub mod bold;
@ -18,12 +18,23 @@ pub mod table;
pub mod underline; pub mod underline;
pub mod verse; pub mod verse;
pub use { pub use anchor::Anchor;
anchor::Anchor, bold::Bold, checkbox::CheckBox, code::Code, header::Header, pub use bold::Bold;
item::Item, linebreak::LineBreak, list::List, literal::Literal, pub use checkbox::CheckBox;
oblique::Oblique, paragraph::Paragraph, preformat::PreFormat, quote::Quote, pub use code::Code;
strike::Strike, table::Table, underline::Underline, verse::Verse, 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)] #[derive(Debug, Eq, PartialEq, Clone)]
pub enum Token { pub enum Token {

View file

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

View file

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

View file

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

View file

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

View file

@ -1,15 +1,14 @@
use std::{ use std::{
collections::{HashMap, hash_map::Entry}, collections::{HashMap, hash_map::Entry},
fmt::Display,
}; };
use crate::{ use crate::{
prelude::*,
graph::Config, graph::Config,
syntax::content::{Parseable, Lexeme}, prelude::*,
syntax::content::{Lexeme, Parseable},
}; };
use std::fmt::Display;
#[derive(Debug, Clone, Eq, PartialEq)] #[derive(Debug, Clone, Eq, PartialEq)]
pub struct Header { pub struct Header {
open: Option<bool>, open: Option<bool>,
@ -113,9 +112,7 @@ impl Parseable for Header {
} }
} }
fn flatten(&self) -> String { fn flatten(&self) -> String { String::default() }
String::default()
}
} }
impl std::fmt::Display for Header { impl std::fmt::Display for Header {
@ -195,9 +192,8 @@ impl Display for Level {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use crate::syntax::content::parser::Token;
use super::*; use super::*;
use crate::syntax::content::parser::Token;
#[test] #[test]
fn make_id() { 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)] #[derive(Default, Debug, Clone, Eq, PartialEq)]
pub struct Item { pub struct Item {
@ -7,9 +7,7 @@ pub struct Item {
} }
impl Parseable for Item { impl Parseable for Item {
fn probe(_: &Lexeme) -> bool { fn probe(_: &Lexeme) -> bool { false }
false
}
fn lex(_: &Lexeme) -> Item { fn lex(_: &Lexeme) -> Item {
panic!("Attempt to lex an item directly from a lexeme") 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") panic!("Items should only be rendered by a list's render method")
} }
fn flatten(&self) -> String { fn flatten(&self) -> String { String::default() }
String::default()
}
} }
impl Item { impl Item {
@ -50,9 +46,8 @@ impl std::fmt::Display for Item {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use crate::syntax::content::parser::Token;
use super::*; use super::*;
use crate::syntax::content::parser::Token;
#[test] #[test]
#[should_panic( #[should_panic(

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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