Class MarkdownDocument

  • All Implemented Interfaces:
    Document

    public class MarkdownDocument
    extends java.lang.Object
    implements Document
    A Document written in Markdown that can be transformed to HTML in 3 steps: 1) pre-processing, 2) markdown to html conversion, and 3) post-processing.
    • Constructor Summary

      Constructors 
      Constructor Description
      MarkdownDocument​(java.io.File input, WebsiteProject project0, java.util.Properties properties0)
      Create a document from the given file.
      MarkdownDocument​(java.io.File fakeInputFile, WebsiteProject project0, java.util.Properties properties0, java.lang.String input)
      Create a document from the given string.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.Object getMetadata​(java.lang.String fieldName)
      Extracts a desired metadata field from the document.
      java.lang.String getModificationDate​(java.io.File input)
      Estimate the date on which this document was last modified.
      java.lang.String postprocess​(org.w3c.dom.Document htmlDoc, java.lang.String format)
      Transform HTML to desired output format and apply late substitutions of properties and other special strings.
      java.lang.String preprocess​(java.lang.String format)
      Prepare for processing: Apply macros and extract metadata.
      org.w3c.dom.Document process​(java.lang.String markDownText)
      Convert Markdown text to an HTML structure.
      void setDebugMode​(boolean mode)
      Turn indentation in generated XML on and off.
      java.lang.String transform​(java.lang.String format)
      Transform this document into a string suitable for writing into an HTML file.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • MarkdownDocument

        public MarkdownDocument​(java.io.File input,
                                WebsiteProject project0,
                                java.util.Properties properties0)
        Create a document from the given file.
        Parameters:
        input - Markdown document text
        project0 - website project context,
        properties0 - Properties to be used in processing this document.
      • MarkdownDocument

        public MarkdownDocument​(java.io.File fakeInputFile,
                                WebsiteProject project0,
                                java.util.Properties properties0,
                                java.lang.String input)
        Create a document from the given string. "Pretend" that the input string was actually read from a file.
        Parameters:
        fakeInputFile - A path to a file that we will "pretend" is where the input string was obtained
        project0 - project website context
        properties0 - Properties to be used in processing this document.
        input - Markdown document text
    • Method Detail

      • transform

        public final java.lang.String transform​(java.lang.String format)
        Transform this document into a string suitable for writing into an HTML file.
        Specified by:
        transform in interface Document
        Parameters:
        format - Specifies a style/format for the generated HTML.
        Returns:
        String containing HTML of page for web site.
      • preprocess

        public final java.lang.String preprocess​(java.lang.String format)
        Prepare for processing: Apply macros and extract metadata.
        Parameters:
        format - HTML format to be applied
        Returns:
        A Markdown document string ready for conversion to HTML.
      • process

        public final org.w3c.dom.Document process​(java.lang.String markDownText)
        Convert Markdown text to an HTML structure.
        Parameters:
        markDownText - document text in Markdown
        Returns:
        DOM tree of generated HTML
      • postprocess

        public final java.lang.String postprocess​(org.w3c.dom.Document htmlDoc,
                                                  java.lang.String format)
        Transform HTML to desired output format and apply late substitutions of properties and other special strings.
        Parameters:
        htmlDoc - the basic XML/HTML structure for the document.
        format - the desired format - used to select a stylesheet for the basic transformations.
        Returns:
        transformed HTML string
      • getMetadata

        public final java.lang.Object getMetadata​(java.lang.String fieldName)
        Extracts a desired metadata field from the document. Metadata fields are found at the start of a document in the form FieldName: value of field Metadata fields become part of the property set that is replaced in the document text as part of the post-processing, in which "@FieldName@" is replaced by the value of that property. Some metadata field names are inserted as part of early processing. These in include Title, Author, CSS, Date, Copyright, and JaxenURL.
        Parameters:
        fieldName - name of the metadata field
        Returns:
        value of that metadata field extracted from the beginning of the document.
      • setDebugMode

        public final void setDebugMode​(boolean mode)
        Turn indentation in generated XML on and off. Must be off in production to avoid distorting code listings.
        Parameters:
        mode - true iff debugging
      • getModificationDate

        public java.lang.String getModificationDate​(java.io.File input)
        Estimate the date on which this document was last modified. 1. If the file is within a Git repository and unchanged, use the date of the last commit. 2. If the file is not within a Git repository or is changed, use the modification date of the file.
        Parameters:
        input - file to be checked
        Returns:
        Data of last modification