Skip to content

Commit 2b3cdd9

Browse files
committed
refactoed ohm logic, stage2 and prettier broken
1 parent 2e56122 commit 2b3cdd9

File tree

5 files changed

+24
-15
lines changed

5 files changed

+24
-15
lines changed

packages/liquid-html-parser/grammar/liquid-html.ohm

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,11 +402,15 @@ LiquidDoc <: Helpers {
402402

403403
fallbackNode = "@" anyExceptStar<endOfParam>
404404
paramNode = "@param" strictSpace* paramType? strictSpace* paramName (strictSpace* "-")? strictSpace* paramDescription
405-
paramType = "{" strictSpace* paramTypeContent strictSpace* "}"
405+
paramType = "{" anyExceptPlus<"}"> "}"
406406
paramTypeContent = anyExceptStar<("}"| strictSpace)>
407407
paramName = identifierCharacter+
408408
paramDescription = anyExceptStar<endOfParam>
409409
endOfParam = strictSpace* (newline | end)
410+
411+
exampleNode = "@example" strictSpace* exampleContent
412+
exampleContent = anyExceptStar<endOfExample>
413+
endOfExample = strictSpace* ("@" | end)
410414
}
411415

412416
LiquidHTML <: Liquid {

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,10 +1116,12 @@ describe('Unit: Stage 1 (CST)', () => {
11161116
expectPath(cst, '0.name').to.equal('doc');
11171117
expectPath(cst, '0.children.0.type').to.equal('LiquidDocExampleNode');
11181118
expectPath(cst, '0.children.0.exampleContent.value').to.equal('');
1119-
expectPath(cst, '0.children.0.locStart').to.equal(testStr.indexOf('@example'));
1120-
expectPath(cst, '0.children.0.locEnd').to.equal(
1121-
testStr.indexOf('@example') + '@example'.length,
1122-
);
1119+
});
1120+
1121+
it('should parse example tag with content that has leading whitespace', () => {
1122+
const testStr = `{% doc %} @example hello there {%- enddoc %}`;
1123+
cst = toCST(testStr);
1124+
expectPath(cst, '0.children.0.exampleContent.value').to.equal('hello there');
11231125
});
11241126

11251127
it('should parse an example tag with a value', () => {

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

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1359,17 +1359,9 @@ function toLiquidDocAST(source: string, matchingSource: string, offset: number)
13591359
locStart,
13601360
locEnd,
13611361
source,
1362-
exampleContent: function (nodes: Node[]) {
1363-
const contentNode = nodes[1];
1364-
return {
1365-
type: ConcreteNodeTypes.TextNode,
1366-
value: contentNode.sourceString,
1367-
source,
1368-
locStart: offset + contentNode.source.startIdx,
1369-
locEnd: offset + contentNode.source.endIdx,
1370-
};
1371-
},
1362+
exampleContent: 2,
13721363
},
1364+
exampleContent: textNode,
13731365
fallbackNode: textNode,
13741366
};
13751367

packages/prettier-plugin-liquid/src/test/liquid-doc/fixed.liquid

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,9 @@ It should normalize the param description
2727
{% doc %}
2828
@param paramName - param with description
2929
{% enddoc %}
30+
31+
It should push example content to the next line
32+
{% doc %}
33+
@example
34+
This is a valid example
35+
{% enddoc %}

packages/prettier-plugin-liquid/src/test/liquid-doc/index.liquid

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,8 @@ It should normalize the param description
2727
{% doc %}
2828
@param paramName - param with description
2929
{% enddoc %}
30+
31+
It should push example content to the next line
32+
{% doc %}
33+
@example This is a valid example
34+
{% enddoc %}

0 commit comments

Comments
 (0)