diff --git a/src/mkdocs/extensions/relative_urls.py b/src/mkdocs/extensions/relative_urls.py index edb91b4..9f12174 100644 --- a/src/mkdocs/extensions/relative_urls.py +++ b/src/mkdocs/extensions/relative_urls.py @@ -1,8 +1,7 @@ import markdown import mkdocs import os -import posixpath -import httpx +import hip class URLProcessor(markdown.treeprocessors.Treeprocessor): @@ -26,7 +25,7 @@ def run(self, root): if link: el.set(key, link) - url = httpx.URL(link) + url = hip.URL(link) # We want to rewrite relative links... '/page' # We don't want to rewrite external links. 'https://elsewhere.com/here' # We don't want to rewrite anchor links. '#section' diff --git a/src/mkdocs/mkdocs.py b/src/mkdocs/mkdocs.py index 6555713..41b2322 100644 --- a/src/mkdocs/mkdocs.py +++ b/src/mkdocs/mkdocs.py @@ -251,9 +251,15 @@ def build(self, input, output): input_dir = pathlib.Path(input) output_dir = pathlib.Path(output) - print(DARK_GRAY + "Collected %d resources" % len(self.site) + RESET) + click.echo( + click.style("Collected %d resources" % len(self.site), fg='bright_black') + ) for page in self.site.pages: - print(GREEN + " + " + RESET + BOLD + str(page.path) + RESET + DARK_GRAY + " [markdown]" + RESET) + click.echo( + click.style(" + ", fg='green') + + click.style(str(page.path), bold=True) + + click.style(" [markdown]", fg='bright_black') + ) input_path = input_dir.joinpath(page.path) output_path = output_dir.joinpath(page.build_path) @@ -268,7 +274,11 @@ def build(self, input, output): output_path.write_text(output) for static in self.site.statics: - print(GREEN + " + " + RESET + BOLD + str(static.path) + RESET + DARK_GRAY + " [static]" + RESET) + click.echo( + click.style(" + ", fg='green') + + click.style(str(static.path), bold=True) + + click.style(" [static]", fg='bright_black') + ) input_path = input_dir.joinpath(static.path) output_path = output_dir.joinpath(static.path) @@ -278,12 +288,22 @@ def build(self, input, output): def serve(self, input): input_dir = pathlib.Path(input) - print(DARK_GRAY + "Serving %d resources" % len(self.site) + RESET) + click.echo( + click.style("Serving %d resources" % len(self.site), fg='bright_black') + ) for page in self.site.pages: - print(GREEN + " + " + RESET + BOLD + str(page.url) + RESET + DARK_GRAY + " [markdown]" + RESET) + click.echo( + click.style(" + ", fg='green') + + click.style(str(page.url), bold=True) + + click.style(" [markdown]", fg='bright_black') + ) for static in self.site.statics: - print(GREEN + " + " + RESET + BOLD + str(static.url) + RESET + DARK_GRAY + " [static]" + RESET) - print() + click.echo( + click.style(" + ", fg='green') + + click.style(str(static.url), bold=True) + + click.style(" [static]", fg='bright_black') + ) + click.echo() def app(request): resource = self.site.lookup_by_url(request.url.path) diff --git a/tests/test_mkdocs.py b/tests/test_mkdocs.py index c9cceba..b74b1e6 100644 --- a/tests/test_mkdocs.py +++ b/tests/test_mkdocs.py @@ -1,8 +1,10 @@ from click.testing import CliRunner +import os import mkdocs +import pathlib -def test_mkdocs(): +def test_mkdocs_help(): runner = CliRunner() result = runner.invoke(mkdocs.mkdocs, ['--help']) assert result.exit_code == 0 @@ -16,3 +18,30 @@ def test_mkdocs(): ' build\n' ' serve\n' ) + + +def test_mkdocs_build(tmp_path: pathlib.Path): + # Setup + os.chdir(tmp_path) + + docs = tmp_path / "docs" + docs.mkdir() + + readme = docs / "README.md" + readme.write_text("# README\n\nhello world!\n") + + site = tmp_path / "site" + + homepage = site / "index.html" + + # Test + runner = CliRunner() + result = runner.invoke(mkdocs.mkdocs, ['build']) + assert result.exit_code == 0 + assert result.output == ( + 'Collected 1 resources\n' + ' + README.md [markdown]\n' + ) + assert site.exists() + assert homepage.exists() + assert "
hello world!
" in homepage.read_text()