[LyX/master] DocBook/HTML: use XML entities for spaces.

Thibaut Cuvelier tcuvelier at lyx.org
Mon Dec 26 17:14:29 UTC 2022


commit 21d1d917ba0b3da902a1c4648a5fbf3a6d287d75
Author: Thibaut Cuvelier <tcuvelier at lyx.org>
Date:   Mon Dec 26 19:11:41 2022 +0100

    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 files changed, 30 insertions(+), 88 deletions(-)

diff --git a/src/insets/InsetSpace.cpp b/src/insets/InsetSpace.cpp
index 71c7395..6541a30 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 << "&#x2003;"; // HTML:  
-		break;
+		return "&#x2003;"; // HTML:  
 	case InsetSpaceParams::QQUAD:
-		xs << XMLStream::ESCAPE_NONE << "&#x2003;&#x2003;"; // HTML:   
-		break;
+		return "&#x2003;&#x2003;"; // HTML:   
 	case InsetSpaceParams::ENSKIP:
-		xs << XMLStream::ESCAPE_NONE << "&#x2002;"; // HTML:  
-		break;
-	case InsetSpaceParams::PROTECTED:
-		xs << XMLStream::ESCAPE_NONE << "&#xA0;"; // HTML:  
-		break;
+		return "&#x2002;"; // HTML:  
 	case InsetSpaceParams::VISIBLE:
-		xs << XMLStream::ESCAPE_NONE << "&#x2423;";
-		break;
+		return "&#x2423;";
 	case InsetSpaceParams::ENSPACE: // HTML: &#x2060; &#x2060; (word joiners)
-		xs << XMLStream::ESCAPE_NONE << "&#x2060;&#x2002;&#x2060;";
-		break;
+		return "&#x2060;&#x2002;&#x2060;";
 	case InsetSpaceParams::THIN:
-		xs << XMLStream::ESCAPE_NONE << "&#x2009;"; // HTML: &thinspace;
-		break;
+		return "&#x2009;"; // HTML: &thinspace;
 	case InsetSpaceParams::MEDIUM:
-		xs << XMLStream::ESCAPE_NONE << "&#x2005;"; // HTML: &emsp14;
-		break;
+		return "&#x2005;"; // HTML: &emsp14;
 	case InsetSpaceParams::THICK:
-		xs << XMLStream::ESCAPE_NONE << "&#x2004;"; // HTML: &emsp13;
-		break;
+		return "&#x2004;"; // HTML: &emsp13;
+	case InsetSpaceParams::PROTECTED:
 	case InsetSpaceParams::NEGTHIN:
 	case InsetSpaceParams::NEGMEDIUM:
 	case InsetSpaceParams::NEGTHICK:
-		xs << XMLStream::ESCAPE_NONE << "&#xA0;"; // HTML:  
-		break;
+		return "&#xA0;"; // 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 ="&#x2060; &#x2060;";
-		break;
-	case InsetSpaceParams::QQUAD:
-		output ="  ";
-		break;
-	case InsetSpaceParams::THICK:
-		output ="&#x2004;";
-		break;
-	case InsetSpaceParams::QUAD:
-		output =" ";
-		break;
-	case InsetSpaceParams::MEDIUM:
-		output ="&#x2005;";
-		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 ="&#x2423;";
-		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();
 }
 


More information about the lyx-cvs mailing list