@@ -185,7 +185,7 @@ fn sanitize_name(name: &str) -> String {
185
185
struct Source < ' s > {
186
186
shebang : Option < & ' s str > ,
187
187
info : Option < & ' s str > ,
188
- frontmatter : Option < String > ,
188
+ frontmatter : Option < & ' s str > ,
189
189
content : & ' s str ,
190
190
}
191
191
@@ -218,12 +218,7 @@ fn split_source(input: &str) -> CargoResult<Source<'_>> {
218
218
}
219
219
220
220
// 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 = '-' ;
227
222
228
223
let tick_end = source
229
224
. content
@@ -234,13 +229,6 @@ fn split_source(input: &str) -> CargoResult<Source<'_>> {
234
229
0 => {
235
230
return Ok ( source) ;
236
231
}
237
- 1 if tick_char == '#' => {
238
- // Attribute
239
- return Ok ( source) ;
240
- }
241
- 2 if tick_char == '#' => {
242
- return split_prefix_source ( source, "##" ) ;
243
- }
244
232
1 | 2 => {
245
233
anyhow:: bail!( "found {tick_end} `{tick_char}` in rust frontmatter, expected at least 3" )
246
234
}
@@ -255,7 +243,7 @@ fn split_source(input: &str) -> CargoResult<Source<'_>> {
255
243
let Some ( ( frontmatter, content) ) = source. content . split_once ( fence_pattern) else {
256
244
anyhow:: bail!( "no closing `{fence_pattern}` found for frontmatter" ) ;
257
245
} ;
258
- source. frontmatter = Some ( frontmatter. to_owned ( ) ) ;
246
+ source. frontmatter = Some ( frontmatter) ;
259
247
source. content = content;
260
248
261
249
let ( line, content) = source
@@ -271,22 +259,6 @@ fn split_source(input: &str) -> CargoResult<Source<'_>> {
271
259
Ok ( source)
272
260
}
273
261
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
-
290
262
#[ cfg( test) ]
291
263
mod test_expand {
292
264
use super :: * ;
@@ -351,10 +323,10 @@ strip = true
351
323
352
324
[workspace]
353
325
"# ,
354
- si ! ( r#"``` cargo
326
+ si ! ( r#"--- cargo
355
327
[dependencies]
356
328
time="0.1.25"
357
- ```
329
+ ---
358
330
fn main() {}
359
331
"# ) ,
360
332
) ;
@@ -382,110 +354,13 @@ name = "test-"
382
354
[profile.release]
383
355
strip = true
384
356
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
-
418
357
[workspace]
419
358
"# ,
420
359
si ! ( r#"---
421
360
[dependencies]
422
361
time="0.1.25"
423
362
---
424
363
fn 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() {}
489
364
"# ) ,
490
365
) ;
491
366
}
0 commit comments