Class MarkdownParser

This class and the Markdown() helper function, provide Markdown parsing for converting Markdown text to HTML.

In it's simplest for you can do:

DO MarkdownParser && Load Library (once)
lcMarkdown = "This is **bold** text and this is [linked](https://west-wind.com)."
lcHtml = Markdown(lcMarkdown)

The helper function is the preferred way to use the Markdown parser as it caches the Markdown parser rather than recreating the Markdown processing pipeline for each request.

Alternately you can explicitly use the MarkdownParser or MarkdownParserExtended classes, which give a little more control over various options:

lcMarkdown = "This is **bold** text and this is [linked](https://west-wind.com)."

loParser = CREATEOBJECT("MarkdownParser")
loParser.lSanitizeHtml = .T.
llUtf8 = .T.  && encode markdown to UTF8 before sending to Parser
loParser.Parse(lcMarkdown,llUtf8)
Custom
  MarkdownParser

Remarks

Distribution dependencies:

  • wwdotnetbridge.dll
  • wwipstuff.dll
  • markdig.dll

Class Members

MemberDescription

CreateParser

This method creates an instance of the Markdown Parser processing pipeline and applies the configuration that determines what features the parser uses.

o.CreateParser()

Markdown (global function)

This global function takes Markdown text and turns it into HTML.

o.MarkdownParser.Markdown(lcMarkdown,lnMode, llReload,llUtf8, llNoSanitizeHtml, llNoHtmlAllowed)

Parse

Parses a Markdown text string to HTML using the CommonMark specification.

o.Parse(lcMarkdownText, llUtf8)

lEncodeScriptBlocks

If .T. handles <% %> script blocks in a special way by stripping them out of the document and then adding them back in after Markdown rendering. This preserves the original code and allows the script to stay embedded in the document as is.

lNoHtmlAllowed

If .T. doesn't process raw HTML inside of the Markdown. Instead the HTML is HTML Encoded and embedded into the documented as text.

lSanitizeHtml

If .T. sanitizes the HTML for XSS attacks by stripping script blocks, javascript: directives and removing onXXX events from elements.

Requirements

Assembly: markdownparser.prg

See also:

Class MarkdownParser | Class MarkdownParserExtended

© West Wind Technologies, 1996-2024 • Updated: 03/24/19
Comment or report problem with topic