-
Notifications
You must be signed in to change notification settings - Fork 29
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 parsing and prettier support for @example tags in liquid doc #725
base: main
Are you sure you want to change the base?
Changes from all commits
d265a2f
c72cb99
e44887c
fcc693e
14f5b3a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ import { | |
isBranchedTag, | ||
RawMarkup, | ||
LiquidDocParamNode, | ||
LiquidDocExampleNode, | ||
} from '@shopify/liquid-html-parser'; | ||
import { Doc, doc } from 'prettier'; | ||
|
||
|
@@ -536,6 +537,30 @@ export function printLiquidDocParam( | |
return parts; | ||
} | ||
|
||
export function printLiquidDocExample( | ||
path: AstPath<LiquidDocExampleNode>, | ||
options: LiquidParserOptions, | ||
_print: LiquidPrinter, | ||
_args: LiquidPrinterArgs, | ||
): Doc { | ||
const node = path.getValue(); | ||
const parts: Doc[] = ['@example']; | ||
|
||
if (node.exampleContent?.value) { | ||
const content = node.exampleContent.value.trim(); | ||
if (content) { | ||
parts.push(hardline); | ||
const lines = content | ||
.split('\n') | ||
.map((line) => line.trim()) | ||
.filter(Boolean); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this behaviour should be tested in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's also add an eslint config for this - https://app.graphite.dev/github/pr/Shopify/theme-tools/646/Add-parsing-prettier-support-for-param-in-doc-tags |
||
parts.push(join(hardline, lines)); | ||
jamesmengo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
|
||
return parts; | ||
} | ||
|
||
function innerLeadingWhitespace(node: LiquidTag | LiquidBranch) { | ||
if (!node.firstChild) { | ||
if (node.isDanglingWhitespaceSensitive && node.hasDanglingWhitespace) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,3 +27,9 @@ It should normalize the param description | |
{% doc %} | ||
@param paramName - param with description | ||
{% enddoc %} | ||
|
||
It should push example content to the next line | ||
{% doc %} | ||
@example | ||
This is a valid example | ||
{% enddoc %} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add a multiline example |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's add some tests for locStart / locEnd and document how we want that to behave, especially considering whitespace etc
Can also add some assertions in stage-2 for position