reactive-python / reactpy-django

It's React, but in Python. Now with Django integration.
https://reactive-python.github.io/reactpy-django/
MIT License
323 stars 18 forks source link

Component regex tries to match commented out code #102

Closed Archmonger closed 1 year ago

Archmonger commented 1 year ago

Current Situation

Currently commented out component tags will attempt to be parsed by our component regex.

For example, this should not be parsed <!-- {% component "my.component" %} -->

Proposed Actions

Modify the regex to avoid any tags within comments.

As a quick test, I attempted to see what would happen if I prefixed the component regex with a negative lookbehind (?<!(<!--))\s*, however, it did not work for any tags containing a space between the comment start <!-- and tag start {%

Additionally, I'm not entirely how to write regex for situations like <!-- {% component "my.component" %} --> while not hitting false negatives for things such as <!-- a comment --> {% component "my.component" %} <!-- another comment -->

If a regex solution can't be made, a quick and dirty solution could be running some kind of HTML minifier to strip out comment tags prior to reading the template HTML.

Or a running a simple regex replace on all comments prior to parsing.