From 73933cf80415ad18c95f4d929e69361b36046169 Mon Sep 17 00:00:00 2001 From: Mike Fix <62121649+mfix-stripe@users.noreply.github.com> Date: Thu, 29 Sep 2022 11:36:18 -0700 Subject: [PATCH] Dont wrap tags within inline parents (#230) * dont wrap tags within inline parents * simplify implementation --- src/formatter.test.ts | 10 ++++++++++ src/formatter.ts | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/formatter.test.ts b/src/formatter.test.ts index 09884f7..a8bbe2e 100644 --- a/src/formatter.test.ts +++ b/src/formatter.test.ts @@ -248,6 +248,16 @@ Yes! stable(expected); }); + it('long inline tags', () => { + const source = `{% button type="button" href="https://example.com/a-very-long-inline-tag" %}A very long inline tag{% /button %} +`; + check(source, source); + + const inlineParent = `### {% image src="/src" alt="A very long alt text to test if the tag wraps or not" /%} +`; + check(inlineParent, inlineParent); + }); + it('long tags with maxTagOpeningWidth=Infinity', () => { const source = ` {% tag a=true b="My very long text well over 80 characters in total" c=123456789 d=false /%} diff --git a/src/formatter.ts b/src/formatter.ts index b6f536f..c8f7f47 100644 --- a/src/formatter.ts +++ b/src/formatter.ts @@ -225,7 +225,7 @@ function* formatNode(n: Node, o: Options = {}) { (o.maxTagOpeningWidth || MAX_TAG_OPENING_WIDTH); // {% tag attributes={...} %} - yield (isLongTagOpening + yield (!n.inline && isLongTagOpening ? tag.join(NL + SPACE.repeat(open.length) + indent) : inlineTag) + SPACE +