Skip to content

Commit 7967301

Browse files
authored
fix: code blocks (#24)
1 parent be7117a commit 7967301

6 files changed

+44
-14
lines changed

Cargo.lock

+37-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ edition = "2021"
77
chumsky = "0.9.3"
88
itertools = "0.13.0"
99
serde = { version = "1.0.203", features = ["derive"] }
10+
textwrap = "0.16.1"
1011
unicode_categories = "0.1.1"
1112

1213
[dev-dependencies]

src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use chumsky::Parser as _;
22
use error::NorgParseError;
33

44
pub use crate::stage_1::stage_1;
5-
use crate::stage_2::stage_2;
5+
pub use crate::stage_2::stage_2;
66
use crate::stage_4::stage_4;
77

88
pub use crate::stage_2::ParagraphSegmentToken;

src/snapshots/rust_norg__tests__ranged_verbatim_tags.snap

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ expression: examples
2323
- first-parameter
2424
- "#&*(&$!)"
2525
- third-parameter
26-
content: "function hello()\nprint(\"Hello World\")\nend hello()\n"
26+
content: "function hello()\n print(\"Hello World\")\nend\n\nhello()\n"

src/stage_1.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ impl std::fmt::Display for NorgToken {
2929
Self::End(c) => write!(f, "{}end", c),
3030
Self::Eof => f.write_char('\0'),
3131
Self::Escape(c) => write!(f, "\\{}", c),
32-
Self::Newlines(count) => f.write_str(&" ".repeat(*count as usize)),
32+
Self::Newlines(count) => f.write_str(&"\n".repeat(*count as usize)),
3333
Self::Regular(c) | Self::Special(c) => f.write_char(*c),
3434
Self::SingleNewline => f.write_char('\n'),
3535
Self::Whitespace(count) => f.write_str(&" ".repeat(*count as usize)),
@@ -61,13 +61,11 @@ pub fn stage_1() -> impl Parser<char, Vec<NorgToken>, Error = chumsky::error::Si
6161
});
6262

6363
let newline = parse_newline
64-
.then_ignore(ws.repeated())
6564
.to(NorgToken::SingleNewline);
6665

6766
let newlines = parse_newline
6867
.repeated()
6968
.at_least(2)
70-
.then_ignore(ws.repeated())
7169
.map(|content| NorgToken::Newlines(content.len() as u16));
7270

7371
let special = one_of(SPECIAL_CHARS).map(NorgToken::Special);

src/stage_3.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use std::fmt::Write;
33
use chumsky::prelude::*;
44
use itertools::Itertools;
55
use serde::Serialize;
6+
use textwrap::dedent;
67

78
use crate::stage_2::{NorgBlock, ParagraphSegmentToken, ParagraphTokenList};
89

@@ -141,7 +142,7 @@ fn paragraph_parser_opener_candidates_and_links() -> impl Parser<
141142
.at_least(1),
142143
)
143144
.then_ignore(just(ParagraphSegmentToken::Special('`')))
144-
.map(|content| ParagraphSegment::InlineVerbatim(content));
145+
.map(ParagraphSegment::InlineVerbatim);
145146

146147
let anchor = just(ParagraphSegmentToken::Special('['))
147148
.ignore_then(
@@ -717,7 +718,7 @@ pub fn stage_3(
717718
NorgASTFlat::VerbatimRangedTag {
718719
name: stringify_tokens_and_split(name),
719720
parameters: parameters.unwrap_or_default().into_iter().map(|parameter| parameter.into_iter().map_into::<String>().collect()).collect(),
720-
content: content.into_iter().map_into::<String>().collect(),
721+
content: dedent(content.into_iter().map_into::<String>().collect::<String>().as_str()),
721722
}
722723
},
723724
};

0 commit comments

Comments
 (0)