Skip to content

Incorrect id Assignment in add_id_to_html_tag Function #413

@dr-rafis

Description

@dr-rafis

Description

The function add_id_to_html_tag contains a bug that causes incorrect ID assignment when generating HTML tags with specific configurations.

Current Behavior

In the current implementation, the id and id[:8] assignments are swapped based on the configuration flags add_ids_to_html_tags and add_short_ids_to_html_tags. This results in:

  • id[:8] being assigned when config.add_ids_to_html_tags is True.
  • The full id being assigned when config.add_short_ids_to_html_tags is True.

Expected Behavior

The logic should be reversed:

  • The full id should be assigned when config.add_ids_to_html_tags is True.
  • id[:8] should be assigned when config.add_short_ids_to_html_tags is True.

Current Code

def add_id_to_html_tag(prefix, id, config):
    if not isinstance(config, HTMLLinearizationConfig) or not prefix:
        return prefix
    if config.add_ids_to_html_tags:
        return prefix[:-1] + f' id="{id[:8]}"' + prefix[-1]
    elif config.add_short_ids_to_html_tags:
        return prefix[:-1] + f' id="{id}"' + prefix[-1]
    else:
        return prefix

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions