From 30369cfdd396794f078115fcd133a5a1f6fef352 Mon Sep 17 00:00:00 2001 From: Kerdonov Date: Thu, 11 Dec 2025 01:46:57 +0200 Subject: [PATCH 1/4] initial parser working --- Cargo.lock | 20 ++- Cargo.toml | 1 + bacon.toml | 132 ++++++++++++++++++++ rust-toolchain | 1 - rust-toolchain.toml | 10 ++ src/ast.rs | 69 +++++++++++ src/main.rs | 5 +- src/parser/block.rs | 243 ++++++++++++++++++++++++++++++++++++ src/parser/inline.rs | 287 +++++++++++++++++++++++++++++++++++++++++++ src/parser/mod.rs | 3 + 10 files changed, 767 insertions(+), 4 deletions(-) create mode 100644 bacon.toml delete mode 100644 rust-toolchain create mode 100644 rust-toolchain.toml create mode 100644 src/ast.rs create mode 100644 src/parser/block.rs create mode 100644 src/parser/inline.rs create mode 100644 src/parser/mod.rs diff --git a/Cargo.lock b/Cargo.lock index 29c8ac6..7b45833 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,4 +4,22 @@ version = 4 [[package]] name = "marginal" -version = "0.1.0" +version = "0.0.1" +dependencies = [ + "nom", +] + +[[package]] +name = "memchr" +version = "2.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f52b00d39961fc5b2736ea853c9cc86238e165017a493d1d5c8eac6bdc4cc273" + +[[package]] +name = "nom" +version = "8.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df9761775871bdef83bee530e60050f7e54b1105350d6884eb0fb4f46c2f9405" +dependencies = [ + "memchr", +] diff --git a/Cargo.toml b/Cargo.toml index 8988115..abff013 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,3 +4,4 @@ version = "0.0.1" edition = "2024" [dependencies] +nom = "8.0.0" diff --git a/bacon.toml b/bacon.toml new file mode 100644 index 0000000..ec3d796 --- /dev/null +++ b/bacon.toml @@ -0,0 +1,132 @@ +# This is a configuration file for the bacon tool +# +# Complete help on configuration: https://dystroy.org/bacon/config/ +# +# You may check the current default at +# https://github.com/Canop/bacon/blob/main/defaults/default-bacon.toml + +default_job = "check" +env.CARGO_TERM_COLOR = "always" + +[jobs.check] +command = ["cargo", "check"] +need_stdout = false + +[jobs.check-all] +command = ["cargo", "check", "--all-targets"] +need_stdout = false + +# Run clippy on the default target +[jobs.clippy] +command = ["cargo", "clippy"] +need_stdout = false + +# Run clippy on all targets +# To disable some lints, you may change the job this way: +# [jobs.clippy-all] +# command = [ +# "cargo", "clippy", +# "--all-targets", +# "--", +# "-A", "clippy::bool_to_int_with_if", +# "-A", "clippy::collapsible_if", +# "-A", "clippy::derive_partial_eq_without_eq", +# ] +# need_stdout = false +[jobs.clippy-all] +command = ["cargo", "clippy", "--all-targets"] +need_stdout = false + +# Run clippy in pedantic mode +# The 'dismiss' feature may come handy +[jobs.pedantic] +command = [ + "cargo", "clippy", + "--", + "-W", "clippy::pedantic", +] +need_stdout = false + +# This job lets you run +# - all tests: bacon test +# - a specific test: bacon test -- config::test_default_files +# - the tests of a package: bacon test -- -- -p config +[jobs.test] +command = [ + "cargo", "nextest", "run", + "--hide-progress-bar", + "--failure-output", "final", + "--no-fail-fast" +] +need_stdout = true +analyzer = "nextest" + +[jobs.nextest] +command = [ + "cargo", "nextest", "run", + "--hide-progress-bar", + "--failure-output", "final", +] +need_stdout = true +analyzer = "nextest" + +[jobs.doc] +command = ["cargo", "doc", "--no-deps"] +need_stdout = false + +# If the doc compiles, then it opens in your browser and bacon switches +# to the previous job +[jobs.doc-open] +command = ["cargo", "doc", "--no-deps", "--open"] +need_stdout = false +on_success = "back" # so that we don't open the browser at each change + +# You can run your application and have the result displayed in bacon, +# if it makes sense for this crate. +[jobs.run] +command = [ + "cargo", "run", + # put launch parameters for your program behind a `--` separator +] +need_stdout = true +allow_warnings = true +background = true + +# Run your long-running application (eg server) and have the result displayed in bacon. +# For programs that never stop (eg a server), `background` is set to false +# to have the cargo run output immediately displayed instead of waiting for +# program's end. +# 'on_change_strategy' is set to `kill_then_restart` to have your program restart +# on every change (an alternative would be to use the 'F5' key manually in bacon). +# If you often use this job, it makes sense to override the 'r' key by adding +# a binding `r = job:run-long` at the end of this file . +# A custom kill command such as the one suggested below is frequently needed to kill +# long running programs (uncomment it if you need it) +[jobs.run-long] +command = [ + "cargo", "run", + # put launch parameters for your program behind a `--` separator +] +need_stdout = true +allow_warnings = true +background = false +on_change_strategy = "kill_then_restart" +# kill = ["pkill", "-TERM", "-P"] + +# This parameterized job runs the example of your choice, as soon +# as the code compiles. +# Call it as +# bacon ex -- my-example +[jobs.ex] +command = ["cargo", "run", "--example"] +need_stdout = true +allow_warnings = true + +# You may define here keybindings that would be specific to +# a project, for example a shortcut to launch a specific job. +# Shortcuts to internal functions (scrolling, toggling, etc.) +# should go in your personal global prefs.toml file instead. +[keybindings] +# alt-m = "job:my-job" +c = "job:clippy-all" # comment this to have 'c' run clippy on only the default target +p = "job:pedantic" diff --git a/rust-toolchain b/rust-toolchain deleted file mode 100644 index 2bf5ad0..0000000 --- a/rust-toolchain +++ /dev/null @@ -1 +0,0 @@ -stable diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 0000000..89eb9bb --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,10 @@ +[toolchain] +channel = "stable" +targets = [ + "x86_64-unknown-linux-gnu" +] +components = [ + "clippy", + "rustfmt", + "rust-analyzer" +] diff --git a/src/ast.rs b/src/ast.rs new file mode 100644 index 0000000..e6a8ab0 --- /dev/null +++ b/src/ast.rs @@ -0,0 +1,69 @@ +// Grammar rules: +// +// Markdown ::= Block Markdown | Block +// +// Block ::= (Heading | CodeBlock | Quote | Paragraph) "\n\n" +// Heading ::= "#{1,6}\s" Inline +// CodeBlock ::= "```.*\n" "(.*?\n)*" "```" +// Quote ::= ">" Block +// Paragraph ::= Inline +// +// Inline ::= InlineElem Inline | InlineElem +// InlineElem ::= Bold | Italic | Code | Link | Text +// Bold ::= "\*" Inline "\*" +// Italic ::= "_" Inline "_" +// Code ::= "`" "[.^`]*" "`" +// Link ::= "\[" Inline "\]\(" Href "\)" +// Href ::= "[.^\)]*" +// Text ::= "[.^`*_\[]*" + +#[derive(Debug, PartialEq)] +pub enum Inline { + Bold { inner: Vec }, + Italic { inner: Vec }, + Link { inner: Vec, href: Href }, + Code { content: String }, + Text { content: String }, +} + +#[derive(Debug, PartialEq)] +pub struct Href(pub String); + +impl Href { + pub fn new(href: &str) -> Self { + // can check for link correctness + Self(href.to_string()) + } +} + +/* +pub struct Markdown { + block: Block, + rest: Option>, +} + +pub enum Block { + Heading(HeadingBlock), + Code(CodeBlock), + Quote(QuoteBlock), + Paragraph(ParagraphBlock), +} + +pub struct HeadingBlock { + level: u8, + content: Inline, +} + +pub struct CodeBlock { + lang: String, + content: String, +} + +pub struct QuoteBlock { + content: Box, +} + +pub struct ParagraphBlock { + content: String, +} +*/ diff --git a/src/main.rs b/src/main.rs index 40e393c..29a7b29 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,7 @@ - mod ast; +mod parser; + fn main() { - + } diff --git a/src/parser/block.rs b/src/parser/block.rs new file mode 100644 index 0000000..cf520b4 --- /dev/null +++ b/src/parser/block.rs @@ -0,0 +1,243 @@ +#![allow(dead_code)] + +use crate::{ast::Inline, parser::inline::inline}; +use nom::{ + IResult, Parser, + bytes::complete::{tag, take_until}, + multi::{many_m_n, many1, many0}, + sequence::{terminated, delimited}, + branch::alt, +}; + +#[derive(Debug, PartialEq)] +pub enum Block { + Heading { inner: Vec, level: u8 }, + Code { content: String, lang: String }, + Quote { inner: Box }, + Paragraph { inner: Vec }, +} + +pub fn blocks(input: &str) -> IResult<&str, Vec> { + many0(block).parse(input) +} + + +pub fn block(input: &str) -> IResult<&str, Block> { + terminated( + alt((heading_block, code_block, quote_block, paragraph_block)), + tag("\n"), + ).parse(input) +} + +fn paragraph_block(input: &str) -> IResult<&str, Block> { + (inline) + .parse(input) + .map(|(rem, inl)| (rem, Block::Paragraph { inner: inl })) +} + +fn heading_block(input: &str) -> IResult<&str, Block> { + (many_m_n(1, 6, tag("#")), many1(tag(" ")), inline) + .parse(input) + .map(|(rem, (head, _, title))| { + ( + rem, + Block::Heading { + inner: title, + level: head.len() as u8, + }, + ) + }) +} + +fn code_block(input: &str) -> IResult<&str, Block> { + delimited( + tag("```"), + (take_until("\n"), tag("\n"), take_until("```\n")), + tag("```\n"), + ) + .parse(input) + .map(|(rem, (lang, _, code))| { + ( + rem, + Block::Code { + content: code.to_string(), + lang: lang.to_string(), + }, + ) + }) +} + +fn quote_block(input: &str) -> IResult<&str, Block> { + (tag(">"), many0(tag(" ")), block).parse(input).map(|(rem, (_, _, inner))| { + ( + rem, + Block::Quote { + inner: Box::new(inner), + }, + ) + }) +} + +//|-------------------------------------------------------------------------------| +//| TESTS TESTS TESTS TESTS TESTS TESTS TESTS TESTS TESTS TESTS TESTS TESTS TESTS | +//|-------------------------------------------------------------------------------| + +#[cfg(test)] +mod test { + use super::*; + use crate::ast::Inline; + + #[test] + fn single_paragraph() { + let md = "Hello markdown!!"; + let (rem, block) = paragraph_block(md).unwrap(); + + assert_eq!(rem, ""); + assert_eq!( + block, + Block::Paragraph { + inner: vec![Inline::Text { + content: "Hello markdown!!".to_string() + }] + } + ); + } + + #[test] + fn single_code_block_with_language() { + let md = "```rust +fn main() { +\tprintln!(\"Hello, World\"); +} +``` +"; + let (rem, block) = code_block(md).unwrap(); + + assert_eq!(rem, ""); + assert_eq!( + block, + Block::Code { + content: "fn main() {\n\tprintln!(\"Hello, World\");\n}\n".to_string(), + lang: "rust".to_string(), + } + ) + } + + #[test] + fn single_code_block_without_language() { + let md = "``` +echo \"hello world\" +``` +"; + let (rem, block) = code_block(md).unwrap(); + + assert_eq!(rem, ""); + assert_eq!( + block, + Block::Code { + content: "echo \"hello world\"\n".to_string(), + lang: "".to_string(), + } + ); + } + + #[test] + fn single_code_block_fail() { + let md = "```abc +echo hello +```errortext +"; + assert!(code_block(md).is_err()); + } + + #[test] + fn level_1_heading() { + let md = "## Heading2"; + let (rem, block) = heading_block(md).unwrap(); + + assert_eq!(rem, ""); + assert_eq!( + block, + Block::Heading { + inner: vec![Inline::Text { + content: "Heading2".to_string() + }], + level: 2, + } + ); + } + + #[test] + fn heading_no_space() { + let md = "#heading"; + assert!(heading_block(md).is_err()); + } + + #[test] + fn level_6_heading() { + let md = "###### Heading6"; + let (rem, block) = heading_block(md).unwrap(); + + assert_eq!(rem, ""); + assert_eq!( + block, + Block::Heading { + inner: vec![Inline::Text { + content: "Heading6".to_string() + }], + level: 6, + } + ); + } + + #[test] + fn no_level_7_heading() { + let md = "####### Heading7"; + assert!(heading_block(md).is_err()); + } + + #[test] + fn single_quote_block_with_paragraph() { + let md = "> sun tzu\n"; + let (rem, block) = quote_block(md).unwrap(); + + assert_eq!(rem, ""); + assert_eq!( + block, + Block::Quote { + inner: Box::new(Block::Paragraph { + inner: vec![ + Inline::Text { content: "sun tzu".to_string() } + ] + }) + } + ); + } + + #[test] + fn heading_and_paragraph() { + let md = +"## Heading +Hello MD +"; + let (rem, blocks) = blocks(md).unwrap(); + + assert_eq!(rem, ""); + assert_eq!( + blocks, + vec![ + Block::Heading { + inner: vec![ + Inline::Text { content: "Heading".to_string() } + ], + level: 2 + }, + Block::Paragraph { + inner: vec![ + Inline::Text { content: "Hello MD".to_string() } + ] + } + ] + ); + } +} diff --git a/src/parser/inline.rs b/src/parser/inline.rs new file mode 100644 index 0000000..131d327 --- /dev/null +++ b/src/parser/inline.rs @@ -0,0 +1,287 @@ +#![allow(dead_code)] + +use nom::IResult; +use nom::{ + Parser, + branch::alt, + bytes::complete::{is_not, tag}, + error::context, + multi::many0, + sequence::delimited, +}; + +use crate::ast::{Inline, Href}; + + +pub fn inline(input: &str) -> IResult<&str, Vec> { + many0(alt((text_inline, bold_inline, italic_inline, code_inline, link_inline))).parse(input) +} + +fn text_inline(input: &str) -> IResult<&str, Inline> { + is_not("*_`[]\n").parse(input).map(|(rem, con)| { + ( + rem, + Inline::Text { + content: con.to_string(), + }, + ) + }) +} + +fn bold_inline(input: &str) -> IResult<&str, Inline> { + delimited( + context("opening bold tag", tag("*")), + inline, + context("closing bold tag", tag("*")), + ) + .parse(input) + .map(|(rem, inl)| (rem, Inline::Bold { inner: inl })) +} + +fn italic_inline(input: &str) -> IResult<&str, Inline> { + delimited( + context("opening italics tag", tag("_")), + inline, + context("closing italics tag", tag("_")), + ) + .parse(input) + .map(|(rem, inl)| (rem, Inline::Italic { inner: inl })) +} + +fn code_inline(input: &str) -> IResult<&str, Inline> { + delimited( + context("opening code tag", tag("`")), + context("inline code", is_not("`\n")), + context("closing code tag", tag("`")), + ) + .parse(input) + .map(|(rem, inl)| (rem, Inline::Code { content: inl.to_string() })) +} + +fn link_inline(input: &str) -> IResult<&str, Inline> { + ( + delimited( + context("opening link tag", tag("[")), + context("link name", inline), + context("closing link tag", tag("]")), + ), + delimited( + context("opening href tag", tag("(")), + context("link href", is_not(")\n")), + context("closing href tag", tag(")")), + ) + ) + .parse(input) + .map(|(rem, (name, href))| (rem, Inline::Link { inner: name, href: Href::new(href) })) +} + + +//|-------------------------------------------------------------------------------| +//| TESTS TESTS TESTS TESTS TESTS TESTS TESTS TESTS TESTS TESTS TESTS TESTS TESTS | +//|-------------------------------------------------------------------------------| + +#[cfg(test)] +mod test { + use super::*; + + #[test] + fn single_text() { + let md = "hello normal inline"; + let (rem, parsed) = text_inline(md).unwrap(); + + assert_eq!(rem, ""); + assert_eq!( + parsed, + Inline::Text { + content: "hello normal inline".to_string() + } + ); + } + + #[test] + fn single_bold() { + let md = "*bold text*"; + let (rem, parsed) = bold_inline(md).unwrap(); + + assert_eq!(rem, ""); + assert_eq!( + parsed, + Inline::Bold { + inner: vec![Inline::Text { + content: "bold text".to_string() + }] + } + ); + } + + #[test] + fn bold_with_leftovers() { + let md = "*bold* leftover"; + let (rem, parsed) = bold_inline(md).unwrap(); + + assert_eq!(rem, " leftover"); + assert_eq!( + parsed, + Inline::Bold { + inner: vec![Inline::Text { + content: "bold".to_string() + }] + } + ) + } + + #[test] + fn inline_normal_and_bold() { + let md = "some *bold* text"; + let (rem, parsed) = inline(md).unwrap(); + + assert_eq!(rem, ""); + assert_eq!( + parsed, + vec![ + Inline::Text { + content: "some ".to_string() + }, + Inline::Bold { + inner: vec![Inline::Text { + content: "bold".to_string() + }] + }, + Inline::Text { + content: " text".to_string() + }, + ] + ) + } + + #[test] + fn multiple_normal_and_bold() { + let md = "some *bold* text and more *bold stuff*"; + let (rem, parsed) = inline(md).unwrap(); + + assert_eq!(rem, ""); + assert_eq!( + parsed, + vec![ + Inline::Text { + content: "some ".to_string() + }, + Inline::Bold { + inner: vec![Inline::Text { + content: "bold".to_string() + }] + }, + Inline::Text { + content: " text and more ".to_string() + }, + Inline::Bold { + inner: vec![Inline::Text { + content: "bold stuff".to_string() + }] + }, + ] + ); + } + + #[test] + fn normal_and_nested_bold() { + let md = "some **extra* bold* stuff"; + let (rem, parsed) = inline(md).unwrap(); + + assert_eq!(rem, ""); + assert_eq!( + parsed, + vec![ + Inline::Text { + content: "some ".to_string() + }, + Inline::Bold { inner: vec![] }, + Inline::Text { + content: "extra".to_string() + }, + Inline::Bold { + inner: vec![Inline::Text { + content: " bold".to_string() + }] + }, + Inline::Text { + content: " stuff".to_string() + }, + ] + ); + } + + #[test] + fn nested_bold_and_italics() { + let md = "some _nested *bold* + italics_, yeah"; + let (rem, parsed) = inline(md).unwrap(); + + assert_eq!(rem, ""); + assert_eq!( + parsed, + vec![ + Inline::Text { + content: "some ".to_string() + }, + Inline::Italic { + inner: vec![ + Inline::Text { + content: "nested ".to_string() + }, + Inline::Bold { + inner: vec![Inline::Text { + content: "bold".to_string() + }] + }, + Inline::Text { + content: " + italics".to_string() + }, + ] + }, + Inline::Text { + content: ", yeah".to_string() + }, + ] + ); + } + + #[test] + fn inline_code_bamboozle() { + let md = "take some `code and *bold* and _italics_` lmao"; + let (rem, parsed) = inline(md).unwrap(); + + assert_eq!(rem, ""); + assert_eq!( + parsed, + vec![ + Inline::Text { content: "take some ".to_string() }, + Inline::Code { content: "code and *bold* and _italics_".to_string() }, + Inline::Text { content: " lmao".to_string() } + ] + ); + } + + #[test] + fn bold_link_text() { + let md = "[this link is *important*](http://example.com)"; + let (rem, parsed) = link_inline(md).unwrap(); + + println!("{rem}"); + + assert_eq!(rem, ""); + assert_eq!( + parsed, + Inline::Link { + inner: vec![ + Inline::Text { content: "this link is ".to_string() }, + Inline::Bold { + inner: vec![Inline::Text { + content: "important".to_string() + }] + }, + ], + href: Href("http://example.com".to_string()) + } + ) + } +} diff --git a/src/parser/mod.rs b/src/parser/mod.rs new file mode 100644 index 0000000..29867db --- /dev/null +++ b/src/parser/mod.rs @@ -0,0 +1,3 @@ +pub mod inline; +pub mod block; + From 17185d4420635c5890edcba66a7cade8fa3d7d21 Mon Sep 17 00:00:00 2001 From: Kerdonov Date: Mon, 15 Dec 2025 01:19:23 +0200 Subject: [PATCH 2/4] added html generation --- Cargo.lock | 123 ++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 3 +- src/ast.rs | 55 ++++-------------- src/generator/block.rs | 26 +++++++++ src/generator/file.rs | 13 +++++ src/generator/inline.rs | 27 +++++++++ src/generator/mod.rs | 56 ++++++++++++++++++ src/main.rs | 11 +++- src/parser/block.rs | 73 +++++++++++------------- src/parser/inline.rs | 93 ++++++++++++++++-------------- src/parser/mod.rs | 33 ++++++++++- test.html | 0 test.md | 12 ++++ 13 files changed, 392 insertions(+), 133 deletions(-) create mode 100644 src/generator/block.rs create mode 100644 src/generator/file.rs create mode 100644 src/generator/inline.rs create mode 100644 src/generator/mod.rs create mode 100644 test.html create mode 100644 test.md diff --git a/Cargo.lock b/Cargo.lock index 7b45833..f1ea844 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,10 +2,100 @@ # It is not intended for manual editing. version = 4 +[[package]] +name = "anstream" +version = "0.6.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43d5b281e737544384e969a5ccad3f1cdd24b48086a0fc1b2a5262a26b8f4f4a" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "is_terminal_polyfill", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5192cca8006f1fd4f7237516f40fa183bb07f8fbdfedaa0036de5ea9b0b45e78" + +[[package]] +name = "anstyle-parse" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e7644824f0aa2c7b9384579234ef10eb7efb6a0deb83f9630a49594dd9c15c2" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40c48f72fd53cd289104fc64099abca73db4166ad86ea0b4341abe65af83dadc" +dependencies = [ + "windows-sys", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "291e6a250ff86cd4a820112fb8898808a366d8f9f58ce16d1f538353ad55747d" +dependencies = [ + "anstyle", + "once_cell_polyfill", + "windows-sys", +] + +[[package]] +name = "clap" +version = "4.5.53" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c9e340e012a1bf4935f5282ed1436d1489548e8f72308207ea5df0e23d2d03f8" +dependencies = [ + "clap_builder", +] + +[[package]] +name = "clap_builder" +version = "4.5.53" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d76b5d13eaa18c901fd2f7fca939fefe3a0727a953561fefdf3b2922b8569d00" +dependencies = [ + "anstream", + "anstyle", + "clap_lex", + "strsim", +] + +[[package]] +name = "clap_lex" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1d728cc89cf3aee9ff92b05e62b19ee65a02b5702cff7d5a377e32c6ae29d8d" + +[[package]] +name = "colorchoice" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b05b61dc5112cbb17e4b6cd61790d9845d13888356391624cbe7e41efeac1e75" + +[[package]] +name = "is_terminal_polyfill" +version = "1.70.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6cb138bb79a146c1bd460005623e142ef0181e3d0219cb493e02f7d08a35695" + [[package]] name = "marginal" version = "0.0.1" dependencies = [ + "clap", "nom", ] @@ -23,3 +113,36 @@ checksum = "df9761775871bdef83bee530e60050f7e54b1105350d6884eb0fb4f46c2f9405" dependencies = [ "memchr", ] + +[[package]] +name = "once_cell_polyfill" +version = "1.70.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe" + +[[package]] +name = "strsim" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" + +[[package]] +name = "utf8parse" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" + +[[package]] +name = "windows-link" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" + +[[package]] +name = "windows-sys" +version = "0.61.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc" +dependencies = [ + "windows-link", +] diff --git a/Cargo.toml b/Cargo.toml index abff013..4ef899d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,4 +4,5 @@ version = "0.0.1" edition = "2024" [dependencies] -nom = "8.0.0" +clap = "4.5.53" +nom = { version = "8.0.0", features = ["std"] } diff --git a/src/ast.rs b/src/ast.rs index e6a8ab0..3474045 100644 --- a/src/ast.rs +++ b/src/ast.rs @@ -1,21 +1,4 @@ -// Grammar rules: -// -// Markdown ::= Block Markdown | Block -// -// Block ::= (Heading | CodeBlock | Quote | Paragraph) "\n\n" -// Heading ::= "#{1,6}\s" Inline -// CodeBlock ::= "```.*\n" "(.*?\n)*" "```" -// Quote ::= ">" Block -// Paragraph ::= Inline -// -// Inline ::= InlineElem Inline | InlineElem -// InlineElem ::= Bold | Italic | Code | Link | Text -// Bold ::= "\*" Inline "\*" -// Italic ::= "_" Inline "_" -// Code ::= "`" "[.^`]*" "`" -// Link ::= "\[" Inline "\]\(" Href "\)" -// Href ::= "[.^\)]*" -// Text ::= "[.^`*_\[]*" +use std::fmt::Display; #[derive(Debug, PartialEq)] pub enum Inline { @@ -36,34 +19,16 @@ impl Href { } } -/* -pub struct Markdown { - block: Block, - rest: Option>, +impl Display for Href { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{}", self.0) + } } +#[derive(Debug, PartialEq)] pub enum Block { - Heading(HeadingBlock), - Code(CodeBlock), - Quote(QuoteBlock), - Paragraph(ParagraphBlock), + Heading { inner: Vec, level: u8 }, + Code { content: String, lang: String }, + Quote { inner: Box }, + Paragraph { inner: Vec }, } - -pub struct HeadingBlock { - level: u8, - content: Inline, -} - -pub struct CodeBlock { - lang: String, - content: String, -} - -pub struct QuoteBlock { - content: Box, -} - -pub struct ParagraphBlock { - content: String, -} -*/ diff --git a/src/generator/block.rs b/src/generator/block.rs new file mode 100644 index 0000000..3febbfc --- /dev/null +++ b/src/generator/block.rs @@ -0,0 +1,26 @@ +use crate::ast::Block; + +use super::ToHtml; + +impl ToHtml for Vec { + fn to_html(&self) -> String { + let mut html = String::new(); + for block in self.iter() { + html.push_str(&block.to_html()) + } + html + } +} + +impl ToHtml for Block { + fn to_html(&self) -> String { + match self { + Block::Paragraph { inner } => format!("

