-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: newline/blankline was sometimes missing after yaml header (#119)
- Loading branch information
Showing
9 changed files
with
124 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
use crate::generation::common::CharScanner; | ||
|
||
pub fn strip_metadata_header(text: &str) -> &str { | ||
// todo(dsherret): use pulldown_cmark to parse this | ||
let mut scanner = CharScanner::new(0, text); | ||
|
||
let delimiter = if scanner.is_next_text("---") { | ||
scanner.move_text("---"); | ||
"---" | ||
} else if scanner.is_next_text("+++") { | ||
scanner.move_text("+++"); | ||
"+++" | ||
} else { | ||
return text; | ||
}; | ||
|
||
if !scanner.move_new_line() { | ||
return text; | ||
} | ||
|
||
while scanner.has_next() { | ||
if scanner.is_next_text(&delimiter) { | ||
scanner.move_text(&delimiter); | ||
if scanner.move_new_line() || scanner.pos() == scanner.end() { | ||
let range = std::ops::Range { | ||
start: 0, | ||
end: scanner.pos(), | ||
}; | ||
return &text[range.end..]; | ||
} | ||
} | ||
|
||
scanner.move_next_line(); | ||
} | ||
|
||
text | ||
} | ||
|
||
#[cfg(test)] | ||
mod test { | ||
use super::*; | ||
#[test] | ||
fn it_should_strip_yaml_header() { | ||
let result = strip_metadata_header( | ||
r#"--- | ||
a: b | ||
--- | ||
Test"#, | ||
); | ||
|
||
assert_eq!(result, "\n\nTest"); | ||
} | ||
|
||
#[test] | ||
fn it_should_strip_plus_plus_plus_header() { | ||
let result = strip_metadata_header( | ||
r#"+++ | ||
a: b | ||
+++ | ||
Test"#, | ||
); | ||
|
||
assert_eq!(result, "\n\nTest"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
~~ deno: true ~~ | ||
!! should format !! | ||
--- | ||
title: Testing | ||
--- | ||
|
||
<blockquote class="md-pullquote" style="border: 0"> | ||
|
||
Everything should be made as simple as possible, but not simpler. | ||
|
||
[expect] | ||
--- | ||
title: Testing | ||
--- | ||
|
||
<blockquote class="md-pullquote" style="border: 0"> | ||
|
||
Everything should be made as simple as possible, but not simpler. |