AddHighlight with style
Post here questions and problems related to oXygen frameworks/document types.
-
- Posts: 5
- Joined: Mon Mar 09, 2020 2:02 pm
AddHighlight with style
Hi,
A Plugin has been developed which marks the content of the XML based on a terminology termbase and some rule.
Non-persistent highlighter has been used to mark the content. At first glance it worked pretty well, but after I tried several files I found that if the file reference any styles, the marking slightly shifted.
So this is the file without formatting:
I simply use this code.
Can you help why this happens and how can I solve this?
Thank you in advance
Best regards,
Balazs
A Plugin has been developed which marks the content of the XML based on a terminology termbase and some rule.
Non-persistent highlighter has been used to mark the content. At first glance it worked pretty well, but after I tried several files I found that if the file reference any styles, the marking slightly shifted.
So this is the file without formatting:
oxygen_1.PNG
And this is the file with some formatting
oxygen_style.PNG
If the CSS file content is empty, I get the same results.I simply use this code.
Code: Select all
AuthorHighlighter highlighter = authorPageAccess.getHighlighter();
ColorHighlightPainter painter = new ColorHighlightPainter(withColor, 20, 10);
highlighter.addHighlight(startOffset , startOffset + length, painter, null);
Thank you in advance
Best regards,
Balazs
You do not have the required permissions to view the files attached to this post.
-
- Posts: 9431
- Joined: Fri Jul 09, 2004 5:18 pm
Re: AddHighlight with style
Hi Balazs,
This looks similar to what our terminology checker add-on does:
https://www.oxygenxml.com/doc/versions/ ... addon.html
Can you give me a small overview over how you compute those "startOffset" and "length" parameters that you use to add highlights?
When XML content is loaded in the Author visual editing mode and the XML has a CSS and schema associated usually Oxygen trims consecutive white spaces, for example if the original XML text was like this:
Oxygen will remove the consecutive spaces in the indentation so that in the Author mode the text content is like this:
When saving the XML content back Oxygen might add again line breaks and indentation.
If the XML does not have a CSS or schema associated, Oxygen considers that all XML elements inside it are space preserve and leaves the indentation and line breaks exactly as they were.
Our Terminology Checker add-on uses this API "ro.sync.ecss.extensions.api.AuthorDocumentController.getTextContentIterator(int, int)" to retrieve text segments exactly as they are present in the Author visual editing mode and check that text instead of checking the initial XML text as it was serialized on disk.
I think another approach would be to do what this free Oxygen add-on which integrates with LanguageTools does:
https://github.com/danielnaber/oxygen-l ... ector.java
to use the "AuthorDocumentController.serializeFragmentToXML" API to serialize the Author nodes to XML, a serialization which does not add indents and extra spaces so it maps well to the content in the Author page.
Regards,
Radu
This looks similar to what our terminology checker add-on does:
https://www.oxygenxml.com/doc/versions/ ... addon.html
Can you give me a small overview over how you compute those "startOffset" and "length" parameters that you use to add highlights?
When XML content is loaded in the Author visual editing mode and the XML has a CSS and schema associated usually Oxygen trims consecutive white spaces, for example if the original XML text was like this:
Code: Select all
<p>some text
second line
Code: Select all
some text second line
If the XML does not have a CSS or schema associated, Oxygen considers that all XML elements inside it are space preserve and leaves the indentation and line breaks exactly as they were.
Our Terminology Checker add-on uses this API "ro.sync.ecss.extensions.api.AuthorDocumentController.getTextContentIterator(int, int)" to retrieve text segments exactly as they are present in the Author visual editing mode and check that text instead of checking the initial XML text as it was serialized on disk.
I think another approach would be to do what this free Oxygen add-on which integrates with LanguageTools does:
https://github.com/danielnaber/oxygen-l ... ector.java
to use the "AuthorDocumentController.serializeFragmentToXML" API to serialize the Author nodes to XML, a serialization which does not add indents and extra spaces so it maps well to the content in the Author page.
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
-
- Posts: 5
- Joined: Mon Mar 09, 2020 2:02 pm
Re: AddHighlight with style
My internal document representation contains key-value pairs, where the key is the XPath to the node and the value is the node's content.
When the user interacts with my program I try to get the AuthorNode by the XPath, and get it start offset by:
The use case is that, some user select a word and want to highlight it ( or replace with another one). The item.startIndex is the word's start index inside the node's content that I want to highlight (I get the content by node.getTextContent()). The length is the word length.
So if I understand issue well, the problem is that the content that I receive from (node.getTextContent()) contains multiple consecutive whitespaces, so it will be trimmed by oxygen if CSS is loaded, am I right?
If that's the case:
When the user interacts with my program I try to get the AuthorNode by the XPath, and get it start offset by:
Code: Select all
AuthorNode node = ...; // get node by current selection or by XPath
int temp = node.getStartOffset();
int startOffset = temp + item.startIndex;
So if I understand issue well, the problem is that the content that I receive from (node.getTextContent()) contains multiple consecutive whitespaces, so it will be trimmed by oxygen if CSS is loaded, am I right?
If that's the case:
- How can I determine if a CSS is loaded or not?
- Does "node.getStartOffset()" return the valid or "miscounted" location, if any previous nodes contains consecutive whitespaces? (So should I calculate all the consecutive whitespace count before the actual word index, or is it enough to calculate only for the current node's content)
-
- Posts: 78
- Joined: Wed Jun 22, 2016 2:48 pm
Re: AddHighlight with style
Post by adrian_sorop »
Hi,
As Radu stated in his previous post, we encourage developers to use the TextContentIterator API and the TextContext API.
The usage is something like:
Regards,
Adrian S
As Radu stated in his previous post, we encourage developers to use the TextContentIterator API and the TextContext API.
The usage is something like:
Code: Select all
TextContentIterator textContentIterator = authorDocumentController.getTextContentIterator(node.getStartOffset(), node.getEndOffset());
while (textContentIterator.hasNext()) {
TextContext textContent = textContentIterator.next();
// now you can use the textContent to get the text, it's offsets and others
}
Adrian S
Adrian Sorop
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
Return to “SDK-API, Frameworks - Document Types”
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service