Add Highlighter on document

Having trouble deploying Oxygen XML Web Author? Got a bug to report? Post it all here.
Isabelle
Posts: 142
Joined: Fri Jan 20, 2017 1:11 pm

Add Highlighter on document

Post by Isabelle »

Hello,

We use Author web in version 26.0.0, and we want to manage Highlighter on the document.

I tried to do it this way :

Code: Select all

public String doOperation(AuthorDocumentModel authorDocumentModel, ArgumentsMap argumentsMap) throws IllegalArgumentException, AuthorOperationException {
        AuthorAccess authorAccess = authorDocumentModel.getAuthorAccess();
	AuthorEditorAccess editorAccess = authorAccess.getEditorAccess();
        AuthorHighlighter highlighter = editorAccess.getHighlighter();
        
        ColorHighlightPainter colorHighlightPainter = new ColorHighlightPainter();
        colorHighlightPainter.setColor(Color.COLOR_BLUE);
        colorHighlightPainter.setTextDecorationStroke(Graphics.STROKE_WAVY_NO_ENDINGS);
        
        int oxygenOffsetStart = 70;
        int oxygenOffsetEnd = 100;
        
        String authorRuleMatch = "It is a Match";
        
        highlighter.addHighlight(oxygenOffsetStart, oxygenOffsetEnd, colorHighlightPainter, authorRuleMatch);
    }
The highlighter is well added in editorAccess, and can be accessed in an other java doOperation().
But no blue STROKE_WAVY_NO_ENDINGS are displayed in web author.

Even if i force the refresh of the document with authorEditorAccess.refresh(), no highlighter are displayed.

How can we manage highlighter in Author Web ?

Thanks,
Regards,
Isabelle
Bogdan Dumitru
Site Admin
Posts: 142
Joined: Tue Mar 20, 2018 5:28 pm

Re: Add Highlighter on document

Post by Bogdan Dumitru »

Hi Isabelle,

Unfortunately, the ColorHighlightPainter API doesn't work in Web Author.
Try instead setting styles via CSS by specifying the "class" attribute on the highlight. Somewhat like this:

Code: Select all

      Map<String, String> attrs = new HashMap<>();
      attrs.put("class", "custom-highlight");
      highlighter.addHighlight(startOffset, endOffset, null, attrs);
and then add an application-level CSS to match be above class. See here a sample plugin that adds such a CSS.
Bogdan Dumitru
http://www.oxygenxml.com
Isabelle
Posts: 142
Joined: Fri Jan 20, 2017 1:11 pm

Re: Add Highlighter on document

Post by Isabelle »

Hi Bogdan,

Your solution works.
Thank you.

Regards,
Isabelle
Post Reply