GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - git-pkgs/markup: A Go library for rendering markup files to HTML

BranchesTags
Open more actions menu

Latest commit

 

History

23 Commits
23 Commits

Folders and files

NameName
Last commit message
Last commit date
.github
.github
 
 
testdata
testdata
 
 
.gitignore
.gitignore
 
 
.golangci.yml
.golangci.yml
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
benchmark_test.go
benchmark_test.go
 
 
external.go
external.go
 
 
go.mod
go.mod
 
 
go.sum
go.sum
 
 
markdown.go
markdown.go
 
 
markup.go
markup.go
 
 
markup_test.go
markup_test.go
 
 
org.go
org.go
 
 

Repository files navigation

markup

A Go library for rendering markup files to HTML. Given a filename and its contents, it picks the right renderer and produces HTML.

Markdown and Org-mode are rendered natively in Go. Other formats (AsciiDoc, reStructuredText, Pod) shell out to external tools. The library has no global state, no forge-specific logic, and no opinion on post-processing.

Installation

go get github.com/git-pkgs/markup

Usage

r := markup.NewDefaultRegistry()

result, err := r.Render("README.md", content)
if err != nil {
    log.Fatal(err)
}
fmt.Println(result.HTML)
fmt.Println(result.Format) // "Markdown"

The default registry comes with all supported formats pre-configured. Native formats (Markdown, Org-mode) always work. External formats return markup.ErrToolNotFound if the required tool isn't on $PATH.

Supported formats

Format Extensions Renderer
Markdown .md, .markdown, .mdown, .mkdn, .mdn, .mdtext, .livemd goldmark (native)
Org-mode .org go-org (native)
AsciiDoc .adoc, .asciidoc, .asc asciidoctor (external)
reStructuredText .rst, .rest, .rst.txt rst2html (external)
Pod .pod pod2html (external)
Textile .textile consumer-provided (external)
MediaWiki .mediawiki, .wiki consumer-provided (external)
Creole .creole consumer-provided (external)
RDoc .rdoc rdoc (external)

Format detection

format := markup.Detect("README.org") // markup.FormatOrg
format.String()                       // "Org"

Custom renderers

Register your own renderer for any format:

r := markup.NewRegistry()

r.Register(markup.FormatMarkdown, markup.NewMarkdownRenderer(), ".md", ".markdown")

r.Register(markup.FormatTextile, markup.NewExternalRenderer(markup.ExternalConfig{
    Command: "pandoc",
    Args:    []string{"-f", "textile", "-t", "html"},
}), ".textile")

// Exact filename matching
r.RegisterFilename(markup.FormatMarkdown, markup.NewMarkdownRenderer(), "README")

Errors

result, err := r.Render("README.adoc", content)
if errors.Is(err, markup.ErrUnsupportedFormat) {
    // no renderer registered for this extension
}
if errors.Is(err, markup.ErrToolNotFound) {
    // renderer registered but external tool not on $PATH
}

Installing external tools

The native formats (Markdown, Org-mode) need no external tools. For the others:

Tool Install Formats
asciidoctor gem install asciidoctor AsciiDoc
rst2html pip install docutils or apt install python3-docutils reStructuredText
pod2html Included with Perl Pod
rdoc Included with Ruby RDoc

Benchmarks

BenchmarkMarkdownSmall     387460    3155 ns/op     7448 B/op     33 allocs/op
BenchmarkMarkdownMedium     43614   27558 ns/op    30626 B/op    196 allocs/op
BenchmarkMarkdownLarge        813 1466013 ns/op  1561079 B/op  11432 allocs/op
BenchmarkOrgSmall          104258   11548 ns/op    11897 B/op    131 allocs/op
BenchmarkOrgFixture          1729  688588 ns/op   236167 B/op   2084 allocs/op

External renderers are dominated by subprocess overhead (~30ms for pod2html, ~90ms for rst2html, ~120ms for asciidoctor).

License

MIT.

About

A Go library for rendering markup files to HTML

git-pkgs.dev

Topics

asciidocgit-pkgsgogolanghtmlmarkdownmarkup

Resources

Readme
MIT license

Code of conduct

Code of conduct

Contributing

Contributing

Security policy

Security policy
Activity
Custom properties

Stars

1 star

Watchers

1 watching

Forks

0 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.