sidenote

package module
v0.0.0-...-bca622e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 15, 2020 License: MIT Imports: 10 Imported by: 0

README

goldmark-sidenote

A goldmark plugin for sidenotes designed for compatibility with tufte-css.

It was hacked together through some minor adjustments to goldmark's included footnotes extension, and (beware!) it probably doesn't work in lots of edge-cases.

Usage

package main

import (
	"bytes"
	"fmt"

	"git.sr.ht/~idmyn/goldmark-sidenote"
	"github.com/yuin/goldmark"
	"github.com/yuin/goldmark/parser"
)

func main() {
	markdown := goldmark.New(
		goldmark.WithExtensions(
			sidenote.Sidenote,
		),
	)

	source := `foobar[^fb] baz.
[^fb]: a meaningless placeholder`

	var buf bytes.Buffer
	context := parser.NewContext()
	if err := markdown.Convert([]byte(source), &buf, parser.WithContext(context)); err != nil {
		panic(err)
	}

	htmlOutput := buf.String()
	fmt.Println(htmlOutput)
}

html output (line breaks added for readability)

<p>
  foobar<span>
    <label for="sn-1" class="margin-toggle sidenote-number"></label>
    <input type="checkbox" id="sn-1" class="margin-toggle"/>
    <span class="sidenote">a meaningless placeholder</span>
  </span> baz.
</p>

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Sidenote = &sidenote{}

Sidenote is an extension that renders PHP Markdown Extra Footnotes as tufte-css-compatible sidenotes

Functions

func NewFootnoteASTTransformer

func NewFootnoteASTTransformer() parser.ASTTransformer

NewFootnoteASTTransformer returns a new parser.ASTTransformer that replaces footnote anchors with footnote content.

func NewFootnoteBlockParser

func NewFootnoteBlockParser() parser.BlockParser

NewFootnoteBlockParser returns a new parser.BlockParser that can parse footnotes of the Markdown(PHP Markdown Extra) text.

func NewFootnoteHTMLRenderer

func NewFootnoteHTMLRenderer(opts ...html.Option) renderer.NodeRenderer

NewFootnoteHTMLRenderer returns a new FootnoteHTMLRenderer.

func NewFootnoteParser

func NewFootnoteParser() parser.InlineParser

NewFootnoteParser returns a new parser.InlineParser that can parse footnote links of the Markdown (PHP Markdown Extra) text.

Types

type FootnoteHTMLRenderer

type FootnoteHTMLRenderer struct {
	html.Config
}

FootnoteHTMLRenderer is a renderer.NodeRenderer implementation that renders Footnote nodes.

func (*FootnoteHTMLRenderer) RegisterFuncs

RegisterFuncs implements renderer.NodeRenderer.RegisterFuncs.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL