Introducing mmarkdown

Albino Tonnina - Apr 23 '18 - - Dev Community

Markdown on caffeine.

Have you ever wanted a bit more from your markdown files?

Introducing Markdown.

Mmarkdown takes a plain markdown file and generates a copy of it.

It starts to be less boring when you add fenced code blocks with the language identifier set to mmd.

For example:

will output:

Hello Jessie

How it works

Everything that is returned (as a string) from the code in a block will be interpreted and replaced to the block in the output file.

It's full async, which is cool, lots of awaits are waiting for you there but soon enough you will face a problem: too much code to write in a markdown file! Terrible experience!

The solution in mmarkdown is in the scripts option.
You can pass the path of a javascript module in your app to the mmarkdown command.
The module that the scripts file returns will be passed to the context of the fenced block, eg:

This block:

//scripts is passed

const array = [1, 3, 5]

const something = await scripts.processMyArray(array)

const myFinalString = something.map(item => '#### ' + item.name)
  .join('\n\n')

return myFinalString
Enter fullscreen mode Exit fullscreen mode

and this script file:


module.exports = {
  processMyArray: async array =>
    new Promise(resolve => {
      setTimeout(() => {
        resolve(
          array.map(item => ({
            name: item + ' async'
          }))
        )
      }, 1000)
    })
}

Enter fullscreen mode Exit fullscreen mode

will output:

1 async

3 async

5 async

(The setTimeout is there just for demo purposes)

Backup

The backup option, false by default, will make a copy of the current output file, postfix it with a timestamp and move it into backupPath.

Can you imagine an use for this?

Share it in the comments!

Thanks for reading!

Don't forget to add me on Twitter ok? :)

. . . . . . . . . .
Terabox Video Player