From 3b8424c8dd22836bb7e86552dc12fbb54fdafb45 Mon Sep 17 00:00:00 2001 From: Ruud Senden <8635138+rsenden@users.noreply.github.com> Date: Tue, 9 Apr 2024 12:14:48 +0200 Subject: [PATCH] chore: Action improvements --- .../cli/common/action/helper/ActionSpelFunctions.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/fcli-core/fcli-common/src/main/java/com/fortify/cli/common/action/helper/ActionSpelFunctions.java b/fcli-core/fcli-common/src/main/java/com/fortify/cli/common/action/helper/ActionSpelFunctions.java index cbe6b69927..eae9122f72 100644 --- a/fcli-core/fcli-common/src/main/java/com/fortify/cli/common/action/helper/ActionSpelFunctions.java +++ b/fcli-core/fcli-common/src/main/java/com/fortify/cli/common/action/helper/ActionSpelFunctions.java @@ -104,12 +104,20 @@ private static String _htmlToText(Document document) { document.select("li").append("\\n"); document.select("br").forEach(e->e.replaceWith(new TextNode("\n"))); document.select("p").prepend("\\n\\n"); + // Replace code blocks, either embedding in backticks if inline (no newline characters) + // or indenting with 4 spaces and fencing with CODE_START and CODE_END, which will remain + // in place when cleaning all HTML tags, and removed using pattern matching below. document.select("span.code").forEach(ActionSpelFunctions::replaceCode); document.select("code").forEach(ActionSpelFunctions::replaceCode); document.select("pre").forEach(ActionSpelFunctions::replaceCode); + // Remove all HTML tags. Note that for now, this keeps escaped characters like > + // We may want to have separate methods or method parameter to allow for escaped + // characters to be unescaped. var s = Jsoup.clean(document.html().replaceAll("\\\\n", "\n"), "", Safelist.none(), new Document.OutputSettings().prettyPrint(false)); + var sb = new StringBuilder(); + // Remove CODE_START and CODE_END fences Matcher m = CODE_PATTERN.matcher(s); while(m.find()){ String code = m.group(1);