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

Support stable heading id for non english languages #968

Open
Alexey-NM opened this issue Aug 26, 2024 · 3 comments
Open

Support stable heading id for non english languages #968

Alexey-NM opened this issue Aug 26, 2024 · 3 comments
Labels
enhancement New feature or request

Comments

@Alexey-NM
Copy link

Alexey-NM commented Aug 26, 2024

Feature

I need ability to make refrences to headers from external documentation (some_chapter.html#zagalovok).
Unfortunately If I have a title in a non english language it will have numeric id which can be changed in any time.
It is difficult to automate and it is unstable because such number can be changed at any time.

<section id="id2">

Solution

I want to have the ablility to define the id generation function in my conf.py to a function that accepts a string and returns a stable id.

The function will generate stable id by a node title.

<section id="zagalovok">

I have maken some test in the function generate_heading_target

name = nodes.fully_normalize_name(implicit_text)
name = conf.make_id_by_any_lang(name)

It seems It is working.

Will it be accepted If I make a pull request?

@Alexey-NM Alexey-NM added the enhancement New feature or request label Aug 26, 2024
@Alexey-NM
Copy link
Author

Alexey-NM commented Aug 26, 2024

Alternative decision is to add ability configuring custom markdown plugins.
A plugin can add id to token similar to attrs_block extension

It is not difficult to add custom function to configure md in create_md_parser

    custom_md_config(md)
    md.options.update(
        {
            "typographer": typographer,
            "linkify": "linkify" in config.enable_extensions,
            "myst_config": config,
        }
    )

@chrisjsewell
Copy link
Member

Heya, what exactly does make_id_by_any_lang do, how is it different to

name = nodes.fully_normalize_name(implicit_text)
node["names"].append(name)

@Alexey-NM
Copy link
Author

what exactly does make_id_by_any_lang do, how is it different to

It generates an english name from other language. It allows to use static id.

def make_id_by_any_lang(str:str)->str:
    # see https://pypi.org/project/transliterate/
    tr_str = translit(str,"ru",reversed=True)
    #This function is a modified version of ``docutils.nodes.make_id()`` of
    #docutils-0.16
    # It is test code so probably it is not nessasary
    result = _make_id(tr_str).lower()
    return result

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

No branches or pull requests

2 participants