Hi Simon,
The styles filter also gets called for ":before" and ":after" selectors if they are initially present in the CSS.
If in your CSS after the imports you add the namespace declaration:
Code: Select all
@namespace oxy url('http://www.oxygenxml.com/extensions/author');
and the following selector:
Code: Select all
oxy|processing-instruction:before {
content:"";
}
you will start receiving in the styles filter events for ":before" selectors for any processing instruction.
Then the filter would work something like this:
Code: Select all
public Styles filter(Styles styles, AuthorNode authorNode) {
if(authorNode.getType() == AuthorNode.NODE_TYPE_PSEUDO_ELEMENT) {
//We want to style a ":before" selector for a PI
if("before".equals(authorNode.getName())) {
AuthorNode node = authorNode.getParent();
if(node instanceof ArtificialNode) {
//Actually in order to match the CSS selectors Oxygen pretends there is an element which is called "processing-instruction"
AuthorNode realNode = ((ArtificialNode)node).getWrappedNode();
if(realNode.getType() == AuthorNode.NODE_TYPE_PI) {
//Found the real PI
try {
String piTextContent = realNode.getTextContent();
styles.setProperty(Styles.KEY_MIXED_CONTENT,
new StaticContent[] { new StringContent(
piTextContent) });
styles.setProperty(Styles.KEY_FOREGROUND_COLOR, new ro.sync.exml.view.graphics.Color(192, 192, 192));
} catch (BadLocationException e) {
e.printStackTrace();
}
}
}
}
}
return styles;
}
The styling is quite complicated because a CSS was not constructed to match other nodes than elements so in order to allow CSS styling for processing instructions Oxygen "fakes" artificial elements for them, it considers a PI to be equivalent with an XML element called
processing-instruction and having the namespace
http://www.oxygenxml.com/extensions/author.
In this way CSS selectors can be constructed to match PIs from the XML document and the styles filter receives events for those artificial elements.
What we plan to implement for a future version (maybe even v14.1) would be that if a PI in the XML contains also pseudo-attributes like:
then you could match it specifically from the CSS like:
Code: Select all
oxy|processing-instruction[target]:before {
content:"";
}
or even like:
Code: Select all
oxy|processing-instruction[target][name='value']:before {
content:"";
}
It would be as if the PI's pseudo attributes would be considered attributes for that artificial element and maybe it would mean removing the styles filter workarounds in some cases.
Regards,
Radu