Skip to content

Commit

Permalink
fix: Make strikethrough precedence the default; add strikethrough tes…
Browse files Browse the repository at this point in the history
…ts (#136)
  • Loading branch information
KevinMGranger authored Jan 28, 2023
1 parent 0a870ce commit 7b31460
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
2 changes: 1 addition & 1 deletion marko/ext/gfm/elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class InlineHTML(inline.InlineHTML):
class Strikethrough(inline.InlineElement):

pattern = re.compile(r"~~([^~]+)~~")
priority = 4
priority = 5
parse_children = True


Expand Down
2 changes: 1 addition & 1 deletion noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
os.environ.update(PDM_IGNORE_SAVED_PYTHON="1")


@nox.session(python=["3.6", "3.8", "3.9", "3.10"])
@nox.session(python=["3.6", "3.8", "3.9", "3.10", "3.11"])
def tests(session):
session.run("pdm", "install", "-d", external=True)
session.run("pytest", "tests/")
Expand Down
35 changes: 35 additions & 0 deletions tests/test_ext.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#! -*- coding: utf-8 -*-

import pytest

from marko import Markdown


Expand Down Expand Up @@ -76,6 +78,39 @@ class TestGFM:
def setup_method(self):
self.markdown = Markdown(extensions=["gfm"])

def test_strikethrough_link(self):
content = "~~[google](https://google.com)~~"
assert (
self.markdown(content).strip()
== '<p><del><a href="https://google.com">google</a></del></p>'
)

def test_strikethrough_inside_link(self):
content = "[~~google~~](https://google.com)"
assert (
self.markdown(content).strip()
== '<p><a href="https://google.com"><del>google</del></a></p>'
)

def test_strikethrough_spec_standard(self):
content = "~~Hi~~ Hello, world!"
expected = "<p><del>Hi</del> Hello, world!</p>"
assert self.markdown(content).strip() == expected

def test_strikethrough_spec_new_paragraph(self):
content = """This ~~has a
new paragraph~~."""
expected = """<p>This ~~has a</p>
<p>new paragraph~~.</p>"""
assert self.markdown(content).strip() == expected

@pytest.mark.skip(reason="existing GFM won't-strike bug")
def test_strikethrough_spec_wont_strike(self):
content = "This will ~~~not~~~ strike."
expected = "<p>This will ~~~not~~~ strike.</p>"
assert self.markdown(content).strip() == expected

def test_gfm_autolink(self):
content = "地址:https://google.com"
assert (
Expand Down

0 comments on commit 7b31460

Please sign in to comment.