Skip to content

Commit

Permalink
Revert "Raise error when pymdownx.details is enabled with mkdocs-mate…
Browse files Browse the repository at this point in the history
…rial, see #47 #44"

This reverts commit c2d4198.
  • Loading branch information
timvink committed May 19, 2021
1 parent cb881d4 commit bb87cd5
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 71 deletions.
4 changes: 1 addition & 3 deletions .pre-commit-config.yaml
Expand Up @@ -23,14 +23,12 @@ repos:
entry: flake8
language: system
types: [python]
args: [--max-line-length=120, --docstring-convention=google, "--ignore=D100,D103,D104,D212,D200,E203,W293,D412,W503,E501"]
args: [--max-line-length=120, --docstring-convention=google, "--ignore=D100,D104,D212,D200,E203,W293,D412,W503"]
# D100 requires all Python files (modules) to have a "public" docstring even if all functions within have a docstring.
# D104 requires __init__ files to have a docstring
# D212
# D200
# D412 No blank lines allowed between a section header and its content
# E203
# E501 line too long (122 > 120 characters)
# D103 Missing docstring in public function
# W293 blank line contains whitespace
# W503 line break before binary operator (for compatibility with black)
12 changes: 0 additions & 12 deletions mkdocs_print_site_plugin/plugin.py
Expand Up @@ -6,7 +6,6 @@
from mkdocs.structure.files import File
from mkdocs.structure.pages import Page
from mkdocs.utils import write_file, copy_file, get_relative_url, warning_filter
from mkdocs.exceptions import ConfigurationError

from mkdocs_print_site_plugin.renderer import Renderer
from mkdocs_print_site_plugin.utils import get_theme_name
Expand Down Expand Up @@ -60,17 +59,6 @@ def on_config(self, config, **kwargs):
msg += "Please update the 'plugins:' section in your mkdocs.yml"
logger.warning(msg)

# There is a bug with mkdocs-material theme and
# the pymdownx.details markdown extension. Detect + raise error.
# Details: https://github.com/squidfunk/mkdocs-material/issues/2655
if "pymdownx.details" in config.get("markdown_extensions", []):
if get_theme_name(config) == "material":
msg = "[mkdocs-print-site-plugin]: Using 'mkdocs-material' theme with "
msg += "the 'pymdownx.details' markdown extension will break printing.\n"
msg += "Please remove 'pymdownx.details' or use a different theme."
msg += "Details: https://github.com/squidfunk/mkdocs-material/issues/2655."
raise ConfigurationError(msg)

# Get abs path to cover_page_template
self.cover_page_template_path = ""
if self.config.get("add_cover_page"):
Expand Down
1 change: 1 addition & 0 deletions tests/fixtures/projects/with_markdown_ext/mkdocs.yml
Expand Up @@ -40,6 +40,7 @@ markdown_extensions:
smart_enable: all
- pymdownx.caret
- pymdownx.critic
- pymdownx.details
- pymdownx.emoji:
emoji_index: !!python/name:materialx.emoji.twemoji
emoji_generator: !!python/name:materialx.emoji.to_svg
Expand Down
29 changes: 0 additions & 29 deletions tests/fixtures/projects/with_markdown_ext/mkdocs_details.yml

This file was deleted.

Expand Up @@ -42,6 +42,7 @@ markdown_extensions:
smart_enable: all
- pymdownx.caret
- pymdownx.critic
- pymdownx.details
- pymdownx.emoji:
emoji_index: !!python/name:materialx.emoji.twemoji
emoji_generator: !!python/name:materialx.emoji.to_svg
Expand Down
Expand Up @@ -41,6 +41,7 @@ markdown_extensions:
smart_enable: all
- pymdownx.caret
- pymdownx.critic
- pymdownx.details
- pymdownx.emoji:
emoji_index: !!python/name:materialx.emoji.twemoji
emoji_generator: !!python/name:materialx.emoji.to_svg
Expand Down
Expand Up @@ -43,6 +43,7 @@ markdown_extensions:
smart_enable: all
- pymdownx.caret
- pymdownx.critic
- pymdownx.details
- pymdownx.emoji:
emoji_index: !!python/name:materialx.emoji.twemoji
emoji_generator: !!python/name:materialx.emoji.to_svg
Expand Down
63 changes: 36 additions & 27 deletions tests/test_building.py
Expand Up @@ -30,27 +30,28 @@

def setup_clean_mkdocs_folder(mkdocs_yml_path, output_path):
"""
Sets up a clean mkdocs directory.
Sets up a clean mkdocs directory
outputpath/testproject
├── docs/
└── mkdocs.yml
Args:
mkdocs_yml_path (Path): Path of mkdocs.yml file to use
output_path (Path): Path of folder in which to create mkdocs project
Returns:
testproject_path (Path): Path to test project
"""

assert os.path.exists(mkdocs_yml_path)

testproject_path = output_path / "testproject"

# Create empty 'testproject' folder
if os.path.exists(str(testproject_path)):
logging.warning(
"""This command does not work on windows.
"""This command does not work on windows.
Refactor your test to use setup_clean_mkdocs_folder() only once"""
)
shutil.rmtree(str(testproject_path))
Expand All @@ -66,28 +67,31 @@ def setup_clean_mkdocs_folder(mkdocs_yml_path, output_path):

def build_docs_setup(testproject_path):
"""
Runs the `mkdocs build` command.
Runs the `mkdocs build` command
Args:
testproject_path (Path): Path to test project
Returns:
command: Object with results of command
"""

cwd = os.getcwd()
os.chdir(str(testproject_path))

try:
run = CliRunner().invoke(build_command, catch_exceptions=True)
os.chdir(cwd)
return run
except Exception:
except:
os.chdir(cwd)
raise


def check_build(tmp_path, project_mkdocs, exit_code=0):
tmp_proj = setup_clean_mkdocs_folder("tests/fixtures/projects/%s" % project_mkdocs, tmp_path)
tmp_proj = setup_clean_mkdocs_folder(
"tests/fixtures/projects/%s" % project_mkdocs, tmp_path
)
result = build_docs_setup(tmp_proj)

msg = "cwd: %s, result: %s, exception: %s, exc_info: %s" % (
Expand All @@ -107,7 +111,7 @@ def text_in_page(tmp_proj, page_path, text):
return re.search(text, contents)


# Tests
#### Tests ####


def test_windmill(tmp_path):
Expand All @@ -118,11 +122,9 @@ def test_no_toc(tmp_path):
prj_path = check_build(tmp_path, "basic/mkdocs_no_toc.yml")

# Table of contents should NOT be there
assert not text_in_page(prj_path, "print_page/index.html", '<div id="print-page-toc"')


def test_pymdownx_details_enabled(tmp_path):
assert check_build(tmp_path, "with_markdown_ext/mkdocs_details.yml", exit_code=1)
assert not text_in_page(
prj_path, "print_page/index.html", '<div id="print-page-toc"'
)


def test_add_to_nav_works(tmp_path):
Expand All @@ -142,7 +144,9 @@ def test_basic_build(tmp_path):
assert text_in_page(prj_path, "print_page/index.html", '<div id="print-page-toc"')

# Make sure all 3 pages are combined and present
assert text_in_page(prj_path, "print_page/index.html", '<h1 id="index-homepage">Homepage')
assert text_in_page(
prj_path, "print_page/index.html", '<h1 id="index-homepage">Homepage'
)
assert text_in_page(prj_path, "print_page/index.html", '<h1 id="a-a">A<')
assert text_in_page(prj_path, "print_page/index.html", '<h1 id="z-z">Z')

Expand All @@ -157,7 +161,9 @@ def test_basic_build2(tmp_path):
assert text_in_page(prj_path, "print_page.html", '<div id="print-page-toc"')

# Make sure all 3 pages are combined and present
assert text_in_page(prj_path, "print_page.html", '<h1 id="index-homepage">Homepage</h1>')
assert text_in_page(
prj_path, "print_page.html", '<h1 id="index-homepage">Homepage</h1>'
)
assert text_in_page(prj_path, "print_page.html", '<h1 id="a-a">A</h1>')
assert text_in_page(prj_path, "print_page.html", '<h1 id="z-z">Z</h1>')

Expand All @@ -169,7 +175,9 @@ def test_basic_build3(tmp_path):
assert text_in_page(prj_path, "index.html", 'class="nav-link">Print Site</a>')

# Make sure all 3 pages are combined and present
assert text_in_page(prj_path, "print_page/index.html", '<h1 id="index-homepage">Homepage</h1>')
assert text_in_page(
prj_path, "print_page/index.html", '<h1 id="index-homepage">Homepage</h1>'
)
assert text_in_page(prj_path, "print_page/index.html", '<h1 id="a-a">A</h1>')
assert text_in_page(prj_path, "print_page/index.html", '<h1 id="z-z">Z</h1>')

Expand All @@ -181,11 +189,13 @@ def test_basic_build4(tmp_path):
assert text_in_page(
prj_path,
"index.html",
'href="print_page/" class="md-nav__link"',
'href="print_page\/" class="md-nav__link"',
)

# Make sure all 3 pages are combined and present
assert text_in_page(prj_path, "print_page/index.html", '<h1 id="index-homepage">Homepage</h1>')
assert text_in_page(
prj_path, "print_page/index.html", '<h1 id="index-homepage">Homepage</h1>'
)
assert text_in_page(prj_path, "print_page/index.html", '<h1 id="a-a">A</h1>')
assert text_in_page(prj_path, "print_page/index.html", '<h1 id="z-z">Z</h1>')

Expand Down Expand Up @@ -230,11 +240,8 @@ def test_exclude_page(tmp_path):
assert not text_in_page(prj_path, "print_page/index.html", "rrI1f2gYE8V4")

# Element in page is ignore (basically 'display: none'), should be present with the right class.
assert text_in_page(
prj_path,
"print_page/index.html",
'<p class="print-site-plugin-ignore">This paragraph is ignored, this unique code should not be found: V5lI1bUdnUI9</p>',
)
assert text_in_page(prj_path, "print_page/index.html", '<p class="print-site-plugin-ignore">This paragraph is ignored, this unique code should not be found: V5lI1bUdnUI9</p>')



def test_basic_build99(tmp_path):
Expand All @@ -245,6 +252,8 @@ def test_basic_build99(tmp_path):
assert text_in_page(prj_path, "index.html", 'class="nav-link">Print Site</a>')

# Make sure all 3 pages are combined and present
assert text_in_page(prj_path, "print_page/index.html", '<h1 id="index-homepage">Homepage')
assert text_in_page(
prj_path, "print_page/index.html", '<h1 id="index-homepage">Homepage'
)
assert text_in_page(prj_path, "print_page/index.html", '<h1 id="a-a">A')
assert text_in_page(prj_path, "print_page/index.html", '<h1 id="z-z">Z')

0 comments on commit bb87cd5

Please sign in to comment.