Revert "feat(embedded): Add prefix-char frontmatter syntax support"

This reverts commit b77ce7fa292622c5482047ee428c1ead1f4c3643.
This commit is contained in:
Ed Page 2024-05-04 22:44:28 +02:00
parent cf7b3c4cf3
commit 5c3bc8d0e1

View File

@ -185,7 +185,7 @@ fn sanitize_name(name: &str) -> String {
struct Source<'s> {
shebang: Option<&'s str>,
info: Option<&'s str>,
frontmatter: Option<String>,
frontmatter: Option<&'s str>,
content: &'s str,
}
@ -234,14 +234,11 @@ fn split_source(input: &str) -> CargoResult<Source<'_>> {
0 => {
return Ok(source);
}
1 if tick_char == '#' => {
// Attribute
return Ok(source);
}
2 if tick_char == '#' => {
return split_prefix_source(source, "##");
}
1 | 2 => {
if tick_char == '#' {
// Attribute
return Ok(source);
}
anyhow::bail!("found {tick_end} `{tick_char}` in rust frontmatter, expected at least 3")
}
_ => source.content.split_at(tick_end),
@ -255,7 +252,7 @@ fn split_source(input: &str) -> CargoResult<Source<'_>> {
let Some((frontmatter, content)) = source.content.split_once(fence_pattern) else {
anyhow::bail!("no closing `{fence_pattern}` found for frontmatter");
};
source.frontmatter = Some(frontmatter.to_owned());
source.frontmatter = Some(frontmatter);
source.content = content;
let (line, content) = source
@ -271,22 +268,6 @@ fn split_source(input: &str) -> CargoResult<Source<'_>> {
Ok(source)
}
fn split_prefix_source<'s>(mut source: Source<'s>, prefix: &str) -> CargoResult<Source<'s>> {
let mut frontmatter = String::new();
while let Some(rest) = source.content.strip_prefix(prefix) {
if !rest.is_empty() && !rest.starts_with(' ') {
anyhow::bail!("frontmatter must have a space between `##` and the content");
}
let (line, rest) = rest.split_once('\n').unwrap_or((rest, ""));
frontmatter.push_str(" ");
frontmatter.push_str(line);
frontmatter.push('\n');
source.content = rest;
}
source.frontmatter = Some(frontmatter);
Ok(source)
}
#[cfg(test)]
mod test_expand {
use super::*;
@ -394,7 +375,7 @@ fn main() {}
}
#[test]
fn test_dash_fence() {
fn test_dash() {
snapbox::assert_matches(
r#"[[bin]]
name = "test-"
@ -427,7 +408,7 @@ fn main() {}
}
#[test]
fn test_hash_fence() {
fn test_hash() {
snapbox::assert_matches(
r#"[[bin]]
name = "test-"
@ -455,37 +436,6 @@ strip = true
time="0.1.25"
###
fn main() {}
"#),
);
}
#[test]
fn test_hash_prefix() {
snapbox::assert_matches(
r#"[[bin]]
name = "test-"
path = [..]
[dependencies]
time = "0.1.25"
[package]
autobenches = false
autobins = false
autoexamples = false
autotests = false
build = false
edition = "2021"
name = "test-"
[profile.release]
strip = true
[workspace]
"#,
si!(r#"## [dependencies]
## time="0.1.25"
fn main() {}
"#),
);
}