Skip to content

Commit c7e11e3

Browse files
authored
Merge pull request allejo#28 from allejo/hotfix/escape-heading-placeholder
2 parents 376bee9 + 3a15990 commit c7e11e3

File tree

4 files changed

+66
-13
lines changed

4 files changed

+66
-13
lines changed

.github/workflows/ci.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ jobs:
3131
with:
3232
ruby-version: '2.5'
3333

34+
- uses: actions/setup-python@v2
35+
with:
36+
python-version: '3.8'
37+
3438
- name: Install bundler
3539
run: gem install bundler
3640

@@ -51,3 +55,19 @@ jobs:
5155
bundle exec jekyll --version
5256
bundle exec jekyll build
5357
python tests.py
58+
59+
on_complete:
60+
name: Notify IRC on Completion
61+
runs-on: ubuntu-latest
62+
needs: tests
63+
if: always()
64+
65+
steps:
66+
- name: Send IRC notification
67+
uses: allejo/supybot-notification-action@v1
68+
with:
69+
status: ${{ needs.tests.result }}
70+
hostname: ${{ secrets.SUPYBOT_HOSTNAME }}
71+
credentials: ${{ secrets.SUPYBOT_PASSWORD }}
72+
channel: '#sujevo-dev'
73+
default_message: true

_includes/anchor_headings.html

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
OTHER DEALINGS IN THE SOFTWARE.
2525
{% endcomment %}
2626
{% comment %}
27-
Version 1.0.8
27+
Version 1.0.9
2828
https://github.com/allejo/jekyll-anchor-headings
2929

3030
"Be the pull request you wish to see in the world." ~Ben Balter
@@ -97,8 +97,10 @@
9797
{% capture anchor %}{% endcapture %}
9898

9999
{% if html_id and headerLevel >= minHeader and headerLevel <= maxHeader %}
100+
{% assign escaped_header = header | strip_html %}
101+
100102
{% if include.headerAttrs %}
101-
{% capture _hAttrToStrip %}{{ _hAttrToStrip | split: '>' | first }} {{ include.headerAttrs | replace: '%heading%', header | replace: '%html_id%', html_id }}>{% endcapture %}
103+
{% capture _hAttrToStrip %}{{ _hAttrToStrip | split: '>' | first }} {{ include.headerAttrs | replace: '%heading%', escaped_header | replace: '%html_id%', html_id }}>{% endcapture %}
102104
{% endif %}
103105

104106
{% capture anchor %}href="#{{ html_id }}"{% endcapture %}
@@ -108,14 +110,14 @@
108110
{% endif %}
109111

110112
{% if include.anchorTitle %}
111-
{% capture anchor %}{{ anchor }} title="{{ include.anchorTitle | replace: '%heading%', header }}"{% endcapture %}
113+
{% capture anchor %}{{ anchor }} title="{{ include.anchorTitle | replace: '%heading%', escaped_header }}"{% endcapture %}
112114
{% endif %}
113115

114116
{% if include.anchorAttrs %}
115-
{% capture anchor %}{{ anchor }} {{ include.anchorAttrs | replace: '%heading%', header | replace: '%html_id%', html_id }}{% endcapture %}
117+
{% capture anchor %}{{ anchor }} {{ include.anchorAttrs | replace: '%heading%', escaped_header | replace: '%html_id%', html_id }}{% endcapture %}
116118
{% endif %}
117119

118-
{% capture anchor %}<a {{ anchor }}>{{ include.anchorBody | replace: '%heading%', header | default: '' }}</a>{% endcapture %}
120+
{% capture anchor %}<a {{ anchor }}>{{ include.anchorBody | replace: '%heading%', escaped_header | default: '' }}</a>{% endcapture %}
119121

120122
<!-- In order to prevent adding extra space after a heading, we'll let the 'anchor' value contain it -->
121123
{% if beforeHeading %}

_tests/escapeHeadingPlaceholder.html

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
# https://github.com/allejo/jekyll-anchor-headings/issues/27
3+
---
4+
5+
{% capture markdown %}
6+
### The [**match**](#match) Expression
7+
{% endcapture %}
8+
{% assign text = markdown | markdownify %}
9+
10+
{% include anchor_headings.html
11+
beforeHeading=false
12+
h_min=2
13+
html=text
14+
anchorClass="permalink icon-link"
15+
anchorBody=""
16+
anchorTitle="Permalink for '%heading%'"
17+
anchorAttrs='data-heading="%heading%"'
18+
headerAttrs='data-heading="%heading%"'
19+
%}
20+
21+
<!-- /// -->
22+
23+
<h3 id="the-match-expression" data-heading="The match Expression">
24+
The <a href="#match"><strong>match</strong></a> Expression <a href="#the-match-expression" class="permalink icon-link" title="Permalink for 'The match Expression'" data-heading="The match Expression"></a>
25+
</h3>

tests.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,23 @@
66
import unittest
77
import xml.etree.ElementTree as ET
88

9-
class TestSequense(unittest.TestCase):
9+
class TestSequence(unittest.TestCase):
1010
pass
1111

1212
def test_generator(a, b):
1313
def test(self):
14+
self.maxDiff = None
1415
self.assertEqual(a, b)
1516
return test
1617

17-
def normalize_xml(xml):
18-
tree = ET.fromstring(xml)
19-
return re.sub('\\n\s+|\\n', '', ET.tostring(tree))
18+
def normalize_xml(xml, test_file):
19+
try:
20+
tree = ET.fromstring(xml)
21+
except:
22+
print(f">> Invalid XML in {test_file}")
23+
raise
24+
25+
return re.sub(r'(\\n|\n)\s*', '', str(ET.tostring(tree)), 0, re.MULTILINE)
2026

2127
if __name__ == '__main__':
2228
test_path = os.path.join(os.getcwd(), '_site', 'tests')
@@ -25,12 +31,12 @@ def normalize_xml(xml):
2531
path = os.path.join(test_path, test_file)
2632
with open(path, 'r') as file:
2733
actual, expected = file.read().split('<!-- /// -->')
28-
actual = normalize_xml(actual)
29-
expected = normalize_xml(expected)
34+
actual = normalize_xml(actual, test_file)
35+
expected = normalize_xml(expected, test_file)
3036

31-
# Add the unit test to our TestSequense
37+
# Add the unit test to our TestSequence
3238
test_name = 'test_{}'.format(test_file)
3339
test = test_generator(actual, expected)
34-
setattr(TestSequense, test_name, test)
40+
setattr(TestSequence, test_name, test)
3541

3642
unittest.main()

0 commit comments

Comments
 (0)