Skip to content

Commit f03ff8e

Browse files
committed
Added functionality to transliterate any language to valid stable html identifiers.
1 parent fbb7f1d commit f03ff8e

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

myst_parser/config/main.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,20 @@ def __repr__(self) -> str:
307307
},
308308
)
309309

310+
fully_normalize_name_slug_func: Callable[[str], str] | None = dc.field(
311+
default=None,
312+
metadata={
313+
"validator": check_heading_slug_func,
314+
"help": (
315+
"Return a case- and whitespace-normalized name."
316+
"or a python import path e.g. `my_package.my_module.my_function`"
317+
"It can be used to transliterate any language to valid stable html identifiers"
318+
),
319+
"global_only": True,
320+
"doc_type": "None | Callable[[str], str] | str",
321+
},
322+
)
323+
310324
html_meta: dict[str, str] = dc.field(
311325
default_factory=dict,
312326
metadata={

myst_parser/mdit_to_docutils/base.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -772,7 +772,11 @@ def generate_heading_target(
772772
# during ref resolution, and is not stored in the document.
773773
# TODO this is purely to mimic docutils, but maybe we don't need it?
774774
# (since we have the slugify logic below)
775-
name = nodes.fully_normalize_name(implicit_text)
775+
776+
if self.md_config.fully_normalize_name_slug_func is not None:
777+
name = self.md_config.fully_normalize_name_slug_func(implicit_text)
778+
else:
779+
name = nodes.fully_normalize_name(implicit_text)
776780
node["names"].append(name)
777781
self.document.note_implicit_target(node, node)
778782

myst_parser/parsers/docutils_.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ def _attr_to_optparse_option(at: Field, default: Any) -> tuple[dict[str, Any], s
139139
"metavar": "<boolean>",
140140
"validator": frontend.validate_boolean,
141141
}, str(default)
142-
if at.type is str or at.name == "heading_slug_func":
142+
if at.type is str or at.name in ("heading_slug_func", "fully_normalize_name_slug_func"):
143143
return {
144144
"metavar": "<str>",
145145
}, f"(default: '{default}')"

0 commit comments

Comments
 (0)