|
1 | | -// import matter = require('gray-matter'); |
2 | 1 | import type { BuiltInParserName, Options, RequiredOptions } from 'prettier'; |
3 | 2 | import { format } from 'prettier'; |
4 | 3 | import type PrettierAngularPlugin from 'prettier/plugins/angular'; |
@@ -391,10 +390,11 @@ export class PugPrinter { |
391 | 390 |
|
392 | 391 | token = this.getNextToken(); |
393 | 392 | } |
394 | | - console.log(this.frontmatter); |
395 | | - //return matter.stringify(results.join(''), this.frontmatter.raw); |
396 | | - console.log(this.frontmatter); |
397 | | - return this.frontmatter.raw + results.join(''); |
| 393 | + |
| 394 | + const fm = await this.frontmatterFormat(this.frontmatter.value); |
| 395 | + const formattedFrontmatter = this.frontmatter ? '---\n' + fm + '---\n' : ''; |
| 396 | + |
| 397 | + return formattedFrontmatter + results.join(''); |
398 | 398 | } |
399 | 399 |
|
400 | 400 | private getNextToken(): Token | null { |
@@ -482,6 +482,15 @@ export class PugPrinter { |
482 | 482 | } |
483 | 483 | } |
484 | 484 |
|
| 485 | + private async frontmatterFormat(frontmatter: string): Promise<string> { |
| 486 | + const options = { |
| 487 | + parser: 'yaml', |
| 488 | + collectionStyle: 'block', |
| 489 | + }; |
| 490 | + |
| 491 | + return format(frontmatter, options); |
| 492 | + } |
| 493 | + |
485 | 494 | private async frameworkFormat(code: string): Promise<string> { |
486 | 495 | const options: Options = { |
487 | 496 | ...this.codeInterpolationOptions, |
|
0 commit comments