Giter Club home page Giter Club logo

luamd's Introduction

luamd

luamd is a Markdown to HTML renderer written in portable, pure Lua. It's also really easy to use.

local md = require "md"
local htmlFragment = md[[
# This is Some Markdown
Write whatever you want.
* Supports Lists
* And other features
]]

Install

Copy md.lua to your project in whatever directory you want.

Use it

Render markdown from a string. On bad input, retuns nil and an error message.

local html, err = md.renderString(str, options)

Render markdown from a line iterator. An iterator is a function the returns successive lines when called repeatedly, and nil when there are no lines left.

local html, err = md.renderLineIterator(iter, options)

Render markdown from a list like table of lines.

local html, err = md.renderTable(t, options)

Renders strings, iterators, and tables.

local html, err = md.render(object, options)

Calling the module as a function will invoke md.render. This is the easiest way to use the module.

The options table is an optional table of options. The currently supported options are below.

  • tag - Surrounding HTML tag for HTML fragment.
  • attributes - A table attributes for the surround HTML node. For example, { style = "padding: 10px;" }.
  • insertHead - An HTML fragment to insert before the main body of HTML. (Inserted after the wrapping tag, if present.)
  • insertTail - An HTML fragment to insert after the main body of HTML. (Inserted before the closing tag, if present.)
  • prependHead - An HTML fragment to insert before the main body of HTML. (Inserted before the opening tag, if present.)
  • appendTail - An HTML fragment to insert after the main body of HTML. (Inserted after the closing tag, if present.)

Here is a little diagram for where the optional fragments go.

** prependHead **
<tag [attributes k1="v1" k2="v2" k3="v3" ...]>
    ** insertHead **

    ... rendered markdown ...

    ** insertTail **
</tag>
** appendTail **

Testing

There is no unit-testing yet, but testing can be done by running the testrender.lua script. This builds HTML files in the test_documents directory that correspond to the markdown source files. Open these with a web browser and assure that they look fine. To add more test documents, place a markdown file in the test_documents folder and add it to the documents list in testrender.lua.

Todo

Needs some good unit testing. :).

Supports most of basic Markdown syntax, but there are some features that need to be implemented. I haven't implemented them because I don't need them - yet.

  • HTML and code escapes - Probably the most important one on the list.
  • Some alternative syntax for numbered Lists (using #.)
  • Indent style code - I prefer backtick quoted code
  • Tables - GitHub style tables would be cool
  • Footnotes - Might need them, but not yet.

Bugs

If anyone wants to use this and finds bugs and issues, let me know! I usually can fix things pretty quickly, and I appreciate help.

luamd's People

Contributors

bakpakin avatar frenzie avatar tomas avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

luamd's Issues

Not generating [Links]("/properly")

Say I got [Links]("/properly")and want to parse this from md to html. The result is going to be:

<a href="" properly""="">Links</a>

For [Links]("http://www.example.com/reallycoolthing") :

<a href="" http:="" www.example.com="" reallycoolthing""="">Links</a>

[Links]("#something") :

<a href="" #something""="">Links</a>

It never parses it into something that's redirectionish.

Is this a known lack of feature or bug, or on a TODO list?

*Got the md.lua through LuaRocks.

Can I link with a file that has an underscore in the name?

Hello, I would like to to make a link to a file that has an underscore in the name:

[Link](foo_bar.html)

But the underscore seems to confuse the library. Instead of the expected result of:
Link

I get something where the file name is not used as the link, but instead written as text on the page:
Link(foo_bar.html)
where the HTML is
<a href="">Link</a> (foo_bar.html)

Could not find closing delimiter should not do anything special

This problem showed up in the very first test document I tossed at the program, which included this link:

http://wiki.tei-c.org/index.php/Publishing_printed_critical_editions_from_TEI

That results in the following error:

./md.lua:127: Could not find closing delimiter "_".

Going by pandoc and GitHub _ isn't supposed to do anything in the middle of words (cf. here and here), but aside from that the expected behavior is to ignore the "problem":

Input:

asdf*bla*asdf*asdf

Expected:

<p>asdf<em>bla</em>asdf*asdf</p>

What is imo the Markdown spec to go for can be found at http://spec.commonmark.org/ but for test ideas I find https://github.com/karlcow/markdown-testsuite/tree/92d125d8d97f1c01191c84404b13319f60b38502/tests a little easier to browse than the tests/examples embedded in the spec.

Anyway, neat project! :-)

Edit: oh, never mind. There's a GitHub page with some interesting tools for the tests: https://github.com/jgm/CommonMark/tree/f3ceed3013a6b719af91dc3323f3888e9dbe8406#running-tests-against-the-spec

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.