npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

simplemark

v0.2.2

Published

A smaller version of Markdown

Downloads

3

Readme

Simplemark

Demo website (demo code on gh-pages branch)

A smaller version of Markdown

~1KB gzipped

Code styled with Prettier

Why? Because Markdown parsers are large. The Commonmark JS parser is 36KB gzipped and others are of a similar size, which makes Markdown a bad format for saving, parsing, and presenting lightly formatted text in single page apps.

The idea is to create a format where the parser can be easily incorporated into single page apps so the raw string can be loaded from the backend and rendered into HTML on the frontend by the app. The format can be used for user generated content (posts, comments, etc...), and can be created using a GUI text editor or written directly.

Fast - the parser is single pass and runs in O(n) time where n is the number of characters in the string.

Current State

  • Supports Heading, Paragraph, Link, Emphasis, Strong, InlineBreak, and BlockBreak elements
  • The only pre-built renderer is for React (part of react-simplemark)
  • Todo
    • Add support for List, Image, BlockQuote, InlineCode, and ThematicBreak elements
    • Create plain HTML renderer
    • Create GUI text editor for generating Simplemark formatted text
    • Add fundamentals of the Simplemark format to the readme (blocks, inlines and nesting)
    • Create definitions for each type of element

Usage

$ yarn add simplemark
# OR
$ npm install --save simplemark

simplemark export's a single function which takes two arguments, the source string in Simplemark format and a renderer object with render functions for each type of element (Heading, Paragraph, Link, etc...).

import simplemark from 'simplemark';

const source = '# String in Simplemark format';
const renderer = {
  Heading({ level, children, key }) {/*return rendered element*/},
  Paragraph({ children, key }) {/*return rendered element*/},
  ...
};

const treeOfRenderedElements = simplemark(source, renderer);

Renderer

  • The renderer is an object with render functions for each type of element (Heading, Paragraph, etc... see list below).
  • Each render function receives as it's sole argument an object with keys for:
    • children an array the element's children (already rendered).
    • key a unique id among its parent's children (as a number).
    • Other properties specific to the element type (e.g. href and title for links).
    • If creating a renderer in React, each render function can be a React Component and the object it receives are its props.
  • Currently the only pre-built renderer is for React (part of react-simplemark).
// list of all element types created by Simplemark
// all keys are required
const renderer = {
  Heading({ level/*number from 1 to 6*/, children/*array*/, key/*number*/ }) {/*return rendered element*/},
  Paragraph({ children, key }) {/*return rendered element*/},
  Link({ href/*string*/, title/*string*/, children, key }) {/*return rendered element*/},
  Emph({ children, key }) {/*return rendered element*/},
  Strong({ children, key }) {/*return rendered element*/},
  InlineBreak({ key }) {/*return rendered element*/},
  BlockBreak({ key }) {/*return rendered element*/},
};