Giter Site home page Giter Site logo

angrykoala / yamp Goto Github PK

View Code? Open in Web Editor NEW
28.0 4.0 14.0 1.35 MB

Yet Another Markdown Parser

Home Page: https://angrykoala.github.io/yamp/

License: GNU General Public License v3.0

JavaScript 79.25% CSS 17.86% HTML 2.89%
markdown markdown-parser marked nodejs javascript pdf html

yamp's Introduction

Yamp

by @angrykoala

npm version Build Status codecov Dependency Status

Yet Another Markdown Parser

The aim of this package is to provide an easy-to-use toolbox for markdown-related task including Html & Pdf conversion.

Features

  • HTML conversion
  • PDF conversion
  • Code highlight support
  • Github-style and academic output
  • API to use yamp programmatically
  • Custom styles
  • CSS-embedded HTML (just open it offline in any browser)
  • HTML tags support (for PDF output too)
  • Include other files in your markdown
  • HTML presentations
  • Front Matter metadata
  • Custom xejs-based tags ({{}})
  • Koalafied

Upcoming features

  • Custom templates
  • Client-side web support (browserify)

Check the project roadmap and our cute kanban board

Installation

To use yamp cli, install it globally using npm:

npm install -g yamp

If you want to use the API instead, install it locally:

npm install --save yamp

then, include yamp in your javascript:

var yamp = require('yamp');

Usage

To create a .pdf file from your markdown file, simply type:

yamp <file.md>

For example:

yamp README.md

Will generate readme.pdf.

Options

  • -h, --help to display a basic usage information
  • -V, --version to display yamp version installed
  • -o, --output <file> output filename (without extension) e.g. yamp my_file.md -o final_name
  • --pdf to generate a pdf (default)
  • --htmlto generate html
  • --remarkto generate a html presentation using remark
  • -t, --title [value] to add a custom title to Html pages
  • --style <file> to set change the css style (supports the provided styles and custom styles)
    • Option not suported along with --no-style
  • --no-style to disable CSS styling
    • Option not supported along with --style <file>
  • --list-styles will list all the styles provided by yamp
    • These styles will be supported by --style option
  • --minify to minify Html output
  • --no-tags to disable custom Yamp tags
  • --no-highlight to disable code highlight
  • --no-front-matter to disable front-matter metadata
  • -k, --koala to koalify your outputs

To generate pdf and html with default styling and options:

yamp myFile.md --pdf --html

The --no-highlight and --no-style options will greatly reduce your Html and Pdf outputs

Yamp tags

Yamp supports extra tags in your markdown files. Currently using xejs templates. All tags are written between double braces {{ ... }} and are not case-sensitive

  • include [file.md]: Includes the given text file (markdown or not), the tags on the included file will also be parsed, allowing nested file structure.
  • date: Will write the current date (at the moment of rendering).
  • page break: Will force a page break in pdf output.
  • yamp version: Will display the yamp version used to render the document.

