Skip to content

Commit 67ac825

Browse files
authored
Merge pull request #91 from JWCook/ref_label_myst
ENH: Add MyST support and tests for ref labels
2 parents 581f3c0 + 74d01d0 commit 67ac825

File tree

8 files changed

+50
-19
lines changed

8 files changed

+50
-19
lines changed

CHANGELOG.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,18 @@
2020

2121
- Added support for tagging Jupyter Notebooks using `nbsphinx` [gh-51](https://github.com/melissawm/sphinx-tags/pull/51)
2222

23-
## Version 0.3.0
23+
## Version 0.3.0 (October 30, 2023)
2424

2525
- Fixed tag labels with spaces
2626
- Fixed tag labels with emoji
2727
- Added normalization for tag URLs to remove/replace urlencoded characters
2828
- Exclude files that match `exclude_patterns` from being tagged
29+
30+
## Version 0.3.1 (October 31, 2023)
31+
32+
- Fixed doc links and minimum sphinx version
33+
34+
## Unreleased
35+
36+
- Added support for tags in directive body
37+
- Added ref label to tag pages, in the format `sphx_tag_<tagname>`

docs/quickstart.rst

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -42,33 +42,35 @@ Next, add the following configuration setting to ``conf.py``::
4242

4343
tags_create_tags = True
4444

45-
To assign one or more tags to a page in the documentation, use
45+
To assign one or more tags to a page in the documentation, use:
4646

47-
.. code-block:: rst
47+
.. tab-set::
48+
49+
.. tab-item:: rST
50+
51+
.. code-block:: rst
52+
53+
.. tags:: tag1, tag2
54+
55+
.. tab-item:: MyST (Markdown)
56+
57+
.. code-block:: md
4858
49-
.. tags:: tag1, tag2
59+
```{tags} tag1, tag2
60+
```
5061
5162
Tags must be separated by commas, and the tags will be shown in the rendered
52-
html output at the same position in the page as in the source .rst file.
63+
html output at the same position in the page as in the source file.
5364

54-
For each tag, a new rst file is created in ``<output_dir>/<tagname>.rst``
65+
For each tag, a new source file is created in ``<output_dir>/<tagname>.<ext>``
5566
containing a table of contents of each file associated with that tag (see
56-
:ref:`config`). A reference label will be added to this rst file, to enable you to
67+
:ref:`config`). A reference label will be added to this file, to enable you to
5768
cross-reference to it. The reference label will have the format: ``sphx_tag_<tagname>``
5869
e.g., a reference would look like: ``:ref:`sphx_tag_tag1```.
5970

6071
A :ref:`tagoverview` page is also created that can be added to the index and
6172
show all tags defined for this documentation set.
6273

63-
.. note::
64-
65-
If you are using MyST to write your documentation in Markdown, you can use
66-
67-
::
68-
69-
```{tags} tag1, tag2
70-
```
71-
7274
.. note::
7375

7476
If you are using both ``md`` and ``rst`` files, all generated pages will be

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ dependencies = [
2121

2222
[project.optional-dependencies]
2323
sphinx = [
24-
"pydata-sphinx-theme",
24+
"pydata-sphinx-theme>=0.13",
2525
"sphinx-design",
2626
"nbsphinx",
2727
"myst-parser"

src/sphinx_tags/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,12 @@ def create_file(
172172
"""
173173
# Get sorted file paths for tag pages, relative to /docs/_tags
174174
tag_page_paths = sorted([i.relpath(srcdir) for i in items])
175+
ref_label = f"sphx_tag_{self.file_basename}"
175176

176177
content = []
177178
if "md" in extension:
178179
filename = f"{self.file_basename}.md"
180+
content.append(f"({ref_label})=")
179181
content.append(f"# {tags_page_title}: {self.name}")
180182
content.append("")
181183
content.append("```{toctree}")
@@ -189,11 +191,11 @@ def create_file(
189191
else:
190192
filename = f"{self.file_basename}.rst"
191193
header = f"{tags_page_title}: {self.name}"
194+
content.append(f".. _{ref_label}:")
195+
content.append("")
192196
content.append(header)
193197
content.append("#" * textwidth(header))
194198
content.append("")
195-
# Return link block at the start of the page"""
196-
content.append(f".. _sphx_tag_{self.file_basename}:")
197199
content.append(".. toctree::")
198200
content.append(" :maxdepth: 1")
199201
content.append(f" :caption: {tags_page_header}")

test/outputs/general/index.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,9 @@ Test document
5252
* {{🧪test tag; please ignore🧪}} (1)
5353

5454
* Page 2
55+
56+
57+
Test ref
58+
========
59+
60+
My tags: tag_1

test/sources/test-ipynb/index.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,7 @@ Test document
88
page_5
99
subdir/index
1010
_tags/tagsindex
11+
12+
Test ref
13+
--------
14+
:ref:`sphx_tag_tag_1`

test/sources/test-myst/index.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,6 @@ page_5
99
subdir/index
1010
_tags/tagsindex
1111
```
12+
13+
## Test ref
14+
{ref}`sphx_tag_tag_1`

test/sources/test-rst/index.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,8 @@ Test document
99
page_5
1010
subdir/index
1111
_tags/tagsindex
12+
13+
Test ref
14+
--------
15+
16+
:ref:`sphx_tag_tag_1`

0 commit comments

Comments
 (0)