Skip to content

Conversation

@taniki
Copy link

@taniki taniki commented Jan 14, 2026

  • follow-up of Add support for frontmatter #390
  • rebase to catch-up with current HEAD
  • copy frontmatter parsing and printing from prettier source code
  • ⚠️ it works but doesn't pass the test because of formatting the frontmatter code. Currently digging into that.

Inspiration: https://github.com/LukeHagar/prettier-plugin-openapi/tree/b1a2f010724eb0b29d0e02ed56b3e493b4ec1438/src/prettier-markdown

@Shinigami92 Shinigami92 added the type: feature request Functionality that introduces a new feature label Jan 14, 2026
@@ -0,0 +1,19 @@
// import * as assert from "#universal/assert";
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no idea how to put it back

@taniki
Copy link
Author

taniki commented Jan 14, 2026

@Shinigami92 I am trying to use https://github.com/inogai/prettier/tree/main/src/language-markdown as a reference but the structure seems a bit different from yours.

@Shinigami92
Copy link
Member

@Shinigami92 I am trying to use inogai/prettier@main/src/language-markdown as a reference but the structure seems a bit different from yours.

Yeah, many plugins are fully driven by their own owners like myself. It is fully up to us maintainers how to run our plugins, but we can ship the plugin as officially under the @prettier org / npm-scope as a sign of trust.

@taniki
Copy link
Author

taniki commented Jan 14, 2026

frontmatter support in markdown, css, and html seems to be done through support of embeds:


const printer = {
  preprocess,
  print: genericPrint,
  embed,
  massageAstNode: clean,
  hasPrettierIgnore,
  insertPragma,
  getVisitorKeys,
};

export default printer;

but I can't find such mecanism in yours. should insert something like inserting a case in the switch section?

@Shinigami92
Copy link
Member

frontmatter support in markdown, css, and html seems to be done through support of embeds:


const printer = {
  preprocess,
  print: genericPrint,
  embed,
  massageAstNode: clean,
  hasPrettierIgnore,
  insertPragma,
  getVisitorKeys,
};

export default printer;

but I can't find such mecanism in yours. should insert something like inserting a case in the switch section?

Yeah... that might be a huge problem, because I implemented plugin-pug when a lot of such things where not available or stable, and then also as pug is a "language" which is very easily written from left to write, top to bottom, it was far more easy to just process the token stream as an array / iterator.

You could have a look how embedded js or css is formatted right now as well as some expressions like embedded vue or angular syntax.
From that you might get a picture of how to achieve similar thing for frontmatter.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (blocking): CLI is telling that these files are not TypeScript files, but JavaScript. You need to use TypeScript.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That will be too much for me right now. Thanks for the support.

private async frontmatterFormat(frontmatter: string): Promise<string> {
const options: Options = {
parser: 'yaml',
collectionStyle: 'block',
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should enforce formatting of flow style array and dict but it doesn't and I don't know why.

@taniki taniki force-pushed the Add_Support_for_Frontmatter branch from 4e259e7 to 21bef49 Compare January 14, 2026 21:59
@taniki
Copy link
Author

taniki commented Jan 14, 2026

I am hitting a wall here.

  • I have no clue about how to efficiently convert the imported javascript code into typescript.
  • the build-in yaml formatter doesn't seem to acknowledge the formatting option enforcing block-style list and dictionaries.
  • there are some lint errors beyond my understanding.

All the bricks are in place tho. If someone to take it up from there, it will be great.

@taniki taniki force-pushed the Add_Support_for_Frontmatter branch from 4248b65 to 824ae96 Compare January 14, 2026 22:10
@taniki taniki force-pushed the Add_Support_for_Frontmatter branch from 824ae96 to 2d61827 Compare January 14, 2026 22:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: feature request Functionality that introduces a new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants