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..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 @@ -15,8 +13,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 29c8ac6..33f2ea2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5,3 +5,21 @@ version = 4 [[package]] name = "marginal" version = "0.1.0" +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..5ebb963 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,8 @@ [package] name = "marginal" -version = "0.0.1" +version = "0.1.0" edition = "2024" +publish = ["gitea"] [dependencies] +nom = { version = "8.0.0", features = ["std"] } 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..3474045 --- /dev/null +++ b/src/ast.rs @@ -0,0 +1,34 @@ +use std::fmt::Display; + +#[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()) + } +} + +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 { inner: Vec, level: u8 }, + Code { content: String, lang: String }, + Quote { inner: Box }, + Paragraph { inner: Vec }, +} diff --git a/src/generator/block.rs b/src/generator/block.rs new file mode 100644 index 0000000..1b520be --- /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 { + 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..6d85385 --- /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 { + 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..8760961 --- /dev/null +++ b/src/generator/mod.rs @@ -0,0 +1,58 @@ +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 { + /// # Errors + /// Could fail when reading file contents is unsuccessful or generation is unsuccessful. + fn try_to_html(&self) -> Result; +} + +/* +impl TryToHtml for T { + fn try_to_html(&self) -> Result> { + Ok::>>(self.to_html()) + } +} +*/ diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..866fc9e --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,13 @@ +mod ast; +pub mod generator; +pub mod parser; + +/* +fn main() { + let infile = PathBuf::from("test.md"); + + let html = infile.try_to_html().unwrap(); + + println!("{}", html); +} +*/ diff --git a/src/main.rs b/src/main.rs deleted file mode 100644 index 40e393c..0000000 --- a/src/main.rs +++ /dev/null @@ -1,6 +0,0 @@ - -mod ast; - -fn main() { - -} diff --git a/src/parser/block.rs b/src/parser/block.rs new file mode 100644 index 0000000..f1f96ad --- /dev/null +++ b/src/parser/block.rs @@ -0,0 +1,236 @@ +use crate::{ast::Block, parser::inline::inline}; +use nom::{ + IResult, Parser, + branch::alt, + bytes::complete::{tag, take_until}, + multi::{many_m_n, many0, many1}, + sequence::{delimited, terminated}, +}; + +use super::MarkdownParseError; + +pub fn blocks(input: &str) -> IResult<&str, Vec, MarkdownParseError> { + many0(block).parse(input) +} + +pub fn block(input: &str) -> IResult<&str, Block, MarkdownParseError> { + terminated( + alt((heading_block, code_block, quote_block, paragraph_block)), + tag("\n"), + ) + .parse(input) +} + +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, MarkdownParseError> { + (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, MarkdownParseError> { + 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, MarkdownParseError> { + (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..1c4941f --- /dev/null +++ b/src/parser/inline.rs @@ -0,0 +1,294 @@ +use nom::IResult; +use nom::{ + Parser, + branch::alt, + bytes::complete::{is_not, tag}, + multi::many0, + sequence::delimited, +}; + +use crate::ast::{Href, Inline}; + +use super::MarkdownParseError; + +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, MarkdownParseError> { + is_not("*_`[]\n").parse(input).map(|(rem, con)| { + ( + rem, + Inline::Text { + content: con.to_string(), + }, + ) + }) +} + +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, MarkdownParseError> { + delimited(tag("_"), inline, tag("_")) + .parse(input) + .map(|(rem, inl)| (rem, Inline::Italic { inner: inl })) +} + +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(), + }, + ) + }) +} + +fn link_inline(input: &str) -> IResult<&str, Inline, MarkdownParseError> { + ( + 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), + }, + ) + }) +} + +//|-------------------------------------------------------------------------------| +//| 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..1706e49 --- /dev/null +++ b/src/parser/mod.rs @@ -0,0 +1,32 @@ +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... +