Skip to content

Support stable heading id for non english languages #968

Closed

Description

@Alexey-NM

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?

Activity

  1. Alexey-NM commented on Aug 26, 2024

    @Alexey-NM
    Author

    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,
            }
        )
    
  2. chrisjsewell commented on Aug 27, 2024

    @chrisjsewell
    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)

  3. Alexey-NM commented on Aug 27, 2024

    @Alexey-NM
    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
  4. Alexey-NM commented on Jan 27, 2025

    @Alexey-NM
    Author

    We have implemented pull request which allows to do it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions