New: Introducing PHP and Composer Support.Read the Announcement
Socket
Book a DemoInstallSign in
Socket

ser1.net/godjot/v2

Package Overview
Dependencies
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ser1.net/godjot/v2

Go Modules
Version
v2.0.5
Version published
Created
Source

godjot

Go Report Card Build status

Djot markup language parser implemented in Go language

The original project is on github.

Installation

You can install godjot as a standalone binary:

$ go install ser1.net/godjot/v2@latest
$ echo '*Hello*, _world_' | godjot
<p><strong>Hello</strong>, <em>world</em></p>

Usage

godjot provides API to parse AST from djot string

var djot []byte
ast := djot_parser.BuildDjotAst(djot)

AST is loosely typed and described with following simple struct:

type TreeNode[T ~int] struct {
    Type       T                     // one of DjotNode options
    Attributes tokenizer.Attributes  // string attributes of node
    Children   []TreeNode[T]         // list of child
    Text       []byte                // not nil only for TextNode
}

You can transform AST to HTML with predefined set of rules:

content := djot_html.New().ConvertDjot(&djot_html.HtmlWriter{}, ast...).String()

Or, you can override some default conversion rules:

content := djot_html.New(
    djot_html.DefaultConversionRegistry,
    map[djot_parser.DjotNode]djot_parser.Conversion[*djot_html.HtmlWriter]{
        djot_parser.ImageNode: func(state djot_parser.ConversionState[*djot_html.HtmlWriter], next func(c djot_parser.Children)) {
            state.Writer.
                OpenTag("figure").
                OpenTag("img", state.Node.Attributes.Entries()...).
                OpenTag("figcaption").
                WriteString(state.Node.Attributes.Get(djot_parser.ImgAltKey)).
                CloseTag("figcaption").
                CloseTag("figure")
        },
    }
).ConvertDjot(&djot_html.HtmlWriter{}, ast...).String()

This implementation passes all examples provided in the spec but can diverge from original javascript implementation in some cases.

FAQs

Package last updated on 15 Sep 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts