Skip to content

Commit

Permalink
Add basic prettier support for doc tag
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesmengo committed Dec 5, 2024
1 parent 79f4c94 commit a218331
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 0 deletions.
13 changes: 13 additions & 0 deletions packages/prettier-plugin-liquid/src/printer/printer-liquid-html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,15 @@ function printNode(
? join(hardline, reindent(lines, shouldSkipFirstLine))
: softline;

if (parentNode && parentNode.name === 'doc') {
// here we know that we are in a liquidDocNode
// Is it better to implement this here or in LiquidRawTag?
// One of the benefits of leaving it here is that we can use the indentation and other logic from the raw markup.
// The benefit of doing it in LiquidRawTag is that we can keep the logic for doc separate
// I still want to understand how embeddings would work in this scenario. Maybe that's a complete different approach that we could take.
return [indent([hardline, body]), hardline];
}

if (shouldIndentBody) {
return [indent([hardline, body]), hardline];
} else {
Expand Down Expand Up @@ -547,6 +556,10 @@ function printNode(
return [...doc, ...lookups];
}

case NodeTypes.LiquidDocParamNode: {
return [node.name, 'asdf123', path.call((p: any) => print(p), 'value')];
}

default: {
return assertNever(node);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
It should indent the body
{% doc %}
@param body
{% enddoc %}

It should not dedent to root
{% doc %}
@param body
{% enddoc %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
It should indent the body
{% doc %}
@param body
{% enddoc %}

It should not dedent to root
{% doc %}
@param body
{% enddoc %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { test } from 'vitest';
import { assertFormattedEqualsFixed } from '../test-helpers';
import * as path from 'path';

test('Unit: liquid-doc', async () => {
await assertFormattedEqualsFixed(__dirname);
});

0 comments on commit a218331

Please sign in to comment.