Skip to content

Commit 189faf0

Browse files
author
Oleh Prypin
authored
Merge pull request #3297 from mkdocs/regr
Regression fixes
2 parents b1624b5 + bb00d4c commit 189faf0

4 files changed

Lines changed: 32 additions & 15 deletions

File tree

mkdocs/structure/files.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ class File:
190190
url: str
191191
"""The URI of the destination file relative to the destination directory as a string."""
192192

193-
inclusion: InclusionLevel
193+
inclusion: InclusionLevel = InclusionLevel.UNDEFINED
194194
"""Whether the file will be excluded from the built site."""
195195

196196
@property

mkdocs/structure/pages.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,11 @@
44
import logging
55
import posixpath
66
import warnings
7-
from typing import TYPE_CHECKING, Any, Callable, Iterator, MutableMapping
7+
from typing import TYPE_CHECKING, Any, Callable, Iterator, MutableMapping, Sequence
88
from urllib.parse import unquote as urlunquote
99
from urllib.parse import urljoin, urlsplit, urlunsplit
1010

1111
import markdown
12-
import markdown.extensions
13-
import markdown.postprocessors
1412
import markdown.treeprocessors
1513
from markdown.util import AMP_SUBSTITUTE
1614

@@ -22,16 +20,12 @@
2220
if TYPE_CHECKING:
2321
from xml.etree import ElementTree as etree
2422

23+
import markdown.postprocessors
24+
2525
from mkdocs.config.defaults import MkDocsConfig
2626
from mkdocs.structure.files import File, Files
2727
from mkdocs.structure.toc import TableOfContents
2828

29-
_unescape: Callable[[str], str]
30-
try:
31-
_unescape = markdown.treeprocessors.UnescapeTreeprocessor().unescape # type: ignore
32-
except AttributeError:
33-
_unescape = markdown.postprocessors.UnescapePostprocessor().run
34-
3529

3630
log = logging.getLogger(__name__)
3731

@@ -437,6 +431,7 @@ def _register(self, md: markdown.Markdown) -> None:
437431

438432
class _ExtractTitleTreeprocessor(markdown.treeprocessors.Treeprocessor):
439433
title: str | None = None
434+
postprocessors: Sequence[markdown.postprocessors.Postprocessor] = ()
440435

441436
def run(self, root: etree.Element) -> etree.Element:
442437
for el in root:
@@ -446,13 +441,18 @@ def run(self, root: etree.Element) -> etree.Element:
446441
el = copy.copy(el)
447442
del el[-1]
448443
# Extract the text only, recursively.
449-
self.title = _unescape(''.join(el.itertext()))
444+
title = ''.join(el.itertext())
445+
# Unescape per Markdown implementation details.
446+
for pp in self.postprocessors:
447+
title = pp.run(title)
448+
self.title = title
450449
break
451450
return root
452451

453452
def _register(self, md: markdown.Markdown) -> None:
453+
self.postprocessors = tuple(md.postprocessors)
454454
md.treeprocessors.register(
455455
self,
456456
"mkdocs_extract_title",
457-
priority=1, # Close to the end.
457+
priority=-1, # After the end.
458458
)

mkdocs/tests/structure/page_tests.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ def test_page_title_from_markdown_stripped_anchorlinks(self, docs_dir):
352352

353353
_FORMATTING_CONTENT = dedent(
354354
'''
355-
# Hello *beautiful* `world`
355+
# \\*Hello --- *beautiful* `world`
356356
357357
Hi.
358358
'''
@@ -361,11 +361,12 @@ def test_page_title_from_markdown_stripped_anchorlinks(self, docs_dir):
361361
@tempdir(files={'testing_formatting.md': _FORMATTING_CONTENT})
362362
def test_page_title_from_markdown_strip_formatting(self, docs_dir):
363363
cfg = load_config()
364+
cfg.markdown_extensions.append('smarty')
364365
fl = File('testing_formatting.md', docs_dir, docs_dir, use_directory_urls=True)
365366
pg = Page(None, fl, cfg)
366367
pg.read_source(cfg)
367368
pg.render(cfg, fl)
368-
self.assertEqual(pg.title, 'Hello beautiful world')
369+
self.assertEqual(pg.title, '*Hello — beautiful world')
369370

370371
_ATTRLIST_CONTENT = dedent(
371372
'''
@@ -819,6 +820,23 @@ def test_relative_html_link_sub_page(self):
819820
'<a href="sub2/non-index.html">link</a>',
820821
)
821822

823+
def test_relative_doc_link_without_extension(self):
824+
self.assertEqual(
825+
self.get_rendered_result(
826+
use_directory_urls=False,
827+
content='[link](bar/Dockerfile)',
828+
files=['foo/bar.md', 'foo/bar/Dockerfile'],
829+
),
830+
'<a href="bar/Dockerfile">link</a>',
831+
)
832+
self.assertEqual(
833+
self.get_rendered_result(
834+
content='[link](bar/Dockerfile)',
835+
files=['foo/bar.md', 'foo/bar/Dockerfile'],
836+
),
837+
'<a href="Dockerfile">link</a>',
838+
)
839+
822840
def test_relative_html_link_with_encoded_space(self):
823841
self.assertEqual(
824842
self.get_rendered_result(

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,6 @@ dependencies = [
151151
"types-PyYAML",
152152
"types-setuptools",
153153
"typing-extensions",
154-
"click <8.1.4",
155154
]
156155
[tool.hatch.envs.types.scripts]
157156
check = "mypy mkdocs"

0 commit comments

Comments
 (0)