Tcl Library Source Code
markdown - Markdown to HTML Converter
Not logged in
Bounty program for improvements to Tcl and certain Tcl packages.

[ Main Table Of Contents | Table Of Contents | Keyword Index | Categories | Modules | Applications ]

markdown(n) 1.1 tcllib "Markdown to HTML Converter"


markdown - Converts Markdown text to HTML


  • package require Tcl 8.5
  • package require Markdown 1.1
  • package require textutil ?0.8?


The package Markdown provides a command to convert Markdown annotated text into HMTL.

::Markdown::convert markdown

This command takes in a block of Markdown text, and returns a block of HTML.

The converter supports two types of syntax highlighting for fenced code blocks: highlighting via a registered converter (see ::Markdown::register), or pure JavaScript highlighting, e.g. via "highlight.js", where the language specifier used in the markup is set as CSS class of the "code" element in the returned markup.

::Markdown::register langspec converter

Register a language specific converter for prettifying a code block (e.g. syntax highlighting). Markdown supports fenced code blocks with an optional language specifier (e.g. "tcl"). When the markdown parser processes such a code block and a converter for the specified langspec is registered, the converter is called with the raw code block as argument. The converter is supposed to return the markup of the code block as result. The specified converter can be an arbitrary Tcl command, the raw text block is added as last argument upon invocation.


Return a dict of language specifier and number of occurrences in fenced code blocks. This function can be used e.g. to detect, whether some CSS or JavaScript headers should be included for rendering without the need of postprocessing the rendered result.


Reset the language counters.

Bugs, Ideas, Feedback

This document, and the package it describes, will undoubtedly contain bugs and other problems. Please report such in the category textutil of the Tcllib Trackers. Please also report any ideas for enhancements you may have for either package and/or documentation.

When proposing code changes, please provide unified diffs, i.e the output of diff -u.

Note further that attachments are strongly preferred over inlined patches. Attachments can be made by going to the Edit form of the ticket immediately after its creation, and then using the left-most button in the secondary navigation bar.


Text processing