version 0.1.2 #3
2
Cargo.lock
generated
2
Cargo.lock
generated
@@ -4,7 +4,7 @@ version = 4
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "marginal"
|
name = "marginal"
|
||||||
version = "0.1.0"
|
version = "0.1.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"nom",
|
"nom",
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "marginal"
|
name = "marginal"
|
||||||
version = "0.1.0"
|
version = "0.1.1"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
publish = ["gitea"]
|
publish = ["gitea"]
|
||||||
|
|
||||||
|
|||||||
@@ -66,6 +66,7 @@ command = [
|
|||||||
"cargo", "nextest", "run",
|
"cargo", "nextest", "run",
|
||||||
"--hide-progress-bar",
|
"--hide-progress-bar",
|
||||||
"--failure-output", "final",
|
"--failure-output", "final",
|
||||||
|
"--no-fail-fast",
|
||||||
]
|
]
|
||||||
need_stdout = true
|
need_stdout = true
|
||||||
analyzer = "nextest"
|
analyzer = "nextest"
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ use nom::{
|
|||||||
IResult, Parser,
|
IResult, Parser,
|
||||||
branch::alt,
|
branch::alt,
|
||||||
bytes::complete::{tag, take_until},
|
bytes::complete::{tag, take_until},
|
||||||
|
combinator::peek,
|
||||||
multi::{many_m_n, many0, many1},
|
multi::{many_m_n, many0, many1},
|
||||||
sequence::{delimited, terminated},
|
sequence::{delimited, terminated},
|
||||||
};
|
};
|
||||||
@@ -14,6 +15,7 @@ pub fn blocks(input: &str) -> IResult<&str, Vec<Block>, MarkdownParseError> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn block(input: &str) -> IResult<&str, Block, MarkdownParseError> {
|
pub fn block(input: &str) -> IResult<&str, Block, MarkdownParseError> {
|
||||||
|
//alt((heading_block, code_block, quote_block, paragraph_block)).parse(input)
|
||||||
terminated(
|
terminated(
|
||||||
alt((heading_block, code_block, quote_block, paragraph_block)),
|
alt((heading_block, code_block, quote_block, paragraph_block)),
|
||||||
tag("\n"),
|
tag("\n"),
|
||||||
@@ -45,7 +47,7 @@ fn code_block(input: &str) -> IResult<&str, Block, MarkdownParseError> {
|
|||||||
delimited(
|
delimited(
|
||||||
tag("```"),
|
tag("```"),
|
||||||
(take_until("\n"), tag("\n"), take_until("```\n")),
|
(take_until("\n"), tag("\n"), take_until("```\n")),
|
||||||
tag("```\n"),
|
(tag("```"), peek(tag("\n"))),
|
||||||
)
|
)
|
||||||
.parse(input)
|
.parse(input)
|
||||||
.map(|(rem, (lang, _, code))| {
|
.map(|(rem, (lang, _, code))| {
|
||||||
@@ -83,10 +85,10 @@ mod test {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn single_paragraph() {
|
fn single_paragraph() {
|
||||||
let md = "Hello markdown!!";
|
let md = "Hello markdown!!\n";
|
||||||
let (rem, block) = paragraph_block(md).unwrap();
|
let (rem, block) = paragraph_block(md).unwrap();
|
||||||
|
|
||||||
assert_eq!(rem, "");
|
assert_eq!(rem, "\n");
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
block,
|
block,
|
||||||
Block::Paragraph {
|
Block::Paragraph {
|
||||||
@@ -107,7 +109,7 @@ fn main() {
|
|||||||
";
|
";
|
||||||
let (rem, block) = code_block(md).unwrap();
|
let (rem, block) = code_block(md).unwrap();
|
||||||
|
|
||||||
assert_eq!(rem, "");
|
assert_eq!(rem, "\n");
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
block,
|
block,
|
||||||
Block::Code {
|
Block::Code {
|
||||||
@@ -125,7 +127,7 @@ echo \"hello world\"
|
|||||||
";
|
";
|
||||||
let (rem, block) = code_block(md).unwrap();
|
let (rem, block) = code_block(md).unwrap();
|
||||||
|
|
||||||
assert_eq!(rem, "");
|
assert_eq!(rem, "\n");
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
block,
|
block,
|
||||||
Block::Code {
|
Block::Code {
|
||||||
@@ -145,11 +147,11 @@ echo hello
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn level_1_heading() {
|
fn level_2_heading() {
|
||||||
let md = "## Heading2";
|
let md = "## Heading2\n";
|
||||||
let (rem, block) = heading_block(md).unwrap();
|
let (rem, block) = heading_block(md).unwrap();
|
||||||
|
|
||||||
assert_eq!(rem, "");
|
assert_eq!(rem, "\n");
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
block,
|
block,
|
||||||
Block::Heading {
|
Block::Heading {
|
||||||
@@ -163,16 +165,16 @@ echo hello
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn heading_no_space() {
|
fn heading_no_space() {
|
||||||
let md = "#heading";
|
let md = "#heading\n";
|
||||||
assert!(heading_block(md).is_err());
|
assert!(heading_block(md).is_err());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn level_6_heading() {
|
fn level_6_heading() {
|
||||||
let md = "###### Heading6";
|
let md = "###### Heading6\n";
|
||||||
let (rem, block) = heading_block(md).unwrap();
|
let (rem, block) = heading_block(md).unwrap();
|
||||||
|
|
||||||
assert_eq!(rem, "");
|
assert_eq!(rem, "\n");
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
block,
|
block,
|
||||||
Block::Heading {
|
Block::Heading {
|
||||||
@@ -186,7 +188,7 @@ echo hello
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn no_level_7_heading() {
|
fn no_level_7_heading() {
|
||||||
let md = "####### Heading7";
|
let md = "####### Heading7\n";
|
||||||
assert!(heading_block(md).is_err());
|
assert!(heading_block(md).is_err());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -85,10 +85,10 @@ mod test {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn single_text() {
|
fn single_text() {
|
||||||
let md = "hello normal inline";
|
let md = "hello normal inline\n";
|
||||||
let (rem, parsed) = text_inline(md).unwrap();
|
let (rem, parsed) = text_inline(md).unwrap();
|
||||||
|
|
||||||
assert_eq!(rem, "");
|
assert_eq!(rem, "\n");
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
parsed,
|
parsed,
|
||||||
Inline::Text {
|
Inline::Text {
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
|
//! A weird markdown parser. Please don't forget to add a newline in the end of a file or it won't
|
||||||
|
//! work :)
|
||||||
|
|
||||||
use std::fmt::{Debug, Display};
|
use std::fmt::{Debug, Display};
|
||||||
|
|
||||||
pub mod block;
|
pub mod block;
|
||||||
|
|||||||
Reference in New Issue
Block a user