From 21d1d917ba0b3da902a1c4648a5fbf3a6d287d75 Mon Sep 17 00:00:00 2001 From: Thibaut Cuvelier Date: Mon, 26 Dec 2022 19:11:41 +0100 Subject: [PATCH] DocBook/HTML: use XML entities for spaces. This part should have been committed with bc73a857 in the first place. --- src/insets/InsetSpace.cpp | 118 ++++++++++---------------------------- 1 file changed, 30 insertions(+), 88 deletions(-) diff --git a/src/insets/InsetSpace.cpp b/src/insets/InsetSpace.cpp index 71c73951db..6541a3024c 100644 --- a/src/insets/InsetSpace.cpp +++ b/src/insets/InsetSpace.cpp @@ -774,44 +774,36 @@ int InsetSpace::plaintext(odocstringstream & os, } -void InsetSpace::docbook(XMLStream & xs, OutputParams const &) const -{ - switch (params_.kind) { +namespace { +std::string spaceToXMLEntity(InsetSpaceParams::Kind kind) { + switch (kind) { case InsetSpaceParams::NORMAL: - xs << XMLStream::ESCAPE_NONE << " "; - break; + return " "; case InsetSpaceParams::QUAD: - xs << XMLStream::ESCAPE_NONE << " "; // HTML:   - break; + return " "; // HTML:   case InsetSpaceParams::QQUAD: - xs << XMLStream::ESCAPE_NONE << "  "; // HTML:    - break; + return "  "; // HTML:    case InsetSpaceParams::ENSKIP: - xs << XMLStream::ESCAPE_NONE << " "; // HTML:   - break; - case InsetSpaceParams::PROTECTED: - xs << XMLStream::ESCAPE_NONE << " "; // HTML:   - break; + return " "; // HTML:   case InsetSpaceParams::VISIBLE: - xs << XMLStream::ESCAPE_NONE << "␣"; - break; + return "␣"; case InsetSpaceParams::ENSPACE: // HTML: ⁠ ⁠ (word joiners) - xs << XMLStream::ESCAPE_NONE << "⁠ ⁠"; - break; + return "⁠ ⁠"; case InsetSpaceParams::THIN: - xs << XMLStream::ESCAPE_NONE << " "; // HTML: &thinspace; - break; + return " "; // HTML: &thinspace; case InsetSpaceParams::MEDIUM: - xs << XMLStream::ESCAPE_NONE << " "; // HTML:   - break; + return " "; // HTML:   case InsetSpaceParams::THICK: - xs << XMLStream::ESCAPE_NONE << " "; // HTML:   - break; + return " "; // HTML:   + case InsetSpaceParams::PROTECTED: case InsetSpaceParams::NEGTHIN: case InsetSpaceParams::NEGMEDIUM: case InsetSpaceParams::NEGTHICK: - xs << XMLStream::ESCAPE_NONE << " "; // HTML:   - break; + return " "; // HTML:   + case InsetSpaceParams::CUSTOM_PROTECTED: + // FIXME XHTML/DocBook + // Probably we could do some sort of blank span? + return " "; case InsetSpaceParams::HFILL: case InsetSpaceParams::HFILL_PROTECTED: case InsetSpaceParams::DOTFILL: @@ -821,74 +813,24 @@ void InsetSpace::docbook(XMLStream & xs, OutputParams const &) const case InsetSpaceParams::UPBRACEFILL: case InsetSpaceParams::DOWNBRACEFILL: case InsetSpaceParams::CUSTOM: - case InsetSpaceParams::CUSTOM_PROTECTED: - xs << '\n'; - break; + // FIXME XHTML/DocBook + // Can we do anything with those? + return "\n"; } + return ""; +} +} + + +void InsetSpace::docbook(XMLStream & xs, OutputParams const &) const +{ + xs << XMLStream::ESCAPE_NONE << from_ascii(spaceToXMLEntity(params_.kind)); } docstring InsetSpace::xhtml(XMLStream & xs, OutputParams const &) const { - string output; - switch (params_.kind) { - case InsetSpaceParams::NORMAL: - output = " "; - break; - case InsetSpaceParams::ENSKIP: - output =" "; - break; - case InsetSpaceParams::ENSPACE: - output ="⁠ ⁠"; - break; - case InsetSpaceParams::QQUAD: - output ="  "; - break; - case InsetSpaceParams::THICK: - output =" "; - break; - case InsetSpaceParams::QUAD: - output =" "; - break; - case InsetSpaceParams::MEDIUM: - output =" "; - break; - case InsetSpaceParams::THIN: - output =" "; - break; - case InsetSpaceParams::PROTECTED: - case InsetSpaceParams::NEGTHIN: - case InsetSpaceParams::NEGMEDIUM: - case InsetSpaceParams::NEGTHICK: - output =" "; - break; - // no XML entity, only Unicode code for space character exists - case InsetSpaceParams::VISIBLE: - output ="␣"; - break; - case InsetSpaceParams::HFILL: - case InsetSpaceParams::HFILL_PROTECTED: - case InsetSpaceParams::DOTFILL: - case InsetSpaceParams::HRULEFILL: - case InsetSpaceParams::LEFTARROWFILL: - case InsetSpaceParams::RIGHTARROWFILL: - case InsetSpaceParams::UPBRACEFILL: - case InsetSpaceParams::DOWNBRACEFILL: - // FIXME XHTML - // Can we do anything with those in HTML? - break; - case InsetSpaceParams::CUSTOM: - // FIXME XHTML - // Probably we could do some sort of blank span? - break; - case InsetSpaceParams::CUSTOM_PROTECTED: - // FIXME XHTML - // Probably we could do some sort of blank span? - output =" "; - break; - } - // don't escape the entities! - xs << XMLStream::ESCAPE_NONE << from_ascii(output); + xs << XMLStream::ESCAPE_NONE << from_ascii(spaceToXMLEntity(params_.kind)); return docstring(); }