🦾 Tiny <2kb Markdown parser written, almost as fast and smart as Tony Stark

Overview

Starkdown 🦾

Total Downloads Latest Stable Version

Starkdown is a Tiny <2kb Markdown parser written, almost as fast and smart as Tony Stark.

npm i starkdown

Motivation

It is a continuation on a similar package called Snarkdown, which had stopped development at 1kb, but doesn't include basic support for paragraphs, tables, fenced divs, etc.

Starkdown stays around 1.6kb and adds these additional enhancements:

Usage

Starkdown is really easy to use, a single function which parses a string of Markdown and returns a String of HTML. Couldn't be simpler.

import { starkdown } from 'starkdown'

const md = '_This_ is **easy** to `use`.'
const html = starkdown(md)
console.log(html)

The html returned will look like:

<p><em>This</em> is <strong>easy</strong> to <code>use</code>.</p>

Paragraphs

With most Markdown implementations, paragraphs are wrapped in <p> tags. With Starkdown, this is no different.

  • All paragraphs and "inline" elements are wrapped in a <p> tags (See List of "inline" elements on MDN)
    • Eg. a standalone image will still be wrapped in a <p> tag, because it's an inline element.
  • All non-inline elements will not be wrapped in <p> tags
    • Eg. a table will not be wrapped in a <p> tag.
