aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib.rs
diff options
context:
space:
mode:
authorLibravatar Titus Wormer <tituswormer@gmail.com>2022-07-28 16:48:00 +0200
committerLibravatar Titus Wormer <tituswormer@gmail.com>2022-07-28 16:48:00 +0200
commitf7e5fb852dc9c416b9eeb1f0d4f2d51ba5b68456 (patch)
treec1ac3f22473bd79566d835b2474d2ae9e00d6c55 /src/lib.rs
parentd729b07712ca9cc91e68af1776dac9d7008a90cb (diff)
downloadmarkdown-rs-f7e5fb852dc9c416b9eeb1f0d4f2d51ba5b68456.tar.gz
markdown-rs-f7e5fb852dc9c416b9eeb1f0d4f2d51ba5b68456.tar.bz2
markdown-rs-f7e5fb852dc9c416b9eeb1f0d4f2d51ba5b68456.zip
Refactor to work on `char`s
Previously, a custom char implementation was used. This was easier to work with, as sometimes “virtual” characters are injected, or characters are ignored. This replaces that with working on actual `char`s. In the hope of in the future working on `u8`s, even. This simplifies the state machine somewhat, as only `\n` is fed, regardless of whether it was a CRLF, CR, or LF. It also feeds `' '` instead of virtual spaces. The BOM, if present, is now available as a `ByteOrderMark` event.
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs15
1 files changed, 7 insertions, 8 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 4dc15e6..c1b0fa0 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -17,7 +17,6 @@ mod util;
use crate::compiler::compile;
use crate::parser::parse;
-use crate::tokenizer::Code;
/// Type of line endings in markdown.
#[derive(Debug, Default, Clone, PartialEq)]
@@ -61,16 +60,16 @@ impl LineEnding {
LineEnding::LineFeed => "\n",
}
}
- /// Turn a [Code] into a line ending.
+ /// Turn a string into a line ending.
///
/// ## Panics
///
/// Panics if `code` is not `\r\n`, `\r`, or `\n`.
- fn from_code(code: Code) -> LineEnding {
- match code {
- Code::CarriageReturnLineFeed => LineEnding::CarriageReturnLineFeed,
- Code::Char('\r') => LineEnding::CarriageReturn,
- Code::Char('\n') => LineEnding::LineFeed,
+ fn from_str(str: &str) -> LineEnding {
+ match str {
+ "\r\n" => LineEnding::CarriageReturnLineFeed,
+ "\r" => LineEnding::CarriageReturn,
+ "\n" => LineEnding::LineFeed,
_ => unreachable!("invalid code"),
}
}
@@ -425,5 +424,5 @@ pub fn micromark(value: &str) -> String {
#[must_use]
pub fn micromark_with_options(value: &str, options: &Options) -> String {
let (events, result) = parse(value, options);
- compile(&events, &result.codes, options)
+ compile(&events, &result.chars, options)
}