@@ -185,7 +185,7 @@ fn sanitize_name(name: &str) -> String {
185185struct Source < ' s > {
186186 shebang : Option < & ' s str > ,
187187 info : Option < & ' s str > ,
188- frontmatter : Option < String > ,
188+ frontmatter : Option < & ' s str > ,
189189 content : & ' s str ,
190190}
191191
@@ -218,12 +218,7 @@ fn split_source(input: &str) -> CargoResult<Source<'_>> {
218218 }
219219
220220 // Experiment: let us try which char works better
221- let tick_char = source
222- . content
223- . chars ( )
224- . filter ( |c| [ '`' , '#' , '-' ] . contains ( c) )
225- . next ( )
226- . unwrap_or ( '`' ) ;
221+ let tick_char = '-' ;
227222
228223 let tick_end = source
229224 . content
@@ -234,13 +229,6 @@ fn split_source(input: &str) -> CargoResult<Source<'_>> {
234229 0 => {
235230 return Ok ( source) ;
236231 }
237- 1 if tick_char == '#' => {
238- // Attribute
239- return Ok ( source) ;
240- }
241- 2 if tick_char == '#' => {
242- return split_prefix_source ( source, "##" ) ;
243- }
244232 1 | 2 => {
245233 anyhow:: bail!( "found {tick_end} `{tick_char}` in rust frontmatter, expected at least 3" )
246234 }
@@ -255,7 +243,7 @@ fn split_source(input: &str) -> CargoResult<Source<'_>> {
255243 let Some ( ( frontmatter, content) ) = source. content . split_once ( fence_pattern) else {
256244 anyhow:: bail!( "no closing `{fence_pattern}` found for frontmatter" ) ;
257245 } ;
258- source. frontmatter = Some ( frontmatter. to_owned ( ) ) ;
246+ source. frontmatter = Some ( frontmatter) ;
259247 source. content = content;
260248
261249 let ( line, content) = source
@@ -271,22 +259,6 @@ fn split_source(input: &str) -> CargoResult<Source<'_>> {
271259 Ok ( source)
272260}
273261
274- fn split_prefix_source < ' s > ( mut source : Source < ' s > , prefix : & str ) -> CargoResult < Source < ' s > > {
275- let mut frontmatter = String :: new ( ) ;
276- while let Some ( rest) = source. content . strip_prefix ( prefix) {
277- if !rest. is_empty ( ) && !rest. starts_with ( ' ' ) {
278- anyhow:: bail!( "frontmatter must have a space between `##` and the content" ) ;
279- }
280- let ( line, rest) = rest. split_once ( '\n' ) . unwrap_or ( ( rest, "" ) ) ;
281- frontmatter. push_str ( " " ) ;
282- frontmatter. push_str ( line) ;
283- frontmatter. push ( '\n' ) ;
284- source. content = rest;
285- }
286- source. frontmatter = Some ( frontmatter) ;
287- Ok ( source)
288- }
289-
290262#[ cfg( test) ]
291263mod test_expand {
292264 use super :: * ;
@@ -351,10 +323,10 @@ strip = true
351323
352324[workspace]
353325"# ,
354- si ! ( r#"``` cargo
326+ si ! ( r#"--- cargo
355327[dependencies]
356328time="0.1.25"
357- ```
329+ ---
358330fn main() {}
359331"# ) ,
360332 ) ;
@@ -382,110 +354,13 @@ name = "test-"
382354[profile.release]
383355strip = true
384356
385- [workspace]
386- "# ,
387- si ! ( r#"```
388- [dependencies]
389- time="0.1.25"
390- ```
391- fn main() {}
392- "# ) ,
393- ) ;
394- }
395-
396- #[ test]
397- fn test_dash_fence ( ) {
398- snapbox:: assert_matches (
399- r#"[[bin]]
400- name = "test-"
401- path = [..]
402-
403- [dependencies]
404- time = "0.1.25"
405-
406- [package]
407- autobenches = false
408- autobins = false
409- autoexamples = false
410- autotests = false
411- build = false
412- edition = "2021"
413- name = "test-"
414-
415- [profile.release]
416- strip = true
417-
418357[workspace]
419358"# ,
420359 si ! ( r#"---
421360[dependencies]
422361time="0.1.25"
423362---
424363fn main() {}
425- "# ) ,
426- ) ;
427- }
428-
429- #[ test]
430- fn test_hash_fence ( ) {
431- snapbox:: assert_matches (
432- r#"[[bin]]
433- name = "test-"
434- path = [..]
435-
436- [dependencies]
437- time = "0.1.25"
438-
439- [package]
440- autobenches = false
441- autobins = false
442- autoexamples = false
443- autotests = false
444- build = false
445- edition = "2021"
446- name = "test-"
447-
448- [profile.release]
449- strip = true
450-
451- [workspace]
452- "# ,
453- si ! ( r#"###
454- [dependencies]
455- time="0.1.25"
456- ###
457- fn main() {}
458- "# ) ,
459- ) ;
460- }
461-
462- #[ test]
463- fn test_hash_prefix ( ) {
464- snapbox:: assert_matches (
465- r#"[[bin]]
466- name = "test-"
467- path = [..]
468-
469- [dependencies]
470- time = "0.1.25"
471-
472- [package]
473- autobenches = false
474- autobins = false
475- autoexamples = false
476- autotests = false
477- build = false
478- edition = "2021"
479- name = "test-"
480-
481- [profile.release]
482- strip = true
483-
484- [workspace]
485- "# ,
486- si ! ( r#"## [dependencies]
487- ## time="0.1.25"
488- fn main() {}
489364"# ) ,
490365 ) ;
491366 }
0 commit comments