• Re: Literals with Spaces in Sphinx

    From Stefan Ram@21:1/5 to Stefan Ram on Fri May 9 18:00:44 2025
    ram@zedat.fu-berlin.de (Stefan Ram) wrote or quoted:
    But if you make these three changes to the Sphinx >"docutils/parsers/rst/states.py" file, it works
    (no guarantees, try it at your own risk!):

    What are those spaces at the start or end of a literal even
    supposed to be good for? They might not be the best idea if you
    think about what HTML or LaTeX could do with them (line break!).
    But I wanted to generate reST, and it made me uneasy to think
    that certain characters just could not be in certain spots . . .

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Stefan Ram@21:1/5 to All on Fri May 9 17:23:01 2025
    In Sphinx reST, you can't put spaces at the beginning or end of
    certain literals and similar things. I think this is more to
    help catch or avoid mistakes than a real technical requirement.

    With three changes to the source code, you can apparently get
    around this restriction, but I have no idea if it always works
    or if it's safe, since I barely tested it and just messed
    around in the Sphinx code without knowing what I was doing.

    Here are the details:

    The following four literals are usually not allowed in Sphinx
    reST source because they start or end with a space:

    abc `` def`` ghi third change

    jkl ``mno `` pqr first change

    stu :literal:` vwx` yza third change

    bcd :literal:`efg ` hij second change

    But if you make these three changes to the Sphinx
    "docutils/parsers/rst/states.py" file, it works
    (no guarantees, try it at your own risk!):

    First change

    Original code

    literal=re.compile(self.non_whitespace_before + '(``)' + end_string_suffix),

    Changed code

    literal=re.compile( '(``)' + end_string_suffix),

    Second change

    Original code

    non_unescaped_whitespace_escape_before = r'(?<!(?<!\x00)[\s\x00])'

    Changed code

    non_unescaped_whitespace_escape_before = r'(?<!(?<!\x00)[\x00])'

    Third change

    Original code

    non_whitespace_after = r'(?!\s)'

    Changed code

    non_whitespace_after = r'()'

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)