diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e21b07d..7a667b6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -31,6 +31,10 @@ jobs: with: ruby-version: '2.5' + - uses: actions/setup-python@v2 + with: + python-version: '3.8' + - name: Install bundler run: gem install bundler @@ -51,3 +55,19 @@ jobs: bundle exec jekyll --version bundle exec jekyll build python tests.py + + on_complete: + name: Notify IRC on Completion + runs-on: ubuntu-latest + needs: tests + if: always() + + steps: + - name: Send IRC notification + uses: allejo/supybot-notification-action@v1 + with: + status: ${{ needs.tests.result }} + hostname: ${{ secrets.SUPYBOT_HOSTNAME }} + credentials: ${{ secrets.SUPYBOT_PASSWORD }} + channel: '#sujevo-dev' + default_message: true diff --git a/_includes/anchor_headings.html b/_includes/anchor_headings.html index 69a5328..be83180 100644 --- a/_includes/anchor_headings.html +++ b/_includes/anchor_headings.html @@ -24,7 +24,7 @@ OTHER DEALINGS IN THE SOFTWARE. {% endcomment %} {% comment %} - Version 1.0.8 + Version 1.0.9 https://github.com/allejo/jekyll-anchor-headings "Be the pull request you wish to see in the world." ~Ben Balter @@ -97,8 +97,10 @@ {% capture anchor %}{% endcapture %} {% if html_id and headerLevel >= minHeader and headerLevel <= maxHeader %} + {% assign escaped_header = header | strip_html %} + {% if include.headerAttrs %} - {% capture _hAttrToStrip %}{{ _hAttrToStrip | split: '>' | first }} {{ include.headerAttrs | replace: '%heading%', header | replace: '%html_id%', html_id }}>{% endcapture %} + {% capture _hAttrToStrip %}{{ _hAttrToStrip | split: '>' | first }} {{ include.headerAttrs | replace: '%heading%', escaped_header | replace: '%html_id%', html_id }}>{% endcapture %} {% endif %} {% capture anchor %}href="#{{ html_id }}"{% endcapture %} @@ -108,14 +110,14 @@ {% endif %} {% if include.anchorTitle %} - {% capture anchor %}{{ anchor }} title="{{ include.anchorTitle | replace: '%heading%', header }}"{% endcapture %} + {% capture anchor %}{{ anchor }} title="{{ include.anchorTitle | replace: '%heading%', escaped_header }}"{% endcapture %} {% endif %} {% if include.anchorAttrs %} - {% capture anchor %}{{ anchor }} {{ include.anchorAttrs | replace: '%heading%', header | replace: '%html_id%', html_id }}{% endcapture %} + {% capture anchor %}{{ anchor }} {{ include.anchorAttrs | replace: '%heading%', escaped_header | replace: '%html_id%', html_id }}{% endcapture %} {% endif %} - {% capture anchor %}{{ include.anchorBody | replace: '%heading%', header | default: '' }}{% endcapture %} + {% capture anchor %}{{ include.anchorBody | replace: '%heading%', escaped_header | default: '' }}{% endcapture %} {% if beforeHeading %} diff --git a/_tests/escapeHeadingPlaceholder.html b/_tests/escapeHeadingPlaceholder.html new file mode 100644 index 0000000..b49b913 --- /dev/null +++ b/_tests/escapeHeadingPlaceholder.html @@ -0,0 +1,25 @@ +--- +# https://github.com/allejo/jekyll-anchor-headings/issues/27 +--- + +{% capture markdown %} +### The [**match**](#match) Expression +{% endcapture %} +{% assign text = markdown | markdownify %} + +{% include anchor_headings.html + beforeHeading=false + h_min=2 + html=text + anchorClass="permalink icon-link" + anchorBody="" + anchorTitle="Permalink for '%heading%'" + anchorAttrs='data-heading="%heading%"' + headerAttrs='data-heading="%heading%"' +%} + + + +

+ The match Expression +

diff --git a/tests.py b/tests.py index 511e1e0..f179411 100644 --- a/tests.py +++ b/tests.py @@ -6,17 +6,23 @@ import unittest import xml.etree.ElementTree as ET -class TestSequense(unittest.TestCase): +class TestSequence(unittest.TestCase): pass def test_generator(a, b): def test(self): + self.maxDiff = None self.assertEqual(a, b) return test -def normalize_xml(xml): - tree = ET.fromstring(xml) - return re.sub('\\n\s+|\\n', '', ET.tostring(tree)) +def normalize_xml(xml, test_file): + try: + tree = ET.fromstring(xml) + except: + print(f">> Invalid XML in {test_file}") + raise + + return re.sub(r'(\\n|\n)\s*', '', str(ET.tostring(tree)), 0, re.MULTILINE) if __name__ == '__main__': test_path = os.path.join(os.getcwd(), '_site', 'tests') @@ -25,12 +31,12 @@ def normalize_xml(xml): path = os.path.join(test_path, test_file) with open(path, 'r') as file: actual, expected = file.read().split('') - actual = normalize_xml(actual) - expected = normalize_xml(expected) + actual = normalize_xml(actual, test_file) + expected = normalize_xml(expected, test_file) - # Add the unit test to our TestSequense + # Add the unit test to our TestSequence test_name = 'test_{}'.format(test_file) test = test_generator(actual, expected) - setattr(TestSequense, test_name, test) + setattr(TestSequence, test_name, test) unittest.main()