Crates.io | ludtwig-parser |
lib.rs | ludtwig-parser |
version | 0.6.0 |
source | src |
created_at | 2021-01-31 11:07:12.078767 |
updated_at | 2024-11-08 13:27:05.527756 |
description | Lossless parser for HTML / Twig templating syntax. |
homepage | |
repository | https://github.com/MalteJanz/ludtwig |
max_upload_size | |
id | 348825 |
size | 640,703 |
Rust crate that parses Twig / HTML templating syntax into a lossless syntax tree. It does not conform to the official HTML spec and the input is required to be as idiomatic as possible (but the parser still tries to recover from errors / parse as much as possible). For example missing closing tags in HTML result in a parsing error (even if browsers can interpret the HTML and reconstruct the closing tag). This makes it possible to represent the template in a hierarchical untyped tree which is easy to navigate and contains both Twig and HTML syntax.
{% block my_component %}
{% set isActive = true %}
<div id="my-component"
class="my-component {% if isLarge %}large{% endif %}"
{{ dataAttribute }}="data"
{# Single word attributes don't strictly require quotes #}
data-active={{ isActive }}
>
{% block my_component_inner %}
<span id="my-span"
{% if isActive %}
style="color: red"
{% endif %}
>
hello {{ name }}
</span>
{% endblock %}
</div>
{% endblock %}
It is developed together with the ludtwig CLI application for formatting and analyzing Twig template files.
MIT - see LICENSE file.
For testing purposes this repository also may include code from the following sources: