Skip to content

Support for multi-line attributes#292

Merged
parsonsmatt merged 1 commit intoyesodweb:masterfrom
alexbiehl:alex/multi-line-attributes
Jun 5, 2025
Merged

Support for multi-line attributes#292
parsonsmatt merged 1 commit intoyesodweb:masterfrom
alexbiehl:alex/multi-line-attributes

Conversation

@alexbiehl
Copy link
Copy Markdown
Contributor

@alexbiehl alexbiehl commented May 18, 2025

Patch for #291.

@alexbiehl alexbiehl force-pushed the alex/multi-line-attributes branch from 199730c to b48bf18 Compare May 18, 2025 17:10
it "Alpine.js multi-line attribute values #291" $
helper "<div x-data=\"{\r\n search: '',\r\n\r\n items: ['foo', 'bar', 'baz'],\r\n\r\n get filteredItems() {\r\n return this.items.filter(\r\n i => i.startsWith(this.search)\r\n )\r\n }\r\n }\"></div>"
[hamlet|
$newline never
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this necessary in order to use multi-line attributes?

Copy link
Copy Markdown
Contributor Author

@alexbiehl alexbiehl Jun 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I just copied an existing test case and it came like that.

Copy link
Copy Markdown
Contributor Author

@alexbiehl alexbiehl Jun 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that it makes the output all go in one line, making it easier to deal with the expected output in absence of multi line strings.

Copy link
Copy Markdown
Collaborator

@parsonsmatt parsonsmatt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this looks great to me! I'll release today.

contentReg NotInQuotes = (ContentRaw . return) <$> noneOf "@^#. \t\n\r>"
contentReg NotInQuotesAttr = (ContentRaw . return) <$> noneOf "@^ \t\n\r>"
contentReg InQuotes = (ContentRaw . return) <$> noneOf "#@^\"\n\r"
contentReg InQuotes = (ContentRaw . return) <$> noneOf "#@^\""
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm trying to imagine the scenario where this code breaks something that exists.

We'd need to call contentReg (called by content' and content), and have quotes, and expect that the end-of-line successfully parses.

However. content - in the InQuotes case - asserts that a quote mark must follow.

    content cr = do
        x <- many $ content' cr
        case cr of
            InQuotes -> void $ char '"'
            NotInQuotes -> return ()
            NotInQuotesAttr -> return ()
            InContent -> eol
        return (cc $ map fst x, any snd x)

We can get a little more confidence that this is safe by grepping for InQuotes. InQuotes is only constructed once, in the parser for tagAttribValue. So we only ever enter in this code path in this case.

I feel pretty confident this is not a breaking change.

@parsonsmatt parsonsmatt merged commit a36def6 into yesodweb:master Jun 5, 2025
17 of 18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants