123 lines
4.2 KiB
Markdown
123 lines
4.2 KiB
Markdown
# 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 it’s life and between that and transitioning it just ate up time like you wouldn’t 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 you’re fond of core dumps.
|
||
The way I’d originally implemented HTML5 (if that’s 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" - don’t do link processing, block tags
|
||
- "noimages" - don’t do image processing, block
|
||
- "nopants" - don’t run smartypants()
|
||
- "nohtml" - don’t allow raw html through AT ALL
|
||
- "strict" - conform to Markdown standard as implemented in Markdown.pl
|
||
- "tagtext" - process text inside an html tag
|
||
- "noext" - don’t 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" - don’t process header blocks
|
||
- "tabstop" - expand tabs to 4 spaces
|
||
- "nodivquote" - forbid >%class% blocks
|
||
- "noalphalist" - forbid alphabetic lists
|
||
- "extrafootnote" - enable markdown extra-style footnotes
|
||
- "nostyle" - don’t 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" - don’t 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`]).
|
||
|
||
|
||
[Lua]: https://www.lua.org/
|
||
[Discount]: http://www.pell.portland.or.us/~orc/Code/discount/
|
||
[Markdown]: https://en.wikipedia.org/wiki/Markdown
|
||
[License]: LICENSE
|
||
[`ISC`]: https://spdx.org/licenses/ISC.html
|