Coder Social home page Coder Social logo

micro-down's Introduction

micro-down

micro-down

JavaScript based Markdown parser without dependencies.

1.4kB markdown parser (minified + gzipped)

check out this demo

npm install -S micro-down

usage

micro-down exports 4 functions, although you mostly want to use parse.

parse turns the full markdown into html

const result = markdown.parse('_this_ is **MARKDOWN**');

inline replaces only the inline markup. (bold,italic,underline,strike-trough,line-breaks); inlineBlock transforms only inline code blocks ands media block handles everything else, see below.

As a second parameter you can pass an options object:

option type default description
preCode boolean false wrap pre blocks ``` in <pre><code>

support:

  • Headlines: ### Headline
  • Inline:
    • *italic*, **bold**, ***bold italic***
    • `_code_="- something";` or direct escaping with \
    • ~underline~, ~~strike through~~, ~~~deleted~~~
  • Blocks:
    • pre format blocks: surrounded by ```
    • div blocks: """ just a div block """
    • blockquotes: > something
    • class support
  • Anchors: #[jump-here]
  • Links: [Label](destination Title)
    • URL auto linking https://github.com/coding-intl/micro-down
  • Images: ![label](source altText))
    • linked: [![label](source altText))](destination Title)
  • IFrames: &[class](url) &[width,height,frame class](url)
  • Lists:
    • Unordered lists using: + and -
    • Ordered lists using: 1.
    • Nested lists
  • Tables: | some | text |
    • Header row: |- header -|- row -| or by a following |---
  • Comments <!-- # Comment -->

micro-down's People

Contributors

shynrou avatar exside avatar hipstersmoothie avatar kiasaki avatar

Stargazers

Artem avatar Hyeseong Kim avatar Kid avatar Alex Khrustalev avatar Chris Puska avatar Chiantine P. Manigos avatar Ben Hsieh avatar  avatar Marcis Bergmanis avatar Ciro Lo Sapio avatar Luca Ban avatar Rouven Spreckels avatar Shinji Yamada avatar Sean Lester-Wilson avatar  avatar  avatar Hadrien TOMA avatar  avatar Tom Golden avatar Dennis Schoepf avatar  avatar Sarah Ziegler avatar

Watchers

James Cloos avatar Artem avatar Rouven Spreckels avatar  avatar

micro-down's Issues

Set target for links?

Hello,

is there a way to add target="_blank" to links in markdown?

We used Markdownit before and here attributes could be specified in the form {target="_blank"} .

Thanks for some help!

Best regards,

Timo

Inline code blocks make parser fail

Also discovered that if inline code blocks with HTML tags exists within the markup, the parser fails:

Headings should be `<h1>` through `<h6>` tags, groups of objects should be marked up as `<ul>` or `<ol>` tags, and so on.

the result will look like that:

image

<pre><code> instead of <pre>

: tag('pre', encode(text), {class: c}),

In order to make PrismJS syntax highlighting work, it requires all code blocks to be formatted like so:

<pre>
  <code>
// the code
  </code>
</pre>

But I believe micro-down only uses <pre> without <code>.

My request is that snarkdown uses <pre><code> by default OR via an option.

From the PrismJS docs:

Encourages good author practices. Other highlighters encourage or even force you to use elements that are semantically wrong, like <pre> (on its own) or <script>. Prism forces you to use the correct element for marking up code: <code>. On its own for inline code, or inside a <pre> for blocks of code. In addition, the language is defined through the way recommended in the HTML5 draft: through a language-xxxx class.

https://prismjs.com/#features-full

Nested list indented with tabs fail to parse

Coming from the same auto-generated nested TOC list as mentioned in #2 I found an issue with the indenting this Atom plugin is doing, it uses tabs instead of two spaces, that messes up the parser and it will instead print this:

<ul><li>undefined</li><li>undefined</li>

but maybe this is also a non issue as I'm not able to reproduce it...I switched to two spaces indenting for the nested list to see if that fixes it (after playing around in your demo), which it did, then I reverted back to tabs to create this issue, and still the parsing works fine^^...no idea what happened there, I could also reproduce it in the demo though...

license: any chance you'd reconsider?

Your micro-down parser looks really great but I can't incorporate a gpl-licensed piece in my open source project. Any chance you'd reconsider and use a more permissive license?

Do not wrap HTML comments in p-tags

First of all, amazing work you have done here!

Second I though it would probably be better to ignore HTML comments within the markdown text, for example I have an automatic TOC generator that will wrap the generated (nested) list into HTML comments, that will end up like this after parsing:

<p><!-- TOC depthFrom:1 depthTo:4 withLinks:1 updateOnSave:1 orderedList:0 --></p>

not a big deal, but you'll get some extra spacing because of that.

anchor in nested list breaks the html

JS version : May 4 2021

added links to your example :

1. Lists can be structured and layered
  1. like this
  2. for example
  3. [NTS Radio](https://www.nts.live/) - London
2. __and can also be mixed__
	- like
	+ this
	- [NTS Radio](https://www.nts.live/) - London
	+ [Radio Musical De Cuba](https://www.cmbfradio.cu/) - Havana

then rendered as (shot by another project)
2023-11-17_173530

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.