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

gemtext

v0.2.2

Published

A parser for text/gemini files

Downloads

31

Readme

gemtext

A parser for text/gemini files.

(NOTE: As of 2020.10.31, this library comfronts to Gemini specification v0.14.2 (July 2nd 2020).)

Usage

Basic usage:

import * as Gemtext from 'gemtext';

Gemtext.parse(yourSourceStringHere).generate(Gemtext.HTMLRenderer);

With built-in CLI tool:

gemtext [-s|--strict] [html|md|org] [input file name] [output file name]

[-s|--strict] and [output file name] can be omitted.

API

  • parse(source: string, strict: boolean = false): ParseResult
  • ParseResult.generate
    • generate<T>(Renderer: Renderer<T>): T
  • Renderers
    • Renderer<T>: The base type of all Renderers.
    • HTMLRenderer: Renderer<string> - Renderer that generates HTML string.
    • MarkdownRenderer: Renderer<string> - Renderer that generates Markdown string.
    • OrgRenderer: Renderer<string> - Renderer that generates org-mode string.

"Strict" gemtext

I decided to have my own take on a strict gemtext subset.

Things that are optional in the official spec but aren't in this subset:

  • 5.4.2 Link lines: there must be at least 1 whitespace character after =>.
  • 5.5.1 Heading lines: there must be at least 1 whitespace character after the last #.
  • 5.5.3 Quote lines: there must be at least 1 whitespace character after >.

Strict mode parsing does not raise exceptions; when a text line does not meet the strict requirements, it will be simply regarded as a normal (unformatted) text line.

Custom Renderer

To write your own custom Renderer, create a new object that contains the following methods:

  • preamble() - Preamble. e.g. HTML header stuff before main content.
  • postamble() - Postamble. e.g. HTML footer stuff before main content (e.g. closing <html> tags and stuff).
  • text(content: string) - normal text lines.
  • link(url: string, alt: string)
  • preformatted(content: string[], alt: string)
  • heading(level: number, text: string)
  • unorderedList(content: string[])
  • quote(content: string[])
const MyCustomRenderer: Gemtext.Renderer<string> = {
    // ...implement all the methods here.
}

Build

You'll need typescript.

npm run build