Class MarkdownHelper

java.lang.Object
nz.org.riskscape.engine.cli.MarkdownHelper

public class MarkdownHelper extends Object

A convinent wrapper around a StringBuilder that allows you to build a markdown file. Call the various addHeading, addText methods, then at the end call writeToFile

  • Constructor Details

    • MarkdownHelper

      public MarkdownHelper()
  • Method Details

    • build

      public String build()

      Returns the markdown as a String

    • addHeading

      public void addHeading(String text)

      Adds a markdown styled heading

    • addHeading

      public void addHeading(String text, int level)

      Adds a markdown styled heading

      Parameters:
      level - The size of the heading (1 is biggest, higher numbers create subheadings.)
    • addLine

      public void addLine()

      Adds two newlines. Equivalent to addLine("")

    • addLine

      public void addLine(String text)

      Adds the given String to the buffer, ensuring this ends with two newline characters. (This corresponds to one newline once the markdown is parsed)

    • addNestedContent

      public void addNestedContent(String content)

      Add content that may itself be markdown formatted with headings.

      Content is split on double line feeds so it can be added line by line. Should any line be a heading it will be prefixed with current heading prefix to effectively alter the heading level to suit the document the new content is being inserted into.

      Parameters:
      content - markdown content to add
    • addRstClass

      public void addRstClass(String className)

      Adds an rst-class directive. The element that follows this will be given this class

    • addText

      public void addText(String text)

      Directly adds the given String to the buffer

    • addTable

      public void addTable(nz.org.riskscape.engine.cli.Table table)
    • addTable

      public void addTable(nz.org.riskscape.engine.cli.Table table, Optional<String> emptyTableMessage)
    • writeToFile

      public Path writeToFile(Path path, String filename) throws IOException

      Writes the stored content to the given path.

      Returns:
      The path that was written to
      Throws:
      IOException