Nothing new functionally here for Meltdown. This is an in depth discussion of the coding for version 2.1 of the Meltdown parser.

GitHub Code Repository

This implements the Meltdown to HTML parser as well as some sample code:

Meltdown V2.1.0 is now available as Nuget package and can be used with any .NET 5.0 apps.


Previously Meltdown was coded such that the parser splits the string passed to it into an array of lines and then for each line it progressively calls methods for each Meltdown Markup feature. The methods determine if the feature is present and appropriately handle it for the line. Certain features preclude other feature methods being called. For example, if the line is part of a table, then list methods are not called.

The parser has been re-coded such that for each line, the line type is first determined from the first few characters in the line. The specific method for the line type is called to do the processing. For some of the line types, there is just a simple substitution and hence to no method Is needed. There is still a overarching method that gets called for all line types to process formatting such as bold, italics etc. Also, HTML links and font colors are processed if present for each line via distinct methods.

There is some state maintained between lines in that the previous line type is remembered so that, for example, a table line type, the parser inserts an open table tag if the line type changes to a table. Conversely, for example, if the line type changes from a table, the parser inserts the table closing tag before the current line.

Line Types

Line Type Start of line Outcome Notes
Paragraph Default (None of below) <p>Line</p> !! within paragraph translates to <br/>
Simple list Minus-Space or Tab-Space <li>_line</li> _line=Line from char 3
Extended List ((n)) <li>_line</li> Where n is the line depth _line=Line from char 5
Heading [[n]] <hn>_line</hn>       Where n=1..9 _line=Line from char 5
Table ((T)) or ((t) ((T)): <th>…</th>
((t)): <tr>…</tr>
csv=Line from char 5 csv is split into headers
csv is split into cells.

Line Prepends depending upon current and previous line types

This table is the HTML code that needs to be added at the start of the line for various previous-current line type combinations.

 Previous Line Type:
Current Line TypeParagraphSimple ListExtended ListHeadingTable 
Paragraph </ul>n</ul> </table>n=list previous depth
Simple List<ul> *<ul></table><ul> 
Extended Listn<ul>*(n-m)</ul> or (m-n)<ul>
(n-m)>0  viz
n<ul></table>n<ul>n=previous list depth
m=new list depth
Heading </ul>n</ul> </table>n=previous list depth

Note 1: n<ul> means <ul> repeated n times etc.
Note 2: (n-m) should typically be +-1 or 0
Note 2: There is actually a new line /n character between most HTML tags in the above.
E.g. </table><ul> is actually </table>/n<ul>


Put simply:

  • If new line is a paragraph, then if previous was list or table then close them
  • If new line is a simple list, then if previous was table then close it.
    • Open list if previous line was not simple list.
  • If new line is a table and previous was a list then close it.
    • If previous line wasn’t table then open the table.

Dotting I’s and crossing t’s: Extended Lists

  • * Current and previous simple list and extended list combinations are disallowed.
  • Whilst simple list is limited to one level, extended list lines can be of any depth where, for example, ((3)) means a list line is 3 deep.
  • When opening an extended list need to add n <ul> where n is the opening depth of the list. This should only be 1 for the first line in a list.
  • When closing an extended list need to add n <ul> depending upon the current list depth. This should normally be 1 for the last line in a list.
  • When adding an extended list line to an existing extended list, need to add (n-m) <ul> if going deeper or (m-n) <ul> if less deep where n is the new list line depth and m is the previous line depth. Normally the difference is only 1 in both cases.

Parser Pseudo Code

  • html <– “”
  • Split input into array of lines
  • For each line
    • Get line type and level (Heading and Extended List types)
    • If new line type <> previous line type
      • Determine prepend and append to HTML string (as above)
    • Case (Line Type):
      • Paragraph: Line <– <p>Line</p>
      • Heading: Line <– <hn>_line</hn>
      • Simple List: Line <– <li>_line</li>
      • Extended List: Line <– <li>_line</li>
      • Table
        • Call Method
          • Csv Split _line into parts
          • ((T)) Line <– <th> headings </th>
            • Foreach part: heading <– <th>part</th>
          • ((t)) Line <– <tr> cells </tr>
            • Foreach part: cell <– <tr>part</tr>
    • Replace any !! with <br/>
    • Call formatting method for line
      • Translate bold, italics etc Meltdown code to HTML code.
    • Call links method for line
      • While line contains Meltdown code for link
        • Translate link code to HTML
    • Call font color method for line
      • While line contains Meltdown code for font color
        • Translate color code to HTML
    • Append modified line to html string (with a /n)
  • Return html string

 This Category Links 
Category:Web Sites Index:Web Sites
  Next: > Meltdown
<  Prev:   Meltdown