Skip to content

Commit

Permalink
document make_xml_id
Browse files Browse the repository at this point in the history
Co-authored-by: Konstantin Baierer <kba@users.noreply.github.com>
  • Loading branch information
bertsky and kba authored Aug 16, 2024
1 parent ace2a7b commit c2b583c
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/ocrd_utils/str.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ def make_file_id(ocrd_file, output_file_grp):
return make_xml_id(ret)

def make_xml_id(idstr: str) -> str:
"""
Turn ``idstr`` into a valid ``xml:id`` literal by replacing ``:`` with ``_``, removing everything non-alphanumeric, ``.`` and ``-`` and prepending `id_` if ``idstr`` starts with a number.
"""
ret = idstr
if not REGEX_FILE_ID.fullmatch(ret):
ret = ret.replace(':', '_')
Expand Down

0 comments on commit c2b583c

Please sign in to comment.