Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hyphen in tag extras file tag list breaks build #6973

Closed
4 tasks done
galthaus opened this issue Mar 25, 2024 · 6 comments
Closed
4 tasks done

hyphen in tag extras file tag list breaks build #6973

galthaus opened this issue Mar 25, 2024 · 6 comments
Labels
bug Issue reports a bug resolved Issue is resolved, yet unreleased if open

Comments

@galthaus
Copy link

Context

No response

Bug description

When adding this to mkdocs.yml, the build breaks.

plugins:
  - tags:
      tags_extra_files:
        tags/object.md:
          - test-automation

Produces stack trace:

ERROR   -  Error reading page 'tags/object.md': bad character range t-a at position 36
Traceback (most recent call last):
  File "/home/galthaus/docs/greg/venv/bin/mkdocs", line 8, in <module>
    sys.exit(cli())
  File "/home/galthaus/docs/greg/venv/lib/python3.8/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
  File "/home/galthaus/docs/greg/venv/lib/python3.8/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
  File "/home/galthaus/docs/greg/venv/lib/python3.8/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/galthaus/docs/greg/venv/lib/python3.8/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/galthaus/docs/greg/venv/lib/python3.8/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
  File "/home/galthaus/docs/greg/venv/lib/python3.8/site-packages/mkdocs/__main__.py", line 286, in build_command
    build.build(cfg, dirty=not clean)
  File "/home/galthaus/docs/greg/venv/lib/python3.8/site-packages/mkdocs/commands/build.py", line 322, in build
    _populate_page(file.page, config, files, dirty)
  File "/home/galthaus/docs/greg/venv/lib/python3.8/site-packages/mkdocs/commands/build.py", line 171, in _populate_page
    page.markdown = config.plugins.on_page_markdown(
  File "/home/galthaus/docs/greg/venv/lib/python3.8/site-packages/mkdocs/plugins.py", line 575, in on_page_markdown
    return self.run_event('page_markdown', markdown, page=page, config=config, files=files)
  File "/home/galthaus/docs/greg/venv/lib/python3.8/site-packages/mkdocs/plugins.py", line 507, in run_event
    result = method(item, **kwargs)
  File "/home/galthaus/docs/greg/venv/lib/python3.8/site-packages/material/plugins/tags/plugin.py", line 163, in on_page_markdown
    markdown = self._handle_deprecated_tags_extra_files(page, markdown)
  File "/home/galthaus/docs/greg/venv/lib/python3.8/site-packages/material/plugins/tags/plugin.py", line 292, in _handle_deprecated_tags_extra_files
    if not re.search(pattern, markdown):
  File "/usr/lib/python3.8/re.py", line 201, in search
    return _compile(pattern, flags).search(string)
  File "/usr/lib/python3.8/re.py", line 304, in _compile
    p = sre_compile.compile(pattern, flags)
  File "/usr/lib/python3.8/sre_compile.py", line 764, in compile
    p = sre_parse.parse(p, flags)
  File "/usr/lib/python3.8/sre_parse.py", line 948, in parse
    p = _parse_sub(source, state, flags & SRE_FLAG_VERBOSE, 0)
  File "/usr/lib/python3.8/sre_parse.py", line 443, in _parse_sub
    itemsappend(_parse(source, state, verbose, nested + 1,
  File "/usr/lib/python3.8/sre_parse.py", line 598, in _parse
    raise source.error(msg, len(this) + 1 + len(that))
re.error: bad character range t-a at position 36

Related links

Reproduction

9.5.15+insiders.4.53.3-hyphen-tags-break-build.zip

Steps to reproduce

  1. Update mkdocs.yml
  2. mkdocs build

Browser

No response

Before submitting

@squidfunk squidfunk added the needs investigation Issue must be investigated by the maintainers label Mar 26, 2024
@alexvoss
Copy link
Sponsor Collaborator

Thanks for reporting and for providing the reproduction. I will have a look to see if I can spot there the issue lies.

Just so you are aware, the Insider Edition version of the tags plugin has seen a significant revision recently that allows you to produce additional tag index pages without using tags_extra_files, which is now deprecated. Existing documentation should still build, of course, so will label this as a bug.

@alexvoss alexvoss added bug Issue reports a bug and removed needs investigation Issue must be investigated by the maintainers labels Mar 26, 2024
@alexvoss
Copy link
Sponsor Collaborator

alexvoss commented Mar 26, 2024

@squidfunk in tags/plugin.py:L291, directive is "material/tags { include: [test-automation] }", so re interprets the part in square brackets as a character set and t-a as a range. Characters with special meanings in regular expressions should be escaped before that line.

I thought that simply adding re.escape() would help but that caused another error. Having another look.

@alexvoss
Copy link
Sponsor Collaborator

alexvoss commented Mar 26, 2024

Looks like in tags/plugin.py:L286 what should be updated is the variable markdown and not page.markdown - cf. _handle_deprecated_tags_file() above.

@squidfunk squidfunk added the resolved Issue is resolved, yet unreleased if open label Mar 27, 2024
@squidfunk
Copy link
Owner

Fixed in 4ff6a57 by @alexvoss 🎉

@galthaus
Copy link
Author

Awesome. I'll look into moving off the tag_extra_files.

@squidfunk
Copy link
Owner

squidfunk commented Mar 31, 2024

Released as part of 9.5.16+insiders-4.53.4.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue reports a bug resolved Issue is resolved, yet unreleased if open
Projects
None yet
Development

No branches or pull requests

3 participants