a4code2html

package
v0.0.197 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2026 License: AGPL-3.0 Imports: 9 Imported by: 0

Documentation

Overview

Package a4code2html converts a small markup language into HTML or alternative formats.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SanitizeURL

func SanitizeURL(raw string) (string, bool)

SanitizeURL validates a hyperlink and returns a safe version.

Types

type A4code2html

type A4code2html struct {
	CodeType CodeType

	// ImageURLMapper optionally maps tag URLs to fully qualified versions.
	// The first parameter provides the tag name, e.g. "img" or "a".
	ImageURLMapper func(tag, val string) string
	// UserColorMapper optionally maps a username to a CSS class for styling quotes.
	UserColorMapper func(username string) string

	// Provider optionally provides custom rendering for links.
	Provider LinkProvider
	// contains filtered or unexported fields
}

func New

func New(opts ...interface{}) *A4code2html

New returns a configured A4code2html converter. Optional arguments may set the output CodeType, enable table of contents generation or provide a custom ImageURLMapper. A *bufio.Reader, io.Reader or io.Writer may be supplied to configure the input or output streams.

func (*A4code2html) Error

func (c *A4code2html) Error() error

Error returns the last processing error, if any.

func (*A4code2html) Escape

func (c *A4code2html) Escape(ch byte) string

func (*A4code2html) Process

func (c *A4code2html) Process() io.Reader

Process converts the markup from the configured reader and returns an io.Reader containing the result. If a writer was provided via New or SetWriter, the output is written there and an empty reader is returned.

func (*A4code2html) ProcessReader

func (c *A4code2html) ProcessReader(r io.Reader, w io.Writer) error

ProcessReader converts the markup from r and writes the result to w in a streaming fashion.

func (*A4code2html) SetInput

func (c *A4code2html) SetInput(s string)

SetInput assigns the text to be processed.

func (*A4code2html) SetReader

func (c *A4code2html) SetReader(r io.Reader)

SetReader assigns the reader supplying the markup.

func (*A4code2html) SetWriter

func (c *A4code2html) SetWriter(w io.Writer)

SetWriter assigns the destination for rendered output.

type CodeType

type CodeType int

CodeType defines the output mode for A4code2html.

const (
	// CTHTML produces standard HTML output.
	CTHTML CodeType = iota

	// CTTableOfContents outputs only the table of contents.
	CTTableOfContents

	// CTTagStrip removes all formatting tags.
	CTTagStrip

	// CTWordsOnly returns only the raw words.
	CTWordsOnly
)

type LinkProvider

type LinkProvider interface {
	RenderLink(url string, isBlock bool, isImmediateClose bool) (htmlOpen string, htmlClose string, consumeImmediate bool)
	MapImageURL(tag, val string) string
}

LinkProvider provides HTML rendering for links and maps image URLs.

type WithTOC

type WithTOC bool

WithTOC enables or disables table-of-contents generation when passed to New.

Jump to

Keyboard shortcuts

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