Class MarkdownUtil

java.lang.Object
ecmwf.common.text.MarkdownUtil

public final class MarkdownUtil extends Object
The Class MarkdownUtil. Converts Markdown source to a restricted, safe HTML fragment - used for the markdown Destination metadata field type, both for its live edit-time preview and for its rendering into the Opsview notes export (ExportDestinationMetaNotesAction), so the two are always byte-for-byte identical. CommonMark is parsed and rendered to HTML first, then the result is run through a jsoup allow-list which strips anything not on it (including all attributes other than the ones explicitly added), rather than trying to sanitise Markdown syntax itself - this way the output stays predictable regardless of what the source contains.
  • Method Details

    • toSafeHtml

      public static String toSafeHtml(String markdown)
      To safe html.
      Parameters:
      markdown - the markdown source, possibly null
      Returns:
      the rendered, allow-listed HTML (empty string if markdown is null/blank)
    • toMessageHtml

      public static String toMessageHtml(String markdown)
      To safe html for a message: single line breaks in the source are preserved.
      Parameters:
      markdown - the markdown source, possibly null
      Returns:
      the rendered, allow-listed HTML
    • toEmailHtml

      public static String toEmailHtml(String markdown)
      To a complete HTML document suitable for an e-mail body.
      Parameters:
      markdown - the markdown source
      Returns:
      the HTML document
    • toPlainText

      public static String toPlainText(String markdown)
      To a readable plain-text approximation (paragraphs, lists, links, tables), for channels which cannot carry HTML.
      Parameters:
      markdown - the markdown source, possibly null
      Returns:
      the plain text