Commit 3b581af6 authored by Michael Hamann's avatar Michael Hamann
Browse files

XRENDERING-668: Attributes starting with data-xwiki- aren't preserved during XHTML parsing

* Only remove attributes when the tag is a metadata tag.
* Add tests.
parent 8a853327
......@@ -217,31 +217,32 @@ private static WikiParameters cleanParametersFromMetadata(WikiParameters paramet
@Override
protected void beginGroup(WikiParameters parameters)
{
boolean withoutMetadata = true;
if (isMetaDataElement(parameters)) {
MetaData metaData = createMetaData(parameters);
getListener().beginMetaData(metaData);
withoutMetadata = false;
}
WikiParameters cleanParameters = cleanParametersFromMetadata(parameters);
if (withoutMetadata || cleanParameters.getSize() > 0) {
super.beginGroup(cleanParameters);
WikiParameters cleanParameters = cleanParametersFromMetadata(parameters);
if (cleanParameters.getSize() > 0) {
super.beginGroup(cleanParameters);
}
} else {
super.beginGroup(parameters);
}
}
@Override
protected void endGroup(WikiParameters parameters)
{
boolean withoutMetadata = true;
if (isMetaDataElement(parameters)) {
getListener().endMetaData(createMetaData(parameters));
withoutMetadata = false;
}
MetaData metaData = createMetaData(parameters);
getListener().endMetaData(metaData);
WikiParameters cleanParameters = cleanParametersFromMetadata(parameters);
if (withoutMetadata || cleanParameters.getSize() > 0) {
super.endGroup(cleanParameters);
WikiParameters cleanParameters = cleanParametersFromMetadata(parameters);
if (cleanParameters.getSize() > 0) {
super.endGroup(cleanParameters);
}
} else {
super.endGroup(parameters);
}
}
......@@ -250,20 +251,19 @@ public void beginFormat(WikiFormat format)
{
WikiParameters wikiParameters = new WikiParameters(format.getParams());
boolean withoutMetadata = true;
if (isMetaDataElement(wikiParameters)) {
getListener().beginMetaData(createMetaData(wikiParameters));
withoutMetadata = false;
}
WikiParameters cleanParameters = cleanParametersFromMetadata(wikiParameters);
if (withoutMetadata || cleanParameters.getSize() > 0 || !format.getStyles().isEmpty()) {
WikiFormat newFormat = format;
if (wikiParameters.getSize() != cleanParameters.getSize()) {
newFormat = format.setParameters(cleanParameters.toList());
WikiParameters cleanParameters = cleanParametersFromMetadata(wikiParameters);
if (cleanParameters.getSize() > 0 || !format.getStyles().isEmpty()) {
WikiFormat newFormat = format;
if (wikiParameters.getSize() != cleanParameters.getSize()) {
newFormat = format.setParameters(cleanParameters.toList());
}
super.beginFormat(newFormat);
}
super.beginFormat(newFormat);
} else {
super.beginFormat(format);
}
}
......@@ -272,20 +272,20 @@ public void endFormat(WikiFormat format)
{
WikiParameters wikiParameters = new WikiParameters(format.getParams());
boolean withoutMetadata = true;
if (isMetaDataElement(wikiParameters)) {
getListener().endMetaData(createMetaData(wikiParameters));
withoutMetadata = false;
}
WikiParameters cleanParameters = cleanParametersFromMetadata(wikiParameters);
if (withoutMetadata || cleanParameters.getSize() > 0 || !format.getStyles().isEmpty()) {
WikiFormat newFormat = format;
if (wikiParameters.getSize() != cleanParameters.getSize()) {
newFormat = format.setParameters(cleanParameters.toList());
}
WikiParameters cleanParameters = cleanParametersFromMetadata(wikiParameters);
if (cleanParameters.getSize() > 0 || !format.getStyles().isEmpty()) {
WikiFormat newFormat = format;
if (wikiParameters.getSize() != cleanParameters.getSize()) {
newFormat = format.setParameters(cleanParameters.toList());
}
super.endFormat(newFormat);
super.endFormat(newFormat);
}
} else {
super.endFormat(format);
}
}
}
......@@ -2,18 +2,18 @@
.input|xhtml/1.0
.# Verify that STRONG tag parameters are recognized.
.#-----------------------------------------------------
<p><strong a="b">something</strong></p>
<p><strong a="b" data-xwiki-parameter="value">something</strong></p>
.#-----------------------------------------------------
.expect|event/1.0
.#-----------------------------------------------------
beginDocument
beginParagraph
beginFormat [BOLD] [[a]=[b]]
beginFormat [BOLD] [[a]=[b][data-xwiki-parameter]=[value]]
onWord [something]
endFormat [BOLD] [[a]=[b]]
endFormat [BOLD] [[a]=[b][data-xwiki-parameter]=[value]]
endParagraph
endDocument
.#-----------------------------------------------------
.expect|xhtml/1.0
.#-----------------------------------------------------
<p><strong><span a="b">something</span></strong></p>
\ No newline at end of file
<p><strong><span a="b" data-xwiki-parameter="value">something</span></strong></p>
\ No newline at end of file
.#-----------------------------------------------------
.input|xhtml/1.0
.# Verify that div tag parameters, also starting with data-xwiki-, are recognized.
.#-----------------------------------------------------
<div a="b" data-xwiki-parameter="value">something</div>
.#-----------------------------------------------------
.expect|event/1.0
.#-----------------------------------------------------
beginDocument
beginGroup [[a]=[b][data-xwiki-parameter]=[value]]
beginParagraph
onWord [something]
endParagraph
endGroup [[a]=[b][data-xwiki-parameter]=[value]]
endDocument
.#-----------------------------------------------------
.expect|xhtml/1.0
.#-----------------------------------------------------
<div a="b" data-xwiki-parameter="value"><p>something</p></div>
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment