Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: Python-Markdown/markdown
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: polidano10/markdown
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Able to merge. These branches can be automatically merged.

Commits on Oct 13, 2022

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    a5eea36 View commit details
  2. test

    polidano10 authored Oct 13, 2022

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    8008efb View commit details
  3. Add files via upload

    polidano10 authored Oct 13, 2022

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    1b4ffe4 View commit details
  4. Add files via upload

    polidano10 authored Oct 13, 2022

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    8b2cd04 View commit details
  5. Add files via upload

    polidano10 authored Oct 13, 2022

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    019372a View commit details
  6. make iframe lazy load

    polidano10 authored Oct 13, 2022

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    f867d1a View commit details
  7. make iframe lazy load

    polidano10 authored Oct 13, 2022

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    2d20121 View commit details
  8. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    f47e687 View commit details

Commits on Apr 8, 2023

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    c155158 View commit details

Commits on Mar 4, 2024

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    c3c8ae1 View commit details

Commits on Nov 27, 2024

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    3be6c67 View commit details

Commits on Nov 28, 2024

  1. Update test_images.py

    BuildTools committed Nov 28, 2024
    Copy the full SHA
    4991b08 View commit details
  2. Update test_images.py

    BuildTools committed Nov 28, 2024
    Copy the full SHA
    aac7a1b View commit details
  3. Update test_images.py

    BuildTools committed Nov 28, 2024
    Copy the full SHA
    a12bea7 View commit details
  4. Update test_images.py

    BuildTools committed Nov 28, 2024
    Copy the full SHA
    a4044b1 View commit details
  5. Update test_images.py

    polidano10 authored and BuildTools committed Nov 28, 2024
    Copy the full SHA
    0c028b9 View commit details
  6. Update test_images.py

    polidano10 authored and polidano10 40580410+polidano10@users.noreply.github.com committed Nov 28, 2024
    Copy the full SHA
    eb899cc View commit details
  7. Update test_images.py

    polidano10 40580410+polidano10@users.noreply.github.com committed Nov 28, 2024
    Copy the full SHA
    d74c0d5 View commit details
  8. Update test_images.py

    polidano10 authored and polidano10 40580410+polidano10@users.noreply.github.com committed Nov 28, 2024
    Copy the full SHA
    82cb665 View commit details
  9. Update test_smarty.py

    polidano10 committed Nov 28, 2024
    Copy the full SHA
    ca37973 View commit details
  10. Update test_legacy_attrs.py

    polidano10 committed Nov 28, 2024
    Copy the full SHA
    f2ae3ad View commit details
  11. Update test_legacy_attrs.py

    polidano10 committed Nov 28, 2024
    Copy the full SHA
    0e9b7d1 View commit details
  12. Update test_abbr.py

    polidano10 committed Nov 28, 2024
    Copy the full SHA
    f8001c7 View commit details
  13. Fix tests

    polidano10 committed Nov 28, 2024
    Copy the full SHA
    5bd909f View commit details
  14. Fix tests

    polidano10 committed Nov 28, 2024
    Copy the full SHA
    1a9d614 View commit details
  15. Fix tests

    polidano10 committed Nov 28, 2024
    Copy the full SHA
    b299a9f View commit details
  16. Support tests for Python 3.13

    polidano10 committed Nov 28, 2024
    Copy the full SHA
    eddf26e View commit details