{}


", inner.to_html()), + Block::Heading { inner, level } => { + format!("{}", level, inner.to_html(), level) + } + Block::Code { content, lang: _ } => format!("
{content}
"), + Block::Quote { inner } => format!("
{}
", inner.to_html()), + } + } +} diff --git a/src/generator/file.rs b/src/generator/file.rs new file mode 100644 index 0000000..a1f9699 --- /dev/null +++ b/src/generator/file.rs @@ -0,0 +1,13 @@ +use std::{fs, path::PathBuf}; + +use crate::parser::block::blocks; + +use super::{GenerationError, ToHtml, TryToHtml}; + +impl TryToHtml for PathBuf { + fn try_to_html(&self) -> Result { + let content_md = fs::read_to_string(self)?; + let (_rem, generated) = blocks(&content_md)?; + Ok(generated.to_html()) + } +} diff --git a/src/generator/inline.rs b/src/generator/inline.rs new file mode 100644 index 0000000..2038fa2 --- /dev/null +++ b/src/generator/inline.rs @@ -0,0 +1,27 @@ +use crate::ast::Inline; + +use super::ToHtml; + +impl ToHtml for Vec { + fn to_html(&self) -> String { + let mut html = String::new(); + for inline in self.iter() { + html.push_str(&inline.to_html()) + } + html + } +} + +impl ToHtml for Inline { + fn to_html(&self) -> String { + match self { + Inline::Text { content } => content.to_owned(), + Inline::Bold { inner } => format!("{}", inner.to_html()), + Inline::Italic { inner } => format!("{}", inner.to_html()), + Inline::Code { content } => format!("{content}"), + Inline::Link { inner, href } => { + format!("{}", href, inner.to_html()) + } + } + } +} diff --git a/src/generator/mod.rs b/src/generator/mod.rs new file mode 100644 index 0000000..9237a2b --- /dev/null +++ b/src/generator/mod.rs @@ -0,0 +1,56 @@ +use std::fmt::Display; + +use crate::parser::MarkdownParseError; + +pub mod block; +pub mod file; +pub mod inline; + +#[derive(Debug)] +pub enum GenerationError { + IO(std::io::Error), + Parse(nom::Err), +} + +impl Display for GenerationError { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!( + f, + "Generation Error: {}", + match self { + GenerationError::IO(e) => format!("IO: {e}"), + GenerationError::Parse(e) => format!("Parse: {e}"), + } + ) + } +} + +impl From for GenerationError { + fn from(value: std::io::Error) -> Self { + Self::IO(value) + } +} + +impl From> for GenerationError { + fn from(value: nom::Err) -> Self { + Self::Parse(value) + } +} + +impl std::error::Error for GenerationError {} + +pub trait ToHtml { + fn to_html(&self) -> String; +} + +pub trait TryToHtml { + fn try_to_html(&self) -> Result; +} + +/* +impl TryToHtml for T { + fn try_to_html(&self) -> Result> { + Ok::>>(self.to_html()) + } +} +*/ diff --git a/src/main.rs b/src/main.rs index 29a7b29..d306d34 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,14 @@ +use crate::generator::TryToHtml; +use std::path::PathBuf; + mod ast; +mod generator; mod parser; - fn main() { - + let infile = PathBuf::from("test.md"); + + let html = infile.try_to_html().unwrap(); + + println!("{}", html); } diff --git a/src/parser/block.rs b/src/parser/block.rs index cf520b4..f1f96ad 100644 --- a/src/parser/block.rs +++ b/src/parser/block.rs @@ -1,41 +1,33 @@ -#![allow(dead_code)] - -use crate::{ast::Inline, parser::inline::inline}; +use crate::{ast::Block, parser::inline::inline}; use nom::{ IResult, Parser, - bytes::complete::{tag, take_until}, - multi::{many_m_n, many1, many0}, - sequence::{terminated, delimited}, branch::alt, + bytes::complete::{tag, take_until}, + multi::{many_m_n, many0, many1}, + sequence::{delimited, terminated}, }; -#[derive(Debug, PartialEq)] -pub enum Block { - Heading { inner: Vec, level: u8 }, - Code { content: String, lang: String }, - Quote { inner: Box }, - Paragraph { inner: Vec }, -} +use super::MarkdownParseError; -pub fn blocks(input: &str) -> IResult<&str, Vec> { +pub fn blocks(input: &str) -> IResult<&str, Vec, MarkdownParseError> { many0(block).parse(input) } - -pub fn block(input: &str) -> IResult<&str, Block> { +pub fn block(input: &str) -> IResult<&str, Block, MarkdownParseError> { terminated( alt((heading_block, code_block, quote_block, paragraph_block)), tag("\n"), - ).parse(input) + ) + .parse(input) } -fn paragraph_block(input: &str) -> IResult<&str, Block> { +fn paragraph_block(input: &str) -> IResult<&str, Block, MarkdownParseError> { (inline) .parse(input) .map(|(rem, inl)| (rem, Block::Paragraph { inner: inl })) } -fn heading_block(input: &str) -> IResult<&str, Block> { +fn heading_block(input: &str) -> IResult<&str, Block, MarkdownParseError> { (many_m_n(1, 6, tag("#")), many1(tag(" ")), inline) .parse(input) .map(|(rem, (head, _, title))| { @@ -49,7 +41,7 @@ fn heading_block(input: &str) -> IResult<&str, Block> { }) } -fn code_block(input: &str) -> IResult<&str, Block> { +fn code_block(input: &str) -> IResult<&str, Block, MarkdownParseError> { delimited( tag("```"), (take_until("\n"), tag("\n"), take_until("```\n")), @@ -67,15 +59,17 @@ fn code_block(input: &str) -> IResult<&str, Block> { }) } -fn quote_block(input: &str) -> IResult<&str, Block> { - (tag(">"), many0(tag(" ")), block).parse(input).map(|(rem, (_, _, inner))| { - ( - rem, - Block::Quote { - inner: Box::new(inner), - }, - ) - }) +fn quote_block(input: &str) -> IResult<&str, Block, MarkdownParseError> { + (tag(">"), many0(tag(" ")), block) + .parse(input) + .map(|(rem, (_, _, inner))| { + ( + rem, + Block::Quote { + inner: Box::new(inner), + }, + ) + }) } //|-------------------------------------------------------------------------------| @@ -206,9 +200,9 @@ echo hello block, Block::Quote { inner: Box::new(Block::Paragraph { - inner: vec![ - Inline::Text { content: "sun tzu".to_string() } - ] + inner: vec![Inline::Text { + content: "sun tzu".to_string() + }] }) } ); @@ -216,8 +210,7 @@ echo hello #[test] fn heading_and_paragraph() { - let md = -"## Heading + let md = "## Heading Hello MD "; let (rem, blocks) = blocks(md).unwrap(); @@ -227,15 +220,15 @@ Hello MD blocks, vec![ Block::Heading { - inner: vec![ - Inline::Text { content: "Heading".to_string() } - ], + inner: vec![Inline::Text { + content: "Heading".to_string() + }], level: 2 }, Block::Paragraph { - inner: vec![ - Inline::Text { content: "Hello MD".to_string() } - ] + inner: vec![Inline::Text { + content: "Hello MD".to_string() + }] } ] ); diff --git a/src/parser/inline.rs b/src/parser/inline.rs index 131d327..1c4941f 100644 --- a/src/parser/inline.rs +++ b/src/parser/inline.rs @@ -1,23 +1,28 @@ -#![allow(dead_code)] - use nom::IResult; use nom::{ Parser, branch::alt, bytes::complete::{is_not, tag}, - error::context, multi::many0, sequence::delimited, }; -use crate::ast::{Inline, Href}; +use crate::ast::{Href, Inline}; +use super::MarkdownParseError; -pub fn inline(input: &str) -> IResult<&str, Vec> { - many0(alt((text_inline, bold_inline, italic_inline, code_inline, link_inline))).parse(input) +pub fn inline(input: &str) -> IResult<&str, Vec, MarkdownParseError> { + many0(alt(( + text_inline, + bold_inline, + italic_inline, + code_inline, + link_inline, + ))) + .parse(input) } -fn text_inline(input: &str) -> IResult<&str, Inline> { +fn text_inline(input: &str) -> IResult<&str, Inline, MarkdownParseError> { is_not("*_`[]\n").parse(input).map(|(rem, con)| { ( rem, @@ -28,54 +33,48 @@ fn text_inline(input: &str) -> IResult<&str, Inline> { }) } -fn bold_inline(input: &str) -> IResult<&str, Inline> { - delimited( - context("opening bold tag", tag("*")), - inline, - context("closing bold tag", tag("*")), - ) +fn bold_inline(input: &str) -> IResult<&str, Inline, MarkdownParseError> { + delimited(tag("*"), inline, tag("*")) .parse(input) .map(|(rem, inl)| (rem, Inline::Bold { inner: inl })) } -fn italic_inline(input: &str) -> IResult<&str, Inline> { - delimited( - context("opening italics tag", tag("_")), - inline, - context("closing italics tag", tag("_")), - ) +fn italic_inline(input: &str) -> IResult<&str, Inline, MarkdownParseError> { + delimited(tag("_"), inline, tag("_")) .parse(input) .map(|(rem, inl)| (rem, Inline::Italic { inner: inl })) } -fn code_inline(input: &str) -> IResult<&str, Inline> { - delimited( - context("opening code tag", tag("`")), - context("inline code", is_not("`\n")), - context("closing code tag", tag("`")), - ) +fn code_inline(input: &str) -> IResult<&str, Inline, MarkdownParseError> { + delimited(tag("`"), is_not("`\n"), tag("`")) .parse(input) - .map(|(rem, inl)| (rem, Inline::Code { content: inl.to_string() })) + .map(|(rem, inl)| { + ( + rem, + Inline::Code { + content: inl.to_string(), + }, + ) + }) } -fn link_inline(input: &str) -> IResult<&str, Inline> { +fn link_inline(input: &str) -> IResult<&str, Inline, MarkdownParseError> { ( - delimited( - context("opening link tag", tag("[")), - context("link name", inline), - context("closing link tag", tag("]")), - ), - delimited( - context("opening href tag", tag("(")), - context("link href", is_not(")\n")), - context("closing href tag", tag(")")), - ) + delimited(tag("["), inline, tag("]")), + delimited(tag("("), is_not(")\n"), tag(")")), ) .parse(input) - .map(|(rem, (name, href))| (rem, Inline::Link { inner: name, href: Href::new(href) })) + .map(|(rem, (name, href))| { + ( + rem, + Inline::Link { + inner: name, + href: Href::new(href), + }, + ) + }) } - //|-------------------------------------------------------------------------------| //| TESTS TESTS TESTS TESTS TESTS TESTS TESTS TESTS TESTS TESTS TESTS TESTS TESTS | //|-------------------------------------------------------------------------------| @@ -254,9 +253,15 @@ mod test { assert_eq!( parsed, vec![ - Inline::Text { content: "take some ".to_string() }, - Inline::Code { content: "code and *bold* and _italics_".to_string() }, - Inline::Text { content: " lmao".to_string() } + Inline::Text { + content: "take some ".to_string() + }, + Inline::Code { + content: "code and *bold* and _italics_".to_string() + }, + Inline::Text { + content: " lmao".to_string() + } ] ); } @@ -273,7 +278,9 @@ mod test { parsed, Inline::Link { inner: vec![ - Inline::Text { content: "this link is ".to_string() }, + Inline::Text { + content: "this link is ".to_string() + }, Inline::Bold { inner: vec![Inline::Text { content: "important".to_string() diff --git a/src/parser/mod.rs b/src/parser/mod.rs index 29867db..1706e49 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs @@ -1,3 +1,32 @@ -pub mod inline; -pub mod block; +use std::fmt::{Debug, Display}; +pub mod block; +pub mod inline; + +#[derive(Debug)] +pub struct MarkdownParseError { + kind: nom::error::ErrorKind, + message: String, +} + +impl Display for MarkdownParseError { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{:?}, {}", self.kind, self.message) + } +} + +impl nom::error::ParseError<&str> for MarkdownParseError { + fn from_error_kind(input: &str, kind: nom::error::ErrorKind) -> Self { + Self { + kind, + message: format!("at: {}", input), + } + } + + fn append(input: &str, kind: nom::error::ErrorKind, other: Self) -> Self { + Self { + kind, + message: format!("{}\nat: {}", other, input), + } + } +} diff --git a/test.html b/test.html new file mode 100644 index 0000000..e69de29 diff --git a/test.md b/test.md new file mode 100644 index 0000000..f34d2e7 --- /dev/null +++ b/test.md @@ -0,0 +1,12 @@ +## This is a testing markdown file + +```rust +fn main() { + println!("Hello world!"); +} +``` + +We'll see if *this* works... + +>A wise man once said... + From 852eddfebf17f78b94ee46b04282b5d256a7fb90 Mon Sep 17 00:00:00 2001 From: Kerdonov Date: Mon, 22 Dec 2025 21:45:28 +0200 Subject: [PATCH 3/4] release action, convert to library crate, bump version to 0.1.0 --- .cargo/config.toml | 2 + .gitea/workflows/cargo-release.yml | 19 +++++ .gitea/workflows/cargo-test.yml | 6 +- Cargo.lock | 125 +---------------------------- Cargo.toml | 4 +- src/generator/block.rs | 4 +- src/generator/inline.rs | 4 +- src/generator/mod.rs | 2 + src/{main.rs => lib.rs} | 9 +-- 9 files changed, 36 insertions(+), 139 deletions(-) create mode 100644 .cargo/config.toml create mode 100644 .gitea/workflows/cargo-release.yml rename src/{main.rs => lib.rs} (62%) diff --git a/.cargo/config.toml b/.cargo/config.toml new file mode 100644 index 0000000..63603d9 --- /dev/null +++ b/.cargo/config.toml @@ -0,0 +1,2 @@ +[registries.gitea] +index = "sparse+https://git.jlux.dev/api/packages/scrac/cargo/" diff --git a/.gitea/workflows/cargo-release.yml b/.gitea/workflows/cargo-release.yml new file mode 100644 index 0000000..e33f4e0 --- /dev/null +++ b/.gitea/workflows/cargo-release.yml @@ -0,0 +1,19 @@ +name: Create release package + +on: + push: + branches: [ "master" ] + +env: + CARGO_TERM_COLOR: always + +jobs: + release: + name: Release + runs-on: rust-latest + + steps: + - run: git clone https://git.jlux.dev/${{ gitea.repository }} . && git checkout ${{ gitea.ref_name }} + - run: cargo build --verbose --release + - run: export CARGO_REGISTRIES_GITEA_TOKEN=${{ secrets.CARGO_BEARER_TOKEN }} + - run: cargo publish --registry gitea diff --git a/.gitea/workflows/cargo-test.yml b/.gitea/workflows/cargo-test.yml index 77ee916..8e3fbe8 100644 --- a/.gitea/workflows/cargo-test.yml +++ b/.gitea/workflows/cargo-test.yml @@ -3,8 +3,8 @@ name: Test the running changes on: push: branches: [ "dev" ] - #pull_request: - # branches: [ "master" ] + pull_request: + branches: [ "master" ] env: CARGO_TERM_COLOR: always @@ -15,8 +15,6 @@ jobs: runs-on: rust-latest steps: - #- run: apt-get update -y - #- uses: actions/checkout@v6 - run: git clone https://git.jlux.dev/${{ gitea.repository }} . && git checkout ${{ gitea.ref_name }} - run: cargo build --verbose - run: cargo clippy -- -D warnings diff --git a/Cargo.lock b/Cargo.lock index f1ea844..33f2ea2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,100 +2,10 @@ # It is not intended for manual editing. version = 4 -[[package]] -name = "anstream" -version = "0.6.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43d5b281e737544384e969a5ccad3f1cdd24b48086a0fc1b2a5262a26b8f4f4a" -dependencies = [ - "anstyle", - "anstyle-parse", - "anstyle-query", - "anstyle-wincon", - "colorchoice", - "is_terminal_polyfill", - "utf8parse", -] - -[[package]] -name = "anstyle" -version = "1.0.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5192cca8006f1fd4f7237516f40fa183bb07f8fbdfedaa0036de5ea9b0b45e78" - -[[package]] -name = "anstyle-parse" -version = "0.2.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e7644824f0aa2c7b9384579234ef10eb7efb6a0deb83f9630a49594dd9c15c2" -dependencies = [ - "utf8parse", -] - -[[package]] -name = "anstyle-query" -version = "1.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40c48f72fd53cd289104fc64099abca73db4166ad86ea0b4341abe65af83dadc" -dependencies = [ - "windows-sys", -] - -[[package]] -name = "anstyle-wincon" -version = "3.0.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291e6a250ff86cd4a820112fb8898808a366d8f9f58ce16d1f538353ad55747d" -dependencies = [ - "anstyle", - "once_cell_polyfill", - "windows-sys", -] - -[[package]] -name = "clap" -version = "4.5.53" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c9e340e012a1bf4935f5282ed1436d1489548e8f72308207ea5df0e23d2d03f8" -dependencies = [ - "clap_builder", -] - -[[package]] -name = "clap_builder" -version = "4.5.53" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d76b5d13eaa18c901fd2f7fca939fefe3a0727a953561fefdf3b2922b8569d00" -dependencies = [ - "anstream", - "anstyle", - "clap_lex", - "strsim", -] - -[[package]] -name = "clap_lex" -version = "0.7.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1d728cc89cf3aee9ff92b05e62b19ee65a02b5702cff7d5a377e32c6ae29d8d" - -[[package]] -name = "colorchoice" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b05b61dc5112cbb17e4b6cd61790d9845d13888356391624cbe7e41efeac1e75" - -[[package]] -name = "is_terminal_polyfill" -version = "1.70.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6cb138bb79a146c1bd460005623e142ef0181e3d0219cb493e02f7d08a35695" - [[package]] name = "marginal" -version = "0.0.1" +version = "0.1.0" dependencies = [ - "clap", "nom", ] @@ -113,36 +23,3 @@ checksum = "df9761775871bdef83bee530e60050f7e54b1105350d6884eb0fb4f46c2f9405" dependencies = [ "memchr", ] - -[[package]] -name = "once_cell_polyfill" -version = "1.70.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe" - -[[package]] -name = "strsim" -version = "0.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" - -[[package]] -name = "utf8parse" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" - -[[package]] -name = "windows-link" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" - -[[package]] -name = "windows-sys" -version = "0.61.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc" -dependencies = [ - "windows-link", -] diff --git a/Cargo.toml b/Cargo.toml index 4ef899d..5ebb963 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,8 +1,8 @@ [package] name = "marginal" -version = "0.0.1" +version = "0.1.0" edition = "2024" +publish = ["gitea"] [dependencies] -clap = "4.5.53" nom = { version = "8.0.0", features = ["std"] } diff --git a/src/generator/block.rs b/src/generator/block.rs index 3febbfc..1b520be 100644 --- a/src/generator/block.rs +++ b/src/generator/block.rs @@ -5,8 +5,8 @@ use super::ToHtml; impl ToHtml for Vec { fn to_html(&self) -> String { let mut html = String::new(); - for block in self.iter() { - html.push_str(&block.to_html()) + for block in self { + html.push_str(&block.to_html()); } html } diff --git a/src/generator/inline.rs b/src/generator/inline.rs index 2038fa2..6d85385 100644 --- a/src/generator/inline.rs +++ b/src/generator/inline.rs @@ -5,8 +5,8 @@ use super::ToHtml; impl ToHtml for Vec { fn to_html(&self) -> String { let mut html = String::new(); - for inline in self.iter() { - html.push_str(&inline.to_html()) + for inline in self { + html.push_str(&inline.to_html()); } html } diff --git a/src/generator/mod.rs b/src/generator/mod.rs index 9237a2b..8760961 100644 --- a/src/generator/mod.rs +++ b/src/generator/mod.rs @@ -44,6 +44,8 @@ pub trait ToHtml { } pub trait TryToHtml { + /// # Errors + /// Could fail when reading file contents is unsuccessful or generation is unsuccessful. fn try_to_html(&self) -> Result; } diff --git a/src/main.rs b/src/lib.rs similarity index 62% rename from src/main.rs rename to src/lib.rs index d306d34..866fc9e 100644 --- a/src/main.rs +++ b/src/lib.rs @@ -1,10 +1,8 @@ -use crate::generator::TryToHtml; -use std::path::PathBuf; - mod ast; -mod generator; -mod parser; +pub mod generator; +pub mod parser; +/* fn main() { let infile = PathBuf::from("test.md"); @@ -12,3 +10,4 @@ fn main() { println!("{}", html); } +*/ From 79e72304bccc044e3903ab10f6d59b29ff780df3 Mon Sep 17 00:00:00 2001 From: Kerdonov Date: Mon, 22 Dec 2025 21:52:04 +0200 Subject: [PATCH 4/4] remove cargo-test workflow on pull request --- .gitea/workflows/cargo-test.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.gitea/workflows/cargo-test.yml b/.gitea/workflows/cargo-test.yml index 8e3fbe8..82fd35b 100644 --- a/.gitea/workflows/cargo-test.yml +++ b/.gitea/workflows/cargo-test.yml @@ -3,8 +3,6 @@ name: Test the running changes on: push: branches: [ "dev" ] - pull_request: - branches: [ "master" ] env: CARGO_TERM_COLOR: always