Skip to content

Commit e24af7d

Browse files
committed
Switch to new handling of headings
From mkdocstrings/mkdocstrings#209
1 parent 9ee0d4c commit e24af7d

5 files changed

Lines changed: 15 additions & 27 deletions

File tree

mkdocstrings/handlers/crystal/renderer.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def get_anchor(self, data: DocItem) -> str:
4141
return data.abs_id
4242

4343
def update_env(self, md: Markdown, config: dict) -> None:
44-
md = Markdown(extensions=config["mdx"], extension_configs=config["mdx_configs"])
44+
super().update_env(md, config)
4545
self._md = md
4646

4747
self._pymdownx_hl = None
@@ -55,8 +55,6 @@ def update_env(self, md: Markdown, config: dict) -> None:
5555
del md.preprocessors["html_block"]
5656
del md.inlinePatterns["html"]
5757

58-
base.ShiftHeadingsExtension().extendMarkdown(md)
59-
base.PrefixIdsExtension().extendMarkdown(md)
6058
md.treeprocessors.register(_RefInsertingTreeprocessor(md), "mkdocstrings_crystal_xref", 12)
6159

6260
self.env.trim_blocks = True
@@ -92,9 +90,7 @@ def do_reference(self, path: Union[str, DocPath], text: Optional[str] = None) ->
9290

9391
def do_convert_markdown(self, text: str, context: DocItem, heading_level: int, html_id: str):
9492
self._md.treeprocessors["mkdocstrings_crystal_xref"].context = context
95-
return base.do_convert_markdown(
96-
self._md, text, heading_level=heading_level, html_id=html_id
97-
)
93+
return super().do_convert_markdown(text, heading_level=heading_level, html_id=html_id)
9894

9995
def _monkeypatch_highlight_function(self, default_lang: str):
10096
"""Changes 'pymdownx.highlight' extension to use this lang by default."""

mkdocstrings/templates/crystal/material/constant.html

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
{{ log.debug() }}
22

33
<div class="doc doc-object doc-{{ obj.kind }}">
4-
<h{{ heading_level }}
5-
id="{{ obj.abs_id }}"
6-
class="doc doc-heading"
7-
data-toc-label="{{ obj.name }}">
8-
4+
{% filter heading(heading_level, id=obj.abs_id, class="doc doc-heading", toc_label=obj.name) %}
95
<code>
106
{{ obj.name }} = <span style="font-weight: normal">{{ obj.value |code_highlight(language="crystal", inline=True) }}</span>
117
</code>
12-
</h{{ heading_level }}>
8+
{% endfilter %}
139

1410
<div class="doc doc-contents {% if root %}first{% endif %}">
1511
{% if obj.doc %}{{ obj.doc |convert_markdown(obj, heading_level, obj.abs_id) }}{% endif %}

mkdocstrings/templates/crystal/material/method.html

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
{{ log.debug() }}
22

33
<div class="doc doc-object doc-method doc-{{ obj.kind }}">
4-
<h{{ heading_level }}
5-
id="{{ obj.abs_id }}"
6-
class="doc doc-heading"
7-
data-toc-label="{{ obj.short_name }}">
8-
4+
{% filter heading(heading_level, id=obj.abs_id, class="doc doc-heading", toc_label=obj.short_name) %}
95
{% if obj.is_abstract %}<small style="font-weight: normal">abstract</small> {% endif %}
106
<code>
117
{{ obj.short_name }}<span style="font-weight: normal">{{ obj.args_string |code_highlight(language="crystal", inline=True) }}</span>
128
</code>
13-
</h{{ heading_level }}>
9+
{% endfilter %}
1410

1511
<div class="doc doc-contents {% if root %}first{% endif %}">
1612
{% if obj.doc %}{{ obj.doc |convert_markdown(obj, heading_level, obj.abs_id) }}{% endif %}

mkdocstrings/templates/crystal/material/type.html

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,12 @@
22

33
<div class="doc doc-object doc-type {{ obj.kind }}">
44
{% if obj.parent %}
5-
<h{{ heading_level }}
6-
id="{{ obj.abs_id }}"
7-
class="doc doc-heading"
8-
data-toc-label="{{ obj.name }}">
9-
5+
{% filter heading(heading_level, id=obj.abs_id, class="doc doc-heading", toc_label=obj.name) %}
106
{% if obj.is_abstract %}abstract {% endif %}{{ obj.kind }} <code>{{ obj.full_name }}</code>
117
{% if obj.superclass %}
128
<br/><small>inherits <code>{{ obj.superclass |reference }}</code></small>
139
{% endif %}
14-
</h{{ heading_level }}>
10+
{% endfilter %}
1511
{% endif %}
1612

1713
<div class="doc doc-contents {% if root %}first{% endif %}">
@@ -39,7 +35,11 @@
3935
{% endfor %}
4036

4137
{% if obj.constants %}
42-
<h{{ heading_level }}>{% if obj.kind == "enum" %}Members{% else %}Constants{% endif %}</h{{ heading_level }}>
38+
{% if obj.kind == "enum" %}
39+
{% filter heading(heading_level, id=obj.abs_id ~ "-members") %}Members{% endfilter %}
40+
{% else %}
41+
{% filter heading(heading_level, id=obj.abs_id ~ "-constants") %}Constants{% endfilter %}
42+
{% endif %}
4343
{% with heading_level = heading_level + 1 %}
4444
{% for obj in obj.constants %}
4545
{% include "constant.html" with context %}
@@ -53,7 +53,7 @@
5353
("Macros", obj.macros),
5454
] %}
5555
{% if sub %}
56-
<h{{ heading_level }}>{{ title }}</h{{ heading_level }}>
56+
{% filter heading(heading_level, id=obj.abs_id ~ "-" ~ title.lower().replace(" ", "-")) %}{{ title }}{% endfilter %}
5757
{% with heading_level = heading_level + 1 %}
5858
{% for obj in sub %}
5959
{% include "method.html" with context %}

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ deduplicate-toc = "mkdocstrings.handlers.crystal.deduplicate_toc:DeduplicateTocE
1616

1717
[tool.poetry.dependencies]
1818
python = "^3.7"
19-
mkdocstrings = ">=0.14.0b1"
19+
mkdocstrings = "^0.15.0"
2020
mkdocs-material = "^6.0.2"
2121
markupsafe = "^1.1.1"
2222
cached-property = "^1.5.2"

0 commit comments

Comments
 (0)