2025-12-13 01:28:21 +04:00
2025-12-14 22:31:17 +04:00
2025-12-14 22:31:17 +04:00
2025-12-13 01:28:21 +04:00
2025-12-13 01:28:21 +04:00
2025-12-13 01:28:21 +04:00
2025-12-13 01:28:21 +04:00
2025-12-13 01:28:21 +04:00
2025-12-14 23:49:11 +04:00
2025-12-13 01:28:21 +04:00

lua-discount3 Markdown

Lua bindings for the Discount Markdown library version >3.0.

Fork of Craig Barnes archive: https://github.com/craigbarnes/lua-discount

Jessica (ex- David) L. Parsons wrote (https://www.pell.portland.or.us/~orc/Code/discount/downloads.html):


I ran out of slots in the original bitmap flags structure, so I dumped it and replaced it with a new flag blob accessed through a flag pointer. This broke the entire published interface and required the update to version 3 (this is why it took me over 3 years to implement it; I needed to test the code to within an inch of its life and between that and transitioning it just ate up time like you wouldnt believe!)
Because I changed the mkd_flag_t structure and replaced it with a blob, the old flags are now a pointer and using the mkd_flag_isset(), mkd_set_flag(), and mkd_clr_flag() functions I introduced during the end of the run for version 2.x.x is now mandatory unless youre fond of core dumps.
The way Id originally implemented HTML5 (if thats even a thing anymore?) support was to have a global structure that I allocated once and then you were stuck with it forever (and had to deallocate the structure whenever you stopped using the library otherwise it would leak memory), so I fixed that for v3.0.0 by moving the html5 details inside the MMIOT (activated by setting the flag MKD_HTML5) so it will automatically be deallocated when you are done with a document without affecting other MMIOTs.

Here is the implementation of bindings for discount v3 API.

Install


luarocks install discount3


Troubleshooting

If you get a compilation error during installation, it's because discount isn't installed as a shared library. See the solution here: https://gitlabor.ru/Datenlabor/discount

Usage

local markdown = require('discount3')

local html = markdown.compile(markdown_text)

print(html.body)

Returns:

table:

  • body - html body
  • title - doc's title (if header exists)
  • author - doc's autor (if header exists)
  • date - docs's date (if header exists)
  • css - docs's CSS (if styles exist)
  • index - table of content (if flag = 'toc')

Flags


markdown.compile(markdown_text,flag,flag,flag)


List of flags:

  • "nolinks" - dont do link processing, block tags
  • "noimages" - dont do image processing, block
  • "nopants" - dont run smartypants()
  • "nohtml" - dont allow raw html through AT ALL
  • "strict" - conform to Markdown standard as implemented in Markdown.pl
  • "tagtext" - process text inside an html tag
  • "noext" - dont allow pseudo-protocols
  • "cdata" - generate code for xml ![CDATA[…]]
  • "nosuperscript" - no A^B
  • "notables" - disallow tables
  • "nostrikethrough" - forbid strikethrough
  • "toc" - do table-of-contents processing (index)
  • "compat" - compatibility with MarkdownTest_1.0
  • "autolink" - make http://foo.com link even without <>s
  • "safelink" - paranoid check for link protocol
  • "noheader" - dont process header blocks
  • "tabstop" - expand tabs to 4 spaces
  • "nodivquote" - forbid >%class% blocks
  • "noalphalist" - forbid alphabetic lists
  • "extrafootnote" - enable markdown extra-style footnotes
  • "nostyle" - dont extract style blocks
  • "dlextra" - enable extra-style definition lists
  • "fencedcode" - enabled fenced code blocks
  • "idanchor" - use id= anchors for TOC links
  • "githubtags" - allow dash and underscore in element names
  • "urlencodedanchor" - urlencode non-identifier chars instead of replacing with dots
  • "latex" - handle embedded LaTeX escapes
  • "html5" - handle html5 elements (maybe obsolete?)
  • "normallist" - disable github-style checkbox lists
  • "explicitlist" - dont combine numbered/bulletted lists
  • "dldiscount" - enable discount-style definition lists
  • "altastitle" - use alt text as the title if no title is listed
  • "extendedattr" - allow extended attribute suffixes

Example:


markdown.compile(markdown_text,"extrafootnote","toc","notables")

License

ISC License (SPDX: ISC).

Description
Lua bindings for the Discount V3 Markdown library.
Readme ISC 565 KiB
Languages
C 67.5%
Lua 23%
Makefile 9.5%