gemtext
    TypeScript icon, indicating that this package has built-in type declarations

    0.2.2 • Public • Published

    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
    

    Keywords

    Install

    npm i gemtext

    DownloadsWeekly Downloads

    2

    Version

    0.2.2

    License

    BSD-3-Clause

    Unpacked Size

    36.9 kB

    Total Files

    10

    Last publish

    Collaborators

    • bctnry