Page 1 of 1

Add Highlighter on document

Posted: Fri Nov 17, 2023 8:29 pm
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

Re: Add Highlighter on document

Posted: Mon Nov 20, 2023 1:00 pm
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.

Re: Add Highlighter on document

Posted: Mon Nov 20, 2023 9:09 pm
by Isabelle
Hi Bogdan,

Your solution works.
Thank you.

Regards,
Isabelle