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

ponymark

v3.3.4

Published

Next-generation PageDown fork

Downloads

13

Readme

ponymark

Next-generation PageDown fork

Click here for a demo

Features

Install

npm i -S ponymark
bower i -S ponymark

Then you have to provide it with a function that can parse Markdown. This can be a function you wrote by yourself or a reference to a module such as a ultramarked.

ponymark.configure({
  markdown: function (text) {
    return parse(text);
  }
});
ponymark.configure({
  markdown: require('ultramarked')
});

Usage

Just include the JavaScript and call the ponymark method on a <textarea> element. You'll get a button bar, the editor, and a preview area just like the one in StackOverflow. Remember to include the CSS to get the button bar working correctly. You can include the Stylus sources directly. The syntax highlighting styles come bundled separately, so that you can pick any other you want.

Test syntax highlighting themes here, then download them here. Just include the style files as is, and you'll be fine.

var elem = document.querySelector('textarea');
ponymark(elem);

You can also specify different containers for the editor and the HTML preview. This is useful when you have multiple inputs and then want the preview to be placed somewhere else in the DOM.

ponymark({
  textarea: document.querySelector('textarea'),
  preview: document.querySelector('footer')
});

Image Uploads

Ponymark supports image uploading through your site. Simply configure it before invoking ponymark.

ponymark.configure({
  imageUploads: '/api/v1/images'
});

You can specify a method by passing an object instead. The default method used is PUT, and the default FormData key used to upload the image is 'image'.

ponymark.configure({
  imageUploads: {
    method: 'POST',
    url: '/api/v0/images',
    key: 'imgur'
  }
});

Server-Side

Ponymark will send requests to the specified HTTP resource with the user image. As for the server-side, a helper is provided, and you can use it as demonstrated below with your favorite web back-end of choice. Here's an example using express@^4.1.2.

'use strict';

var path = require('path');
var ponymark = require('ponymark');
var dir = path.resolve('./temp/images');

module.exports = function (req, res, next) {
  var options = {
    // note that the key should match imageUploads.key, see above
    image: req.files && req.files.image,
    imgur: process.env.IMGUR_API_KEY,
    local: dir
  };

  ponymark.imageUpload(options, uploaded);

  function uploaded (err, result) {
    if (err) {
      errored(err.message); return;
    }
    res.status(200).json(result);
  }

  function errored (message) {
    res.status(400).json({ messages: [message] });
  }
};

If an API key to imgur isn't provided, then the local file system will be used. That is super unreliable in production environments, so either provide the API key, or implement your own endpoint. The local file system functionality is entirely disabled when process.env.NODE_ENV === 'production'. The local option specifies the directory where files will be uploaded to, and the localUrl method is provided an absolute file path, and expects you to return the URL you'll be using to serve that file from. That url will only be used for the response.

The HTTP endpoint is expected to return a JSON response like the one below. This is the type of response returned in result if the upload doesn't fail.

{
  "url": "http://i.imgur.com/cC3fCEN.jpg",
  "alt": "doge.png"
}

Screenshot

screenshot.png

License

MIT