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

change: unique source code span and codeline IDs #200

Open
brynpickering opened this issue Oct 25, 2024 · 2 comments
Open

change: unique source code span and codeline IDs #200

brynpickering opened this issue Oct 25, 2024 · 2 comments
Assignees

Comments

@brynpickering
Copy link

Is your change request related to a problem? Please describe.

When using show_source the code snippet has a span and codelineno ID per line, e.g. </span><span id="__span-0-35"><a id="__codelineno-0-35" name="__codelineno-0-35"></a>.

If referencing the same line in two different code snippets (e.g. the same line from two different modules given on the same page or the same method being referenced as it is inherited from the parent abstract base class in a module), there are duplicate instances of the same spand and codeline ID. Accessibility checkers complain about this, and with good reason!

Describe the solution you'd like

Ideally, each source code snippet would have some kind of unique code (maybe a random hash?) that is added to the IDs.

Describe alternatives you've considered

For now, I've simply ignored these types of IDs in my Accessibility checker, but it is non-ideal...

Additional context

@pawamoy
Copy link
Member

pawamoy commented Oct 25, 2024

Hi @brynpickering, thanks for the change request.

Can you share your config, particularly pymdownx's?

@brynpickering
Copy link
Author

brynpickering commented Nov 15, 2024

Sure:


markdown_extensions:
  - admonition
  - attr_list
  - mkdocs-click
  - tables
  - pymdownx.emoji:
      emoji_index: !!python/name:material.extensions.emoji.twemoji
      emoji_generator: !!python/name:material.extensions.emoji.to_svg
  - pymdownx.highlight:
      anchor_linenums: true
      line_spans: __span
      pygments_lang_class: true
  - pymdownx.inlinehilite:
      style_plain_text: shell
  - pymdownx.details
  - pymdownx.superfences
  - pymdownx.snippets
  - pymdownx.tabbed:
      alternate_style: true
  - toc:
      permalink: "#"
      toc_depth: 3
  - pymdownx.arithmatex:
      generic: true

hooks:
  - docs/static/hooks.py
plugins:
  - search
  - autorefs
  - mkdocs-jupyter:
      include: ["examples/*.ipynb"]
      allow_errors: false
      kernel_name: ntem_synthpop
      include_source: True
      execute: false
  - mkdocstrings:
      default_handler: python
      handlers:
        python:
          options:
            docstring_section_style: spacy
            show_bases: true
            filters:
              - "!^_"
            merge_init_into_class: true
            show_if_no_docstring: true
            signature_crossrefs: true
            show_root_toc_entry: false
            show_signature_annotations: false
          paths: [src]
          import:
            - https://docs.python.org/3/objects.inv

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants