Commit ec71d0da authored by pennae's avatar pennae
Browse files

docs/nrd: move make_xml_id to manual_structure

since we don't want to break links and changing the id generation scheme
would Very Break links this id generation function is unfortunately
somewhat part of the manual structure now, so we may as well put it there.
parent 02aff756
Loading
Loading
Loading
Loading
+0 −13
Original line number Diff line number Diff line
@@ -6,19 +6,6 @@ from xml.sax.saxutils import escape, quoteattr

from .md import Renderer

_xml_id_translate_table = {
    ord('*'): ord('_'),
    ord('<'): ord('_'),
    ord(' '): ord('_'),
    ord('>'): ord('_'),
    ord('['): ord('_'),
    ord(']'): ord('_'),
    ord(':'): ord('_'),
    ord('"'): ord('_'),
}
def make_xml_id(s: str) -> str:
    return s.translate(_xml_id_translate_table)

class Deflist:
    has_dd = False

+2 −2
Original line number Diff line number Diff line
@@ -13,9 +13,9 @@ from typing import Any, Callable, cast, ClassVar, Generic, get_args, NamedTuple
from markdown_it.token import Token

from . import md, options
from .docbook import DocBookRenderer, Heading, make_xml_id
from .docbook import DocBookRenderer, Heading
from .html import HTMLRenderer, UnresolvedXrefError
from .manual_structure import check_structure, FragmentType, is_include, TocEntry, TocEntryType, XrefTarget
from .manual_structure import check_structure, FragmentType, is_include, make_xml_id, TocEntry, TocEntryType, XrefTarget
from .md import Converter, Renderer

class BaseConverter(Converter[md.TR], Generic[md.TR]):
+17 −0
Original line number Diff line number Diff line
@@ -201,3 +201,20 @@ class TocEntry(Freezeable):
        while len(entries) > 1:
            entries[-2][1].children.append(entries.pop()[1])
        return (entries[0][1], examples, figures)

_xml_id_translate_table = {
    ord('*'): ord('_'),
    ord('<'): ord('_'),
    ord(' '): ord('_'),
    ord('>'): ord('_'),
    ord('['): ord('_'),
    ord(']'): ord('_'),
    ord(':'): ord('_'),
    ord('"'): ord('_'),
}
# this function is needed to generate option id attributes in the same format as
# the docbook toolchain did to not break existing links. we don't actually use
# xml any more, that's just the legacy we're dealing with and part of our structure
# now.
def make_xml_id(s: str) -> str:
    return s.translate(_xml_id_translate_table)
+2 −2
Original line number Diff line number Diff line
@@ -17,10 +17,10 @@ from . import md
from . import parallel
from .asciidoc import AsciiDocRenderer, asciidoc_escape
from .commonmark import CommonMarkRenderer
from .docbook import DocBookRenderer, make_xml_id
from .docbook import DocBookRenderer
from .html import HTMLRenderer
from .manpage import ManpageRenderer, man_escape
from .manual_structure import XrefTarget
from .manual_structure import make_xml_id, XrefTarget
from .md import Converter, md_escape, md_make_code
from .types import OptionLoc, Option, RenderedOption