From 51922943b765a36887461b9290306f9708188b13 Mon Sep 17 00:00:00 2001 From: Michael Osipov Date: Sun, 2 Oct 2022 00:18:38 +0200 Subject: [PATCH] [DOXIA-671] Double quotes contained in markdown page are removed in HTML output Ideally, one would use this list in the future: https://html.spec.whatwg.org/multipage/named-characters.html#named-character-references This closes #123 --- .../maven/doxia/parser/AbstractXmlParser.java | 34 ++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/doxia-core/src/main/java/org/apache/maven/doxia/parser/AbstractXmlParser.java b/doxia-core/src/main/java/org/apache/maven/doxia/parser/AbstractXmlParser.java index c0b1ddb15..f67e3ca6e 100644 --- a/doxia-core/src/main/java/org/apache/maven/doxia/parser/AbstractXmlParser.java +++ b/doxia-core/src/main/java/org/apache/maven/doxia/parser/AbstractXmlParser.java @@ -53,6 +53,7 @@ import org.codehaus.plexus.util.FileUtils; import org.codehaus.plexus.util.IOUtil; import org.codehaus.plexus.util.StringUtils; +import org.codehaus.plexus.util.xml.pull.EntityReplacementMap; import org.codehaus.plexus.util.xml.pull.MXParser; import org.codehaus.plexus.util.xml.pull.XmlPullParser; import org.codehaus.plexus.util.xml.pull.XmlPullParserException; @@ -99,6 +100,18 @@ public abstract class AbstractXmlParser private boolean validate = false; + /** + * If set the parser will be loaded with all single characters + * from the XHTML specification. + * The entities used: + * + */ + private boolean addDefaultEntities = true; + /** {@inheritDoc} */ public void parse( Reader source, Sink sink, String reference ) throws ParseException @@ -128,7 +141,9 @@ public void parse( Reader source, Sink sink, String reference ) // 2 second parsing to process try { - XmlPullParser parser = new MXParser(); + XmlPullParser parser = addDefaultEntities + ? new MXParser( EntityReplacementMap.defaultEntityReplacementMap ) + : new MXParser(); parser.setInput( src ); @@ -578,6 +593,23 @@ public void setValidate( boolean validate ) this.validate = validate; } + /** + * @since 2.0.0-M4 + */ + public boolean getAddDefaultEntities() + { + return addDefaultEntities; + } + + /** + * @since 2.0.0-M4 + */ + public void setAddDefaultEntities( boolean addDefaultEntities ) + { + this.addDefaultEntities = addDefaultEntities; + } + + // ---------------------------------------------------------------------- // Private methods // ----------------------------------------------------------------------