Class AsciiDoc


  • public final class AsciiDoc
    extends Object
    Root builder for AsciiDoc markup. All operations may be applied at the current linear position within the document being built, such that markup that must appear at the top should be added first.

    This class is not thread-safe.

    • Field Detail

      • INCLUDE_PATTERN

        public static final Pattern INCLUDE_PATTERN
        Regex for finding Include-directives, where group 1 contains the path-value.
        See Also:
        include(String...)
    • Method Detail

      • asciiDoc

        public static AsciiDoc asciiDoc()
        Creates a new builder instance.
        Returns:
        builder
      • newline

        public AsciiDoc newline()
        Inserts a UNIX newline character, where two adjacent newlines will create a new paragraph. As a best-practice, they suggest one-sentence-per-line style.
        Returns:
        builder
      • rawText

        public AsciiDoc rawText​(String text)
        Inserts raw text (may contain markup or only whitespace).
        Parameters:
        text - Raw text/markup
        Returns:
        builder
      • rawLine

        public AsciiDoc rawLine​(String text)
        Inserts raw line (may contain markup), and will insert one newline-characters above and below, if those newlines do not already exist.
        Parameters:
        text - Raw text/markup
        Returns:
        builder
      • rawParagraph

        public AsciiDoc rawParagraph​(String text)
        Inserts raw paragraph (may contain markup), and will insert two newline-characters above and below, if those newlines do not already exist [ref].
        Parameters:
        text - Raw text/markup
        Returns:
        builder
      • boldText

        public AsciiDoc boldText​(String text)
        Inserts bold text.
        Parameters:
        text - Text to make bold
        Returns:
        builder
      • italic

        public AsciiDoc italic​(String text)
        Inserts italic text.
        Parameters:
        text - Text to make bold
        Returns:
        Doc builder
      • mono

        public AsciiDoc mono​(String text)
        Inserts monospaced (e.g., code) text.
        Parameters:
        text - Text to make monospaced
        Returns:
        Doc builder
      • documentTitle

        public AsciiDoc documentTitle​(String title)
        Inserts a document title.
        Parameters:
        title - Document title
        Returns:
        Doc builder
      • blockTitle

        public AsciiDoc blockTitle​(String title)
        Inserts a block title.
        Parameters:
        title - Block title
        Returns:
        Doc builder
      • sectionTitle

        public AsciiDoc sectionTitle​(String title,
                                     int level)
        Inserts a section title, at a given level.
        Parameters:
        title - Section title
        level - Section level [1-5]
        Returns:
        Doc builder
      • sectionTitle1

        public AsciiDoc sectionTitle1​(String title)
        Inserts a section title, level 1.
        Parameters:
        title - Section title
        Returns:
        Doc builder
      • sectionTitle2

        public AsciiDoc sectionTitle2​(String title)
        Inserts a section title, level 2.
        Parameters:
        title - Section title
        Returns:
        Doc builder
      • sectionTitle3

        public AsciiDoc sectionTitle3​(String title)
        Inserts a section title, level 3.
        Parameters:
        title - Section title
        Returns:
        Doc builder
      • sectionTitle4

        public AsciiDoc sectionTitle4​(String title)
        Inserts a section title, level 4.
        Parameters:
        title - Section title
        Returns:
        Doc builder
      • sectionTitle5

        public AsciiDoc sectionTitle5​(String title)
        Inserts a section title, level 5.
        Parameters:
        title - Section title
        Returns:
        Doc builder
      • exampleBlock

        public AsciiDoc exampleBlock​(String content)
        Inserts an example-block.
        Parameters:
        content - Content
        Returns:
        Doc builder
      • listingBlock

        public AsciiDoc listingBlock​(String content)
        Inserts a listing-block.
        Parameters:
        content - Content
        Returns:
        Doc builder
      • listingBlock

        public AsciiDoc listingBlock​(String content,
                                     String sourceType)
        Inserts a listing-block, with the source-code type (e.g., java, json, etc.) noted for formatting purposes.
        Parameters:
        content - Content
        sourceType - Type of source-code in the listing
        Returns:
        Doc builder
      • literalBlock

        public AsciiDoc literalBlock​(String content)
        Inserts a literal-block.
        Parameters:
        content - Content
        Returns:
        Doc builder
      • passthroughBlock

        public AsciiDoc passthroughBlock​(String content)
        Inserts a pass-through-block.
        Parameters:
        content - Content
        Returns:
        Doc builder
      • sidebarBlock

        public AsciiDoc sidebarBlock​(String content)
        Inserts a sidebar-block.
        Parameters:
        content - Content
        Returns:
        Doc builder
      • anchor

        public AsciiDoc anchor​(String id)
        Inserts a cross-reference anchor.
        Parameters:
        id - Anchor ID
        Returns:
        Doc builder
      • anchor

        public AsciiDoc anchor​(String id,
                               String xreflabel)
        Inserts a cross-reference anchor, with a custom xreflabel.
        Parameters:
        id - Anchor ID
        xreflabel - Custom cross-reference link
        Returns:
        Doc builder
      • link

        public AsciiDoc link​(String anchorId)
        Inserts a cross-reference link.
        Parameters:
        anchorId - Anchor ID
        Returns:
        Doc builder
      • link

        public AsciiDoc link​(String anchorId,
                             String xreflabel)
        Inserts a cross-reference link, with a custom xreflabel.
        Parameters:
        anchorId - Anchor ID
        xreflabel - Custom cross-reference link
        Returns:
        Doc builder
      • unorderedList1

        public AsciiDoc unorderedList1​(String content)
        Inserts a line for an unordered list, at level 1 indentation.
        Parameters:
        content - Line of content
        Returns:
        Doc builder
      • listContinuation

        public AsciiDoc listContinuation()
        Inserts a list-continuation, for adding complex formatted content to a list.
        Returns:
        Doc builder
      • horizontalRule

        public AsciiDoc horizontalRule()
        Inserts a horizontal-rule divider.
        Returns:
        Doc builder
      • tableStart

        public AsciiDocTable tableStart()
        Starts a table at the current position.
        Returns:
        Table builder
      • include

        public AsciiDoc include​(String... path)
        Inserts an include-directive, given a relative path to a file.
        Parameters:
        path - Relative path segments
        Returns:
        Doc builder
      • toFile

        public void toFile​(Path outputDirPath,
                           String filename)
                    throws IOException
        Saves builder content to a file.
        Parameters:
        outputDirPath - Output directory
        filename - Filename
        Throws:
        IOException - When error occurs while saving.
      • toString

        public String toString()
        Converts builder content to a String.

        Overrides:
        toString in class Object
        Returns:
        Doc builder content
      • normalizeName

        public static String normalizeName​(String... parts)
        Normalizes a name such that it can be used as a unique filename and/or anchor in AsciiDoc. Names are converted to lower-case, unsupported characters are collapsed to a single underscore-character, and parts are separated by an underscore.
        Parameters:
        parts - Name-parts to normalize
        Returns:
        Normalized name