Starting a tag with {{# will create a comment tag that will not be rendered into the final file

Yamp styles

Yamp provides several styles for your document (supported for html and pdf outputs).

  • github.css Default style, will look similar to Github style
  • acm-sig.css Academic style based on ACM SIG templates

You can select any of these styles with the option --style [style.css], the same option will enable you to use your own files instead --style [myfolder/mystyle.css]

You can always check the styles with the option --list-styles

API

Include yamp in your javascript with:

var yamp = require('yamp');

You'll have access to different renderers to process your files:

  • yamp.renderers.html to process a markdown file into an full Html page
  • yamp.renderers.pdf to process a markdown into a pdf

To use a renderer:

var myRenderer = new renderers.pdf(options);
renderer.renderFile(myFile, function(err){
    if (err) return console.log("Error while rendering: "+err);
    else console.log("Rendering was successful");
});

Options

The options accepted by the default renderers are:

  • outputFilename: name of the output filename (without extension), will default to the input filename
  • highlight: (true) indicates if code blocks should be highlighted
  • style: (true) indicates if default style should be used or no style at all. If a filename is passed, it will use it as custom css style
  • minify: (false) whether the Html output should be minified or not
  • title: Custom title for the Html page
  • tags: (true) whether to parse yamp tags or not ({{ ... }})
  • koala: (false) true to koalify your outputs

Creating new renderers

If you need a custom renderer, instead of using one of the defaults you can extend directly from Renderer class or any of the default renderers:

class MyCustomRenderer extends yamp.Renderer {
    constructor(options) {
        super(options, "default.ejs", yamp.parsers.md2Html);
        this.output="html"; //desired output extension
    }

    beforeLoad(filename){
        //Modify filename or this.fileLoader before loading it
    }


    beforeRender(templateOptions) {
        // Modify the data passed to the template before rendering, including title, content and options
    }
    
    afterRender(content) {
        // Modify template result (Html)
    }

    fileOutput(content,done) {
        // Write file (preferably to this.options.outputFilename) in the desired format using a parser
    }
}

Custom parser: It is possible to use a custom parser from markdown to Html instead of the built-in yamp.parsers.md2html, the parser must be a function of the type function(originalString,options,callback) that will translate from originalString (markdown) to html, calling the callback(err,res) afterwards.

If, instead of extending from yamp.Renderer you are extending from one of the default renderers, you should only re-implement the methods you need, and usually you should call super().methodName to maintain its basic functionality.

Development Instructions

To contribute to yamp you should clone the official repository https://github.com/angrykoala/yamp or your own fork with git.

You can also download it from GitHub clicking here

  • To install execute npm install in the downloaded/cloned folder
  • To test, execute npm test
    • The tests will also run jshint
  • To execute the CLI, execute npm start -- <file> [options]
  • To install your local version globally, execute npm install -g . on the project folder
  • To generate documentation (with installed version of yamp) execute npm run docs

It is strongly recommended to install the npm repository version instead of your local copy

Contributors

If you want to contribute to yamp please:

  1. Read CONTRIBUTING.md
  2. Fork from dev branch
  3. Make sure tests passes before pull request
  4. Check the opened and closed issues before creating one

Thanks for your help!

Acknowledgments

YAMP is developed under GNU GPL-3 license by @angrykoala

yamp's People

Contributors

andrewda avatar angrykoala avatar bbohen avatar cosminlupu avatar daanvanham avatar dbradf avatar kbariotis avatar limaagabriel avatar sarupbanskota avatar simeg avatar smddzcy avatar tenshi13 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

Watchers

 avatar  avatar  avatar  avatar

yamp's Issues

Support html attributes in title parser

Currently, title parser accepts any html header 1 of the form <h1>Title</h1>, however, it doesn't support using attributes such as <h1 class="title">Title</h1>

One solution would be changing the current regex into a regex that accepts arguments and adapting the slice call that get the content to use other regex

/<h1(.*?>).+?<\/h1>/

Include code highlight only if necessary

Using the highlightRenderer and a flag boolean, it should be possible to disable highlight automatically if no code block was created (check this) so highlight css and js will only be included if needed

Force page jump tag

use a tag (like {{page-jump}} or in markdown files to force a page-jump on pdf output

this tag should follow the same rules as the tags defined on #15

and options (maybe default) should apply a page jump on every <h1>

Code beautifier

Add code beautifier to project workflow (for example js-beautify)

Support include in markdown

Support some include tags to compile several .md files into one file (check current standards on extra tags for markdown)

e.g.

# My Book
{include chapter1.md}
{include chapter2.md}
**The End**

Add tests and CI

Make some basic tests checking all the parsing and add continuous integration service to the repo

Client-side markdown parser

user browserify or similar to provide a client-side parser, allowing to dynamically parse blocks of code

e.g.

<p class="markdown">
   ## A nice header
</p>

Support custom parser

provide one (or more) default parsers, but allow the usage of other markdown parsers optionally

Separate renderers in module renderer

have to separate function (or classes) for each type of rendering (children of a parent class maybe?) and export all of them, so you don't need to pass an output value with your configuration object.

So it loads something like:

var htmlRenderer=require('./app/renderer').html;

Code blocks truncated

Code blocks are formatted in HTML using the

 ... </ code></ pre> tags. If the block is greater than the width of the page, a horizontal scroll bar is displayed (as github pages, off course).

When creating the PDF, this bar is displayed as a static image, it does not allow scrolling text, and the right side is hidden.

This effect is increased because the font in the PDF is too big. With the current font, the code block has a width of 61 characters, apparently.

For example, the following block:

text in a code block with many characters:
1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890

will create this HTML code:

<pre><code> text in a code block with many characters:
1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
</code></pre>

to display in the PDF as follows:

captura

Inject css into html

inject styles within the html (optional) to make it easier to open and process into a pdf

Elements are being cut by pages

The Text and elements are not 'page aware' in the pdfs, so tables, images and stuff may be directly cut between pages.

Make all this content page aware, and force a page break when an element doesn't fit

Create npm package

create a npm package/module, easy to install and add to a node project

Check pdf-html fonts

The font-size should be similar in the html and pdf output, check github style.

relate to #12

Header and footer support for pdfs

using <div id="pageHeader"></div> and <div id="pageFooter"></div> it would be possible to customize the pdf header and footer of each page

Module API

API to use yamp as a module, importing it into a node app

Accept metadata in markdown file

A header in some standard format (json, yml, etc..) could provide some compiling default information (title, style etc..). (Front-matter)

Add support for metadata headers in markdown.
e.g.

title: mytitle
style: mystyle
tags: false
-------------
# my md file

Live parser

Create a real-time md parser that only process the changed elements

Avoid parsing unwanted tags

Add a step to change unwanted markdown tags <% tags into <%%

for example, when the tag is inside a code block

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.