tobiasah / mkdocs-caption

MkDocs plugin to add captions and easy element numbering
MIT License
3 stars 2 forks source link

Missing auto-text-generation for cross-referencing in multi-page documentation. #17

Closed leiwu84 closed 1 week ago

leiwu84 commented 2 months ago

I have defined a table in the table.md file, this tool will automatically assign a number to this table, e.g. Table 1. If I refer it in the same file, the reference text will show Table 1. However, if I reference it in another file text.md, then Table 1 is not shown. Is it possible to automatically generate the reference text like <Page Name>/<Table Number>, like Tables/Table 1? The <Page Name> is defined in the mkdocs.yml file, nav section.

Here is an complete example.

Structure

mkdocs.yml
|
docs
   |_index.md
   |_table.md
   |_text.md

index.md file.

This is the home page.

table.md file.

Some text.

Table: table caption {#my-table}

| heading 1| heading 2 | 
| - | - | 
| content 1 | content 2 |
| content 3 | content 4 |

See [](#my-table) for more details.

Here Table 1 is shown at the reference place as expected.

text.md file.

See [](table.md#my-table) in that page.

Here Table 1 is not shown at the reference place. I would like to see something like Table/Table 1. The first Table is the page name

mkdocs.yml file

site_name: My Docs
docs_dir: docs
theme:
  name: material
  features:
    - navigation.expand
    - navigation.top
    - search.suggest
    - search.highlight
    - content.tabs.link
    - content.code.annotation
    - content.code.copy
  language: en
  palette:
    - scheme: default
      toggle:
        icon: material/toggle-switch-off-outline
        name: Switch to dark mode
      primary: teal
      accent: purple
    - scheme: slate
      toggle:
        icon: material/toggle-switch
        name: Switch to light mode
      primary: teal
      accent: lime

extra_javascript:
  - javascripts/mathjax.js
  - https://polyfill.io/v3/polyfill.min.js?features=es6
  - https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js

plugins:
  - autorefs
  - search
  - caption:
      table:
        position: top

markdown_extensions:
  - pymdownx.highlight:
      anchor_linenums: true
  - pymdownx.inlinehilite
  - pymdownx.snippets
  - admonition
  - pymdownx.arithmatex:
      generic: true
  - footnotes
  - pymdownx.details
  - pymdownx.mark
  - pymdownx.tasklist:
      custom_checkbox: true
  - attr_list
  - md_in_html
  - pymdownx.superfences
  - pymdownx.tabbed:
      alternate_style: true
  - pymdownx.emoji:
      emoji_index: !!python/name:material.extensions.emoji.twemoji
      emoji_generator: !!python/name:material.extensions.emoji.to_svg

nav:
  - Home: index.md
  - Table: table.md
  - Text: text.md
tobiasah commented 2 months ago

Thanks for filing this issue.

Yes, for now, the cross-reference resolution with the right tag is not supported across pages.

It should, however, be possible to do.

Can you elaborate more on the expected outcome? Should it somehow be accounted that, e.g., the table is on another page?

leiwu84 commented 2 months ago

Thanks for the quick response. I just updated the description above. In short, is it possible to automatically generate the reference text like <Page Name>/<Table Number>, like Tables/Table 1? The <Page Name> is defined in the mkdocs.yml file, nav section.

tobiasah commented 1 month ago

Sorry it took so long ... I finally had some spare time to give your request/idea a shot.

I created a draft here, #18. It's not finished, as I have not adapted the tests yet, and I want to allow this feature to be customizable through the config. (I also expect that there are a few subtle issues, e.g if no page title is defined)

Could you give it a try and give me some feedback?

I will try to finish up the PR in the upcoming week.

leiwu84 commented 1 week ago

Hi @tobiasah , thanks a lot for creating this feature. I have tested on my laptop, it works perfectly.

tobiasah commented 1 week ago

@leiwu84, thanks for the feedback. I fixed the remaining issues and merged the change. It has already been released with 1.2.0

FYI, in case you want to change the link text, you can use the cross_reference_text config field: https://tobiasah.github.io/mkdocs-caption/config/#default