Check [github](https://github.com)

Img: ![](/some-image.png)

converts to

<p>Check <a href="https://github.com">github</a></p><p>Img: <img src="/some-image.png" alt="" /></p>

But also, when just using images and links:

[github](https://github.com)

![](/some-image.png)

converts to

<p><a href="https://github.com">github</a></p><p><img src="/some-image.png" alt="" /></p>

In contrast, non-inline elements won't get a <p> tag:

### Usage

\`\`\`js
const a = 1
\`\`\`

converts to

<h3>Usage</h3><pre class="code js"><code class="language-js">const a = 1</code></pre>

Tables

| My | Table |

converts to

<table><tr><td>My</td><td>Table</td></tr></table>

Fenced Divs

:::
this is some info
:::

converts to

<div class="fenced"><p>this is some info</p></div>

Or with a custom class.

::: info
this is some info
:::

converts to

<div class="fenced info"><p>this is some info</p></div>

Formating done Right

You need to pad your formatting with spaces in order to correctly convert sentences like these:

snake_case is _so-so_

correctly converts to

<!-- in this library -->
<p>snake_case is <em>so-so</em></p>

<!-- but in Snarkdown... -->
snake<em>case is </em>so-so<em></em>

I have greatly simplified the complex logic of Snarkdown and fixed formatting issues like these.

Security

Note on XSS: Starkdown doesn't sanitize HTML. Please bring your own HTML sanitation for any place where user input will be converted into HTML.

You might also like...

Scrap all (almost) posts from your instagram

inst scrap Scrap all (almost) posts from your instagram Дисклеймер Конечно это неопттимальный говнокод c багами) Но +- работает) Шаг 1 Залогиньтесь в

Mar 13, 2022

(Almost) monochromatic light theme for VSCode

(Almost) monochromatic light theme for VSCode

monotropic for Visual Studio Code (Almost) monochromatic theme for VSCode. Originally based on caffo/monotropic-theme (emacs). Install now 🛒 Screensh

Dec 18, 2022

A ~2kb hotkeys library for solid that adds only 2 event listeners.

A ~2kb hotkeys library for solid that adds only 2 event listeners.

Solid Hotkeys - Cmd+S+H Solid Hotkeys is the easiest way to add hotkeys to your application. Built for and with Solid. Motivation You gotta have hotke

Aug 1, 2022

A lightweight (~2kB) library to create range sliders that can capture a value or a range of values with one or two drag handles

range-slider-input A lightweight (~2kB) library to create range sliders that can capture a value or a range of values with one or two drag handles. Ex

Dec 24, 2022

Lightweight vanilla js modal component (just 2kb) , pure javascript Modal

Lightweight vanilla js modal component (just 2kb) pure javascript Modal , This is just 2kb Lightweight vanilla js modal component with zero dependenci

Dec 12, 2022

A jQuery Single/Multi Select plugin which can be used on almost any device

jquery.sumoselect jquery.sumoselect.js - A beautiful cross device Single/Multi Select jQuery Select plugin. A jQuery plugin that progressively enhance

Dec 7, 2022

Jsonup - This is a zero dependency compile-time JSON parser written in TypeScript

jsonup This is a zero dependency compile-time JSON parser written in TypeScript.

Dec 8, 2022

An obsidian plugin for uploading local images embedded in markdown to remote store and export markdown for publishing to static site.

An obsidian plugin for uploading local images embedded in markdown to remote store and export markdown for publishing to static site.

Obsidian Publish This plugin cloud upload all local images embedded in markdown to specified remote image store (support imgur only, currently) and ex

Dec 13, 2022

A plugin for the Obsidian markdown note application, adding functionality to render markdown documents with multiple columns of text.

A plugin for the Obsidian markdown note application, adding functionality to render markdown documents with multiple columns of text.

Multi-Column Markdown Take your boring markdown document and add some columns to it! With Multi Column Markdown rather than limiting your document lay

Jan 2, 2023
Comments
  • the ability to make text bold with**out** spaces

    the ability to make text bold with**out** spaces

    the ability to make text bold with**out** spaces
    

    should become:

    the ability to make text bold without spaces

    the ability to make text italic with_out_ spaces
    

    should become:

    the ability to make text italic with_out_ spaces

    and other languages without spaces:

    12時に**保存**済み
    

    should become

    12時に保存済み

    • [ ] should make ** usable without leading and trailing spaces
    • [ ] should make * usable without leading and trailing spaces
    • [ ] should make _ usable without leading and trailing spaces
    • [ ] should make ~~ usable without leading and trailing spaces
    opened by mesqueeb 0
Releases(v3.0.3)
  • v3.0.3(Sep 30, 2022)

    • refactor: improve tsconfig 2618e68
    • fix: correctly handle spaces/no spaces with _ and * formatting e90c339
    • chore: remove workflows and add github config 6180095
    • fix: change file extension cb4984c

    https://github.com/cycraft/starkdown/compare/v3.0.2...v3.0.3

    Source code(tar.gz)
    Source code(zip)
  • v3.0.2(Sep 10, 2022)

  • v3.0.1(Sep 10, 2022)

  • v3.0.0(Sep 10, 2022)

    • fix: metadata 31c1025
    • build: new release script 1985cb9
    • lint baa4c86
    • fix: many fixes and improvements f3ca550
    • fix: better paragraph handling dea60b1
    • fix: add types e3530fe
    • fix: prevent clashing variable name e113691
    • fix: unify inline element handling 9db4025
    • feat: auto-wrap in paragraphs &amp
    Source code(tar.gz)
    Source code(zip)
Owner
CyCraft
CyCraft
Horizontally scalable blockchain using STARK's and partitioned transactional memory

quark quark - quick STARK! A decentralized horizontally-scaled state machine that can transfer 1,000,000 unique tokens on Uniswap in a single atomic t

Liam Zebedee 56 Nov 25, 2022
Json-parser - A parser for json-objects without dependencies

Json Parser This is a experimental tool that I create for educational purposes, it's based in the jq works With this tool you can parse json-like stri

Gabriel Guerra 1 Jan 3, 2022
A markdown parser and compiler. Built for speed.

Marked ⚡ built for speed ⬇️ low-level compiler for parsing markdown without caching or blocking for long periods of time ⚖️ light-weight while impleme

Marked 28.9k Jan 7, 2023
Simple and Extensible Markdown Parser for Svelte, however its simplicity can be extended to any framework.

svelte-simple-markdown This is a fork of Simple-Markdown, modified to target Svelte, however due to separating the parsing and outputting steps, it ca

Dave Caruso 3 May 22, 2022
A simple inefficient and buggy JSON parser written in JavaScript. Just a fun project

A simple inefficient and buggy JSON parser written in JavaScript This JSON parser isn't guaranteed to work properly. Its recommended to use builtin JS

Pranav Baburaj 2 Feb 20, 2022
A Laravel Blade parser, compiler, and static analyzer written in TypeScript.

Blade Parser This library provides a Laravel Blade parser written in TypeScript. In addition to being able to parse Blade template files, this library

Stillat 7 Jan 4, 2023
A nonsensical React application made (almost) entirely by GitHub Copilot

GitHub Copilot Demo This is a demo project for the GitHub Copilot project. The previous sentence was written by it! This is a (fairly ugly) timer app

Cassidy Williams 32 May 1, 2022
The 2Kb smallest Chat component.

tidi Meet tidi, the 2kb bubble chat component for any website... made using preact, running with a 4MB compiled backend service. FrontEnd Backend Disc

darker 72 Dec 11, 2022
kimchi is a staple Korean side dish that's present at almost every meal.

(✿◠‿◠)*:・゚✧ (c) 02/2021 Dear reader, Essentially, kimchi is a staple Korean side dish that's present at almost every meal. It's fermented napa cabbage

null 0 Sep 20, 2022
Avoid use of dangerouslySetInnerHTML with this lightweight (2KB) function.

Avoid use of dangerouslySetInnerHTML with this lightweight (2KB) function. Can parse HTML strings into VDom trees, ready to render in your Preact components

James Hill 4 May 14, 2022