-
-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for Frontmatter #389
Comments
@jlangeveld Which file-extension does such a frontmatter file have? |
The frontmatter is part of a normal pug-file (.pug extension) The 11ty docs explain this much better than I do: |
This is a bug, not a feature request.. |
Please note that I privately work in my free time on this project when I have time and I don't get any money for that! You are also very welcome to read a blogpost written by @antfu https://antfu.me/posts/why-reproductions-are-required |
I realise and respect that, apologies if I implied otherwise.
I suppose you're right
While checking out implementations, I noticed that prettier has builtin support for this for the css and markdown languages. I will attempt implementing it, doesn't look too hard. |
Thank you for your understanding
I also thought about something like this, but hadn't yet the time 🙁 If you open a PR in draft mode, I hope I can help here and there, otherwise I cannot promise but maybe upcoming weekend I have more time. But currently it's a bit stressful for me. |
Actually, that's taken care of by prettier's .../utils/front-matter implementation. All we have to do is hook that up at the beginning and end of the parse function and we have it working basically for free!
Never done that before, but there's a lot of docs, so that won't be a problem. I'll handle that later today or tomorrow.
No problem, I'll prepare some code and testcases and set it up for review |
I hope it's as easy as that, but I hope you will not get afraid when you see how I implemented this plugin and that I don't use the prettier's plugin utilities 👀 |
Your printer class is initialised with content as 1st param, coming from the main plugin. Could I use that to stuff in the parsed front-matter from the parse? |
Uhm, sorry I don't fully understand your question (I'm not english native) |
Uhm... I found this 👀 https://www.npmjs.com/package/front-matter-pug Also for me, it looks like that the frontmatter block at the top is not native pug 🤔 |
Yeah thanks, I know about that one too. It's unmaintained... I have a working implementation, currently fixing testcases and working out json frontmatter. |
Okay... It could work. We have two options I assume: Option 1When passing your example file into the tokenizer we get Tokens[
{"type":"code","loc":{"start":{"line":1,"column":1},"end":{"line":1,"column":4}},"val":"--","mustEscape":false,"buffer":false},
{"type":"newline","loc":{"start":{"line":2,"column":1},"end":{"line":2,"column":1}}},
{"type":"tag","loc":{"start":{"line":2,"column":1},"end":{"line":2,"column":6}},"val":"title"},
{"type":":","loc":{"start":{"line":2,"column":6},"end":{"line":2,"column":8}}},
{"type":"tag","loc":{"start":{"line":2,"column":8},"end":{"line":2,"column":13}},"val":"Hello"},
{"type":"text","loc":{"start":{"line":2,"column":14},"end":{"line":2,"column":19}},"val":"world"},
{"type":"newline","loc":{"start":{"line":3,"column":1},"end":{"line":3,"column":1}}},
{"type":"code","loc":{"start":{"line":3,"column":1},"end":{"line":3,"column":4}},"val":"--","mustEscape":false,"buffer":false},
{"type":"newline","loc":{"start":{"line":4,"column":1},"end":{"line":4,"column":1}}},
// ... vvv real pug starts below vvv
{"type":"doctype","loc":{"start":{"line":4,"column":1},"end":{"line":4,"column":8}},"val":""},
{"type":"newline","loc":{"start":{"line":5,"column":1},"end":{"line":5,"column":1}}},
{"type":"tag","loc":{"start":{"line":5,"column":1},"end":{"line":5,"column":5}},"val":"html"},
{"type":"indent","loc":{"start":{"line":6,"column":1},"end":{"line":6,"column":3}},"val":2},
{"type":"tag","loc":{"start":{"line":6,"column":3},"end":{"line":6,"column":7}},"val":"head"},
{"type":"indent","loc":{"start":{"line":7,"column":1},"end":{"line":7,"column":5}},"val":4},
{"type":"tag","loc":{"start":{"line":7,"column":5},"end":{"line":7,"column":10}},"val":"title"},
{"type":"code","loc":{"start":{"line":7,"column":10},"end":{"line":7,"column":17}},"val":"title","mustEscape":true,"buffer":true},
{"type":"outdent","loc":{"start":{"line":8,"column":1},"end":{"line":8,"column":3}}},
{"type":"tag","loc":{"start":{"line":8,"column":3},"end":{"line":8,"column":7}},"val":"body"},
{"type":"indent","loc":{"start":{"line":9,"column":1},"end":{"line":9,"column":5}},"val":4},
{"type":"tag","loc":{"start":{"line":9,"column":5},"end":{"line":9,"column":7}},"val":"h1"},
{"type":"text","loc":{"start":{"line":9,"column":8},"end":{"line":9,"column":19}},"val":"Hello world"},
{"type":"outdent","loc":{"start":{"line":10,"column":1},"end":{"line":10,"column":1}}},
{"type":"outdent","loc":{"start":{"line":10,"column":1},"end":{"line":10,"column":1}}},
{"type":"eos","loc":{"start":{"line":10,"column":1},"end":{"line":10,"column":1}}}
] When I remove the frontmatter yaml part, and let the document start with the So we could test for Option 2Instead of passing the whole file content into pug's tokenizer, we could test from the start of the file for these |
Feel free to already open a PR in draft state, so I can see your progress 🙂 |
Perhaps it's better if I push my current work and setup that pull-request so you can see what I did... |
Ok, I'll let you know when I'm ready
Op wo 8 jun. 2022 11:20 schreef Shinigami ***@***.***>:
… Your printer class is initialised with content as 1st param, coming from
the main plugin. Could I use that to stuff in the parsed front-matter from
the parse?
Uhm, sorry I don't fully understand your question (I'm not english native)
But try everything you want to support it, I have a really strong and big
test-suite 😜
As long as all current tests are green + your newly added tests are also
green, everything is welcome 🙌
—
Reply to this email directly, view it on GitHub
<#389 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAANO6F4ZE6FQEGBP4EF6M3VOBQXRANCNFSM5X7Y5TDA>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Any update on this feature? |
Plugin Version
v2.1.0
Prettier Version
v2.6.2
Which frameworks are affected?
Node Version
v18.3.0
Which operating systems have you used?
Prettier config
Input
Output or Error
Expected Output
Additional Context
This makes pug templates unusable in frameworks like eleventy, which parse and use the frontmatter keys.
The text was updated successfully, but these errors were encountered: