File tree Expand file tree Collapse file tree 2 files changed +17
-9
lines changed
Expand file tree Collapse file tree 2 files changed +17
-9
lines changed Original file line number Diff line number Diff line change @@ -15,13 +15,13 @@ import { options as pugOptions } from './options';
1515import { convergeOptions } from './options/converge' ;
1616import type { PugPrinterOptions } from './printer' ;
1717import { PugPrinter } from './printer' ;
18- import parse from './utils/frontmatter/parse' ;
18+ import { default as parseFrontmatter } from './utils/frontmatter/parse' ;
1919
2020/** Ast path stack entry. */
2121interface AstPathStackEntry {
2222 content : string ;
2323 tokens : Token [ ] ;
24- frontmatter : Frontmatter < string > ;
24+ frontmatter : string ;
2525}
2626
2727/** The plugin object that is picked up by prettier. */
@@ -45,8 +45,10 @@ export const plugin: Plugin<AstPathStackEntry> = {
4545 parse ( text , options ) {
4646 logger . debug ( '[parsers:pug:parse]:' , { text } ) ;
4747
48- const parts = parse ( text ) ;
49- const frontmatter = parts . frontMatter ;
48+ const parts : FrontMatter = parseFrontmatter ( text ) ;
49+ const frontmatter : string = parts . frontMatter
50+ ? parts . frontMatter . value
51+ : undefined ;
5052 text = parts . content ;
5153
5254 let trimmedAndAlignedContent : string = text . replace ( / ^ \s * \n / , '' ) ;
Original file line number Diff line number Diff line change @@ -236,12 +236,13 @@ export class PugPrinter {
236236 * @param content The pug content string.
237237 * @param tokens The pug token array.
238238 * @param options Options for the printer.
239+ * @param frontmatter The extracted frontmatter part.
239240 */
240241 public constructor (
241242 private readonly content : string ,
242243 private tokens : Token [ ] ,
243244 private readonly options : PugPrinterOptions ,
244- private readonly frontmatter : Frontmatter < string > ,
245+ private readonly frontmatter : string ,
245246 ) {
246247 this . frontmatter = frontmatter ;
247248 this . indentString = options . pugUseTabs
@@ -392,10 +393,15 @@ export class PugPrinter {
392393 }
393394
394395 if ( this . frontmatter ) {
395- const frontmatter : string = await this . frontmatterFormat (
396- this . frontmatter . value ,
397- ) ;
398- results . unshift ( '---\n' , frontmatter , '---\n' ) ;
396+ try {
397+ results . unshift (
398+ '---\n' ,
399+ await this . frontmatterFormat ( this . frontmatter ) ,
400+ '---\n' ,
401+ ) ;
402+ } catch ( error : any ) {
403+ logger . warn ( error ) ;
404+ }
399405 }
400406
401407 return results . join ( '' ) ;
You can’t perform that action at this time.
0 commit comments