Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Ignore lonely comment end tags #23

Merged
merged 5 commits into from
Nov 22, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions src/compress.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@
{% comment %}Remove comments{% endcomment %}

{% if site.compress_html.comments.size == 2 %}
{% assign _new = "" %}
{% assign _comment_befores = _content | split: site.compress_html.comments.first %}
{% for _comment_before in _comment_befores %}
{% assign _comment_after = _comment_before | split: site.compress_html.comments.last | last %}
{% assign _new = _new | append: _comment_after %}
{% assign _comment_content = _comment_before | split: site.compress_html.comments.last | first %}
{% if _comment_content %}
{% capture _comment %}{{ site.compress_html.comments.first }}{{ _comment_content }}{{ site.compress_html.comments.last }}{% endcapture %}
{% assign _content = _content | remove: _comment %}
{% endif %}
{% endfor %}
{% assign _content = _new %}
{% endif %}


Expand All @@ -30,11 +31,13 @@
{% assign _pre_befores = _content | split: "<pre" %}
{% for _pre_before in _pre_befores %}
{% assign _pres = _pre_before | split: "</pre>" %}
{% if _pres.size == 2 %}
{% assign _new = _new | append: "<pre" | append: _pres.first | append: "</pre>" %}
{% if _pres.size > 0 %}
{% if _pres.size == 2 %}
{% assign _new = _new | append: "<pre" | append: _pres.first | append: "</pre>" %}
{% endif %}
{% assign _compressed = _pres.last | split: " " | join: " " %}
{% assign _new = _new | append: _compressed %}
{% endif %}
{% assign _compressed = _pres.last | split: " " | join: " " %}
{% assign _new = _new | append: _compressed %}
{% endfor %}
{% assign _content = _new %}

Expand Down
3 changes: 3 additions & 0 deletions test/expected/comments/fake.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<pre>
&lt;!-- Two -->
</pre>
3 changes: 3 additions & 0 deletions test/expected/comments/right-angle-bracket.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<pre>
&lt;!-- Two -->
</pre>
7 changes: 7 additions & 0 deletions test/source/comments/fake.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
layout: compress
---

<pre>
&lt;!-- Two -->
</pre>
8 changes: 8 additions & 0 deletions test/source/comments/right-angle-bracket.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
layout: compress
---

<!-- One -->
<pre>
&lt;!-- Two -->
</pre>