Skip to content

Commit 7b277c1

Browse files
committed
Add basic prettier support for doc tag
1 parent 1a1108a commit 7b277c1

File tree

6 files changed

+35
-1
lines changed

6 files changed

+35
-1
lines changed

packages/liquid-html-parser/src/stage-1-cst.ts

+2
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ export interface ConcreteBasicNode<T> {
110110
export interface ConcreteLiquidDocParamNode
111111
extends ConcreteBasicNode<ConcreteNodeTypes.LiquidDocParamNode> {
112112
name: string;
113+
value: string;
113114
}
114115

115116
export interface ConcreteHtmlNodeBase<T> extends ConcreteBasicNode<T> {
@@ -1328,6 +1329,7 @@ function toLiquidDocAST(source: string, matchingSource: string, offset: number)
13281329
paramNode: {
13291330
type: ConcreteNodeTypes.LiquidDocParamNode,
13301331
name: 0,
1332+
value: 2,
13311333
locStart,
13321334
locEnd,
13331335
source,

packages/liquid-html-parser/src/stage-2-ast.ts

+2
Original file line numberDiff line numberDiff line change
@@ -757,6 +757,7 @@ export interface TextNode extends ASTNode<NodeTypes.TextNode> {
757757

758758
export interface LiquidDocParamNode extends ASTNode<NodeTypes.LiquidDocParamNode> {
759759
name: string;
760+
value: string;
760761
}
761762

762763
export interface ASTNode<T> {
@@ -1279,6 +1280,7 @@ function buildAst(
12791280
name: node.name,
12801281
position: position(node),
12811282
source: node.source,
1283+
value: node.value,
12821284
});
12831285
break;
12841286
}

packages/prettier-plugin-liquid/src/printer/printer-liquid-html.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,11 @@ function printNode(
210210
}
211211

212212
case NodeTypes.RawMarkup: {
213+
if (node.parentNode?.name === 'doc') {
214+
const liquidDocBody = path.map((p: any) => print(p), 'nodes');
215+
return [indent([hardline, liquidDocBody]), hardline];
216+
}
217+
213218
const isRawMarkupIdentationSensitive = () => {
214219
switch (node.kind) {
215220
case RawMarkupKinds.typescript:
@@ -548,7 +553,7 @@ function printNode(
548553
}
549554

550555
case NodeTypes.LiquidDocParamNode: {
551-
return node.name;
556+
return [node.name, ' ', node.value];
552557
}
553558

554559
default: {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
It should indent the body
2+
{% doc %}
3+
@param body
4+
{% enddoc %}
5+
6+
It should not dedent to root
7+
{% doc %}
8+
@param body
9+
{% enddoc %}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
It should indent the body
2+
{% doc %}
3+
@param body
4+
{% enddoc %}
5+
6+
It should not dedent to root
7+
{% doc %}
8+
@param body
9+
{% enddoc %}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { test } from 'vitest';
2+
import { assertFormattedEqualsFixed } from '../test-helpers';
3+
import * as path from 'path';
4+
5+
test('Unit: liquid-doc', async () => {
6+
await assertFormattedEqualsFixed(__dirname);
7+
});

0 commit comments

Comments
 (0)