4 changes: 3 additions & 1 deletion .github/workflows/tox.yml
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@ jobs:
fail-fast: false
max-parallel: 4
matrix:
tox-env: [py38, py39, py310, py311, py312, pypy38, pypy39, pypy310, pygments]
tox-env: [py38, py39, py310, py311, py312, py313, pypy38, pypy39, pypy310, pygments]
include:
- tox-env: py38
python-version: '3.8'
@@ -32,6 +32,8 @@ jobs:
python-version: '3.11'
- tox-env: py312
python-version: '3.12'
- tox-env: py313
python-version: '3.13'
- tox-env: pypy38
python-version: pypy-3.8
- tox-env: pypy39
4 changes: 4 additions & 0 deletions markdown/extensions/md_in_html.py
Original file line number Diff line number Diff line change
@@ -100,6 +100,10 @@ def get_state(self, tag, attrs: Mapping[str, str]) -> Literal['block', 'span', '

def handle_starttag(self, tag, attrs):
# Handle tags that should always be empty and do not specify a closing tag

if tag in {"iframe", "img"}:
attrs.append(("loading", "lazy"))

if tag in self.empty_tags and (self.at_line_start() or self.intail):
attrs = {key: value if value is not None else key for key, value in attrs}
if "markdown" in attrs:
2 changes: 2 additions & 0 deletions markdown/inlinepatterns.py
Original file line number Diff line number Diff line change
@@ -858,6 +858,7 @@ def handleMatch(self, m: re.Match[str], data: str) -> tuple[etree.Element | None
el = etree.Element("img")

el.set("src", src)
el.set("loading", "lazy")

if title is not None:
el.set("title", title)
@@ -936,6 +937,7 @@ def makeTag(self, href: str, title: str, text: str) -> etree.Element:
""" Return an `img` [`Element`][xml.etree.ElementTree.Element]. """
el = etree.Element("img")
el.set("src", href)
el.set("loading", "lazy")
if title:
el.set("title", title)
el.set("alt", self.unescape(text))
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -34,6 +34,7 @@ classifiers = [
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Programming Language :: Python :: 3.12',
'Programming Language :: Python :: 3.13',
'Programming Language :: Python :: 3 :: Only',
'Programming Language :: Python :: Implementation :: CPython',
'Programming Language :: Python :: Implementation :: PyPy',
4 changes: 2 additions & 2 deletions tests/basic/angle-links-and-img.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<p><a href="simple link" title="title">link</a>
<img alt="image" src="http://example.com/image.jpg" />
<img alt="image" loading="lazy" src="http://example.com/image.jpg" />
<a href="http://example.com/(()((())923)(">link</a>
<img alt="image" src="link(()))(" /></p>
<img alt="image" loading="lazy" src="link(()))(" /></p>
18 changes: 9 additions & 9 deletions tests/misc/brackets-in-img-title.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<p><img alt="alt" src="local-img.jpg" />
<img alt="alt" src="local-img.jpg" title="" />
<img alt="alt" src="local-img.jpg" title="normal title" /></p>
<p><img alt="alt" src="local-img.jpg" title="(just title in brackets)" />
<img alt="alt" src="local-img.jpg" title="title with brackets (I think)" /></p>
<p><img alt="alt" src="local-img.jpg" title="(" />
<img alt="alt" src="local-img.jpg" title="(open only" />
<img alt="alt" src="local-img.jpg" title=")" />
<img alt="alt" src="local-img.jpg" title="close only)" /></p>
<p><img alt="alt" loading="lazy" src="local-img.jpg" />
<img alt="alt" loading="lazy" src="local-img.jpg" title="" />
<img alt="alt" loading="lazy" src="local-img.jpg" title="normal title" /></p>
<p><img alt="alt" loading="lazy" src="local-img.jpg" title="(just title in brackets)" />
<img alt="alt" loading="lazy" src="local-img.jpg" title="title with brackets (I think)" /></p>
<p><img alt="alt" loading="lazy" src="local-img.jpg" title="(" />
<img alt="alt" loading="lazy" src="local-img.jpg" title="(open only" />
<img alt="alt" loading="lazy" src="local-img.jpg" title=")" />
<img alt="alt" loading="lazy" src="local-img.jpg" title="close only)" /></p>
2 changes: 1 addition & 1 deletion tests/misc/image_in_links.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<p><a href="path/to/image.png"><img alt="altname" src="path/to/img_thumb.png" /></a></p>
<p><a href="path/to/image.png"><img alt="altname" loading="lazy" src="path/to/img_thumb.png" /></a></p>
6 changes: 3 additions & 3 deletions tests/misc/uche.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<p><img alt="asif" src="http://fourthought.com/images/ftlogo.png" title="Fourthought logo" /></p>
<p><a href="http://fourthought.com/"><img alt="Alt text" src="http://fourthought.com/images/ftlogo.png" title="Fourthought logo" /></a></p>
<p><a href="http://link.com/"><img alt="text" src="x" /></a></p>
<p><img alt="asif" loading="lazy" src="http://fourthought.com/images/ftlogo.png" title="Fourthought logo" /></p>
<p><a href="http://fourthought.com/"><img alt="Alt text" loading="lazy" src="http://fourthought.com/images/ftlogo.png" title="Fourthought logo" /></a></p>
<p><a href="http://link.com/"><img alt="text" loading="lazy" src="x" /></a></p>
5 changes: 2 additions & 3 deletions tests/test_syntax/extensions/test_abbr.py
Original file line number Diff line number Diff line change
@@ -439,9 +439,8 @@ def test_abbr_with_attr_list(self):
"""
),
self.dedent(
"""
<p><img alt="Image with abbr in title" src="abbr.png" title="Image with abbr in title" /></p>
"""
"""<p><img alt="Image with abbr in title" loading="lazy" src="abbr.png" """
"""title="Image with abbr in title" /></p>"""
),
extensions=['abbr', 'attr_list']
)
4 changes: 2 additions & 2 deletions tests/test_syntax/extensions/test_legacy_attrs.py
Original file line number Diff line number Diff line change
@@ -60,8 +60,8 @@ def testLegacyAttrs(self):
</ul>
<p id="TABLEOFCONTENTS">Or in the middle of the text </p>
<p id="tableofcontents"></p>
<p><a href="http://fourthought.com/"><img alt="" src="http://fourthought.com/images/ftlogo.png" style="float: left; margin: 10px; border: none;" title="Fourthought logo" /></a></p>
<p><img alt="img" id="foo" src="http://example.com/i.jpg" /></p>
<p><a href="http://fourthought.com/"><img alt="" loading="lazy" src="http://fourthought.com/images/ftlogo.png" style="float: left; margin: 10px; border: none;" title="Fourthought logo" /></a></p>
<p><img alt="img" id="foo" loading="lazy" src="http://example.com/i.jpg" /></p>
"""), # noqa: E501
extensions=['legacy_attrs']
)
2 changes: 1 addition & 1 deletion tests/test_syntax/extensions/test_smarty.py
Original file line number Diff line number Diff line change
@@ -113,7 +113,7 @@ def test_escaped(self):
def test_escaped_attr(self):
self.assertMarkdownRenders(
'![x\"x](x)',
'<p><img alt="x&quot;x" src="x" /></p>'
'<p><img alt="x&quot;x" loading="lazy" src="x" /></p>'
)

def test_code_spans(self):
57 changes: 34 additions & 23 deletions tests/test_syntax/inline/test_images.py
Original file line number Diff line number Diff line change
@@ -23,106 +23,116 @@


class TestAdvancedImages(TestCase):

def test_nested_square_brackets(self):
self.assertMarkdownRenders(
"""![Text[[[[[[[]]]]]]][]](http://link.com/image.png) more text""",
"""<p><img alt="Text[[[[[[[]]]]]]][]" src="http://link.com/image.png" /> more text</p>"""
"""<p><img alt="Text[[[[[[[]]]]]]][]" loading="lazy" src="http://link.com/image.png" /> """
"""more text</p>"""
)

def test_nested_round_brackets(self):
self.assertMarkdownRenders(
"""![Text](http://link.com/(((((((()))))))()).png) more text""",
"""<p><img alt="Text" src="http://link.com/(((((((()))))))()).png" /> more text</p>"""
"""<p><img alt="Text" loading="lazy" src="http://link.com/(((((((()))))))()).png" /> """
"""more text</p>"""
)

def test_uneven_brackets_with_titles1(self):
self.assertMarkdownRenders(
"""![Text](http://link.com/(.png"title") more text""",
"""<p><img alt="Text" src="http://link.com/(.png" title="title" /> more text</p>"""
"""<p><img alt="Text" loading="lazy" src="http://link.com/(.png" title="title" /> more text</p>"""
)

def test_uneven_brackets_with_titles2(self):
self.assertMarkdownRenders(
"""![Text](http://link.com/('.png"title") more text""",
"""<p><img alt="Text" src="http://link.com/('.png" title="title" /> more text</p>"""
"""<p><img alt="Text" loading="lazy" src="http://link.com/('.png" title="title" /> more text</p>"""
)

def test_uneven_brackets_with_titles3(self):
self.assertMarkdownRenders(
"""![Text](http://link.com/(.png"title)") more text""",
"""<p><img alt="Text" src="http://link.com/(.png" title="title)" /> more text</p>"""
"""<p><img alt="Text" loading="lazy" src="http://link.com/(.png" title="title)" /> more text</p>"""
)

def test_uneven_brackets_with_titles4(self):
self.assertMarkdownRenders(
"""![Text](http://link.com/(.png "title") more text""",
"""<p><img alt="Text" src="http://link.com/(.png" title="title" /> more text</p>"""
"""<p><img alt="Text" loading="lazy" src="http://link.com/(.png" title="title" /> more text</p>"""
)

def test_uneven_brackets_with_titles5(self):
self.assertMarkdownRenders(
"""![Text](http://link.com/(.png "title)") more text""",
"""<p><img alt="Text" src="http://link.com/(.png" title="title)" /> more text</p>"""
"""<p><img alt="Text" loading="lazy" src="http://link.com/(.png" title="title)" /> more text</p>"""
)

def test_mixed_title_quotes1(self):
self.assertMarkdownRenders(
"""![Text](http://link.com/'.png"title") more text""",
"""<p><img alt="Text" src="http://link.com/'.png" title="title" /> more text</p>"""
"""<p><img alt="Text" loading="lazy" src="http://link.com/'.png" title="title" /> more text</p>"""
)

def test_mixed_title_quotes2(self):
self.assertMarkdownRenders(
"""![Text](http://link.com/".png'title') more text""",
"""<p><img alt="Text" src="http://link.com/&quot;.png" title="title" /> more text</p>"""
"""<p><img alt="Text" loading="lazy" src="http://link.com/&quot;.png" title="title" /> """
"""more text</p>"""
)

def test_mixed_title_quotes3(self):
self.assertMarkdownRenders(
"""![Text](http://link.com/with spaces.png'"and quotes" 'and title') more text""",
"""<p><img alt="Text" src="http://link.com/with spaces.png" title="&quot;and quotes&quot; 'and title" />"""
"""<p><img alt="Text" loading="lazy" src="http://link.com/with spaces.png" """
"""title="&quot;and quotes&quot; 'and title" />"""
""" more text</p>"""
)

def test_mixed_title_quotes4(self):
self.assertMarkdownRenders(
"""![Text](http://link.com/with spaces'.png"and quotes" 'and title") more text""",
"""<p><img alt="Text" src="http://link.com/with spaces'.png" title="and quotes&quot; 'and title" />"""
"""<p><img alt="Text" loading="lazy" src="http://link.com/with spaces'.png" """
"""title="and quotes&quot; 'and title" />"""
""" more text</p>"""
)

def test_mixed_title_quotes5(self):
self.assertMarkdownRenders(
"""![Text](http://link.com/with spaces .png'"and quotes" 'and title') more text""",
"""<p><img alt="Text" src="http://link.com/with spaces .png" title="&quot;and quotes&quot;"""
"""<p><img alt="Text" loading="lazy" src="http://link.com/with spaces .png" """
"""title="&quot;and quotes&quot;"""
""" 'and title" /> more text</p>"""
)

def test_mixed_title_quotes6(self):
self.assertMarkdownRenders(
"""![Text](http://link.com/with spaces "and quotes".png 'and title') more text""",
"""<p><img alt="Text" src="http://link.com/with spaces &quot;and quotes&quot;.png" title="and title" />"""
"""<p><img alt="Text" loading="lazy" """
"""src="http://link.com/with spaces &quot;and quotes&quot;.png" """
"""title="and title" />"""
""" more text</p>"""
)

def test_single_quote(self):
self.assertMarkdownRenders(
"""![test](link"notitle.png)""",
"""<p><img alt="test" src="link&quot;notitle.png" /></p>"""
"""<p><img alt="test" loading="lazy" src="link&quot;notitle.png" /></p>"""
)

def test_angle_with_mixed_title_quotes(self):
self.assertMarkdownRenders(
"""![Text](<http://link.com/with spaces '"and quotes".png> 'and title') more text""",
"""<p><img alt="Text" src="http://link.com/with spaces '&quot;and quotes&quot;.png" title="and title" />"""
"""<p><img alt="Text" loading="lazy" """
"""src="http://link.com/with spaces '&quot;and quotes&quot;.png" """
"""title="and title" />"""
""" more text</p>"""
)

def test_misc(self):
self.assertMarkdownRenders(
"""![Poster](http://humane_man.jpg "The most humane man.")""",
"""<p><img alt="Poster" src="http://humane_man.jpg" title="The most humane man." /></p>"""
"""<p><img alt="Poster" loading="lazy" src="http://humane_man.jpg" """
"""title="The most humane man." /></p>"""
)

def test_misc_ref(self):
@@ -136,27 +146,28 @@ def test_misc_ref(self):
),
self.dedent(
"""
<p><img alt="Poster" src="http://humane_man.jpg" title="The most humane man." /></p>
<p><img alt="Poster" loading="lazy" src="http://humane_man.jpg" title="The most humane man." /></p>
"""
)
)

def test_misc_blank(self):
self.assertMarkdownRenders(
"""![Blank]()""",
"""<p><img alt="Blank" src="" /></p>"""
"""<p><img alt="Blank" loading="lazy" src="" /></p>"""
)

def test_misc_img_title(self):
self.assertMarkdownRenders(
"""![Image](http://humane man.jpg "The most humane man.")""",
"""<p><img alt="Image" src="http://humane man.jpg" title="The most humane man." /></p>"""
"""<p><img alt="Image" loading="lazy" src="http://humane man.jpg" """
"""title="The most humane man." /></p>"""
)

def test_misc_img(self):
self.assertMarkdownRenders(
"""![Image](http://humane man.jpg)""",
"""<p><img alt="Image" src="http://humane man.jpg" /></p>"""
"""<p><img alt="Image" loading="lazy" src="http://humane man.jpg" /></p>"""
)

def test_short_ref(self):
@@ -168,7 +179,7 @@ def test_short_ref(self):
[ref]: ./image.jpg
"""
),
'<p><img alt="ref" src="./image.jpg" /></p>'
'<p><img alt="ref" loading="lazy" src="./image.jpg" /></p>'
)

def test_short_ref_in_link(self):
@@ -180,5 +191,5 @@ def test_short_ref_in_link(self):
[img ref]: ./image.jpg
"""
),
'<p><a href="http://example.com/"><img alt="img ref" src="./image.jpg" /></a></p>'
'<p><a href="http://example.com/"><img alt="img ref" loading="lazy" src="./image.jpg" /></a></p>'
)
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist = py{38, 39, 310, 311, 312}, pypy{38, 39, 310}, pygments, flake8, checkspelling, pep517check, checklinks
envlist = py{38, 39, 310, 311, 312, 313}, pypy{38, 39, 310}, pygments, flake8, checkspelling, pep517check, checklinks
isolated_build = True

[testenv]