use of org.xwiki.rendering.parser.HighlightParser in project xwiki-platform by xwiki.
the class CodeMacro method highlight.
/**
* Return a highlighted version of the provided content.
*
* @param parameters the code macro parameters.
* @param content the content to highlight.
* @return the highlighted version of the provided content.
* @throws ParseException the highlight parser failed.
* @throws ComponentLookupException failed to find highlight parser for provided language.
*/
protected List<Block> highlight(CodeMacroParameters parameters, String content) throws ParseException, ComponentLookupException {
HighlightParser parser;
if (parameters.getLanguage() != null) {
if (this.componentManager.hasComponent(HighlightParser.class, parameters.getLanguage())) {
try {
parser = this.componentManager.getInstance(HighlightParser.class, parameters.getLanguage());
return parser.highlight(parameters.getLanguage(), new StringReader(content));
} catch (ComponentLookupException e) {
this.logger.error("Faild to load highlighting parser for language [{}]", parameters.getLanguage(), e);
}
}
}
this.logger.debug("Can't find any specific highlighting parser for language [{}]. Trying the default highlighting parser.", parameters.getLanguage());
parser = this.componentManager.getInstance(HighlightParser.class, "default");
return parser.highlight(parameters.getLanguage(), new StringReader(content));
}
Aggregations