cfm

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2026 License: MIT Imports: 8 Imported by: 0

README

chameth.com-flavoured markdown

Go library that converts Markdown to HTML in the manner required for chameth.com.

[!WARNING] This code has been entirely written by LLMs, and I haven't reviewed it. The output seems to be byte-compatible with Goldmark aside from deliberate deviations. It's primarily intended for use in chameth.com, not as a general purpose library. Feel free to report bugs or raise issues if you do use it, but buyer beware.

Supports most CommonMark syntax and standard extensions like tables and footnotes, and applies smart typography and heading IDs.

Things it explicitly does NOT support:

  • indents to create code blocks - causes headaches in HTML heavy uses
  • setext headings
  • markdown images
  • reference links
  • various kitchen-sink syntaxes like *-*- dividers, trailing # in headings

Usage

import "chameth.com/cfm"

html := cfm.Markdown("Hello *world*")

// or with syntax highlighting
renderer := cfm.Renderer{
	Highlight: func(code, language string) (string, error) {
		return myHighlighter(code, language)
	},
}
html = renderer.Markdown(source)

Documentation

Overview

Package cfm implements chameth.com flavoured Markdown. Input must be trusted: raw HTML and unsafe URLs are preserved.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Markdown

func Markdown(source string) string

Markdown converts Markdown source to HTML with the default renderer.

Types

type Highlighter

type Highlighter func(code, language string) (string, error)

Highlighter renders the body of a fenced code block as complete, trusted HTML. It receives the verbatim code and the block's language. When it reports an error, the renderer falls back to an escaped plain code block.

type Renderer

type Renderer struct {
	// Highlight renders fenced code blocks. When nil, or when it reports an
	// error, fenced code falls back to escaped plain code.
	Highlight Highlighter
}

Renderer converts Markdown source to HTML. The zero value is ready to use.

func (Renderer) Markdown

func (r Renderer) Markdown(source string) string

Markdown converts Markdown source to HTML.

Jump to

Keyboard shortcuts

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