hexcerpt

package module
v0.0.0-...-077658d Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2025 License: MIT Imports: 4 Imported by: 0

README

go-hexcerpt

Package hexcerpt provides an http.Handler middleware to render hexcerpt (structured-HTML) to HTML, for the Go programming language.

hexcerpt is an HTML based format for creating excerpts with quotations and citations. hexcerpt uses some custom HTML elements.

An hexcerpt excerpt looks similar to this:

<x-excerpt>
	<x-quotation>
		<p>
			Yesterday I was clever, so I wanted to change the world.
			Today I am wise, so I am changing myself.
		</p>
	</x-quotation>
	<x-citation>
		⸺
		<x-who>Rumi</x-who>
	</x-citation>
</x-excerpt>

And this:

<x-excerpt>
	<x-quotation>
		<p>
			Anthropologists and linguists had long known that the way colors are classified varies from language to language.
			Careful studies conducted by anthropologists after World War II, such as Harold Conklin’s (1955) study of Hanunóo color words, made the point very clearly.
		</p>
	</x-quotation>
	<x-citation>
		⸺
		<x-who>Donald E. Brown</x-who>.
		(<x-when>1991</x-when>).
		<x-what>Human Universals</x-what>.
	</x-citation>
</x-excerpt>

Documention

Online documentation, which includes examples, can be found at: http://godoc.org/codeberg.org/reiver/go-hexcerpt

GoDoc

Example

Here is an example of using hexcerpt.WrapHTTPHandler() to wrap another handler, to provide hexcerpt (structured-HTML) to HTML rendering.

The http.Handler that hexcerpt.WrapHTTPHandler() returns looks at what the sub-http.Handler to see if the Content-Type it wrote has text/excerpt+html.

import "codeberg.org/reiver/go-hexcerpt"

// ...

var handler http.Handler = ...

handler = hexcerpt.WrapHTTPHandler(handler) // <---------

err := http.ListenAndServe(":8080", handler)
if nil != err {
	return err
}

Import

To import package hexcerpt use import code like the following:

import "codeberg.org/reiver/go-hexcerpt"

Installation

To install package hexcerpt do the following:

GOPROXY=direct go get codeberg.org/reiver/go-hexcerpt

Author

Package hexcerpt was written by Charles Iliya Krempeaux

Documentation

Index

Constants

View Source
const FileExtension string = ".hext"

FileExtension is constant for the file-extension used for hexcerpt files.

Here is an example of a hexcerpt file-name that has the ".hext" file-extension:

readme.hq
View Source
const MediaType string = "text/excerpt+html"

MediaType is a constant for the media-type used for harticle content.

Note that the value of the HTTP Content-Type response header and the HTTP Accept request header both use media-types.

Variables

This section is empty.

Functions

func Transform

func Transform(hext []byte) (html []byte, err error)

Transform accepts hexcerpt data and return HTML.

Note that the HTML is NOT a full HTML page.

func WrapHTTPHandler

func WrapHTTPHandler(subHandler http.Handler) http.Handler

WrapHTTPHandler provides http.Handler middleware.

If the http.Handler WrapHTTPHandler returns sees the "text/excerpt+html" media-type in the "Content-Type" response header generated by the sub-http.Handler AND "text/excerpt+html" isn't in the "Accept" request header, then it will transform the body to (regular) HTML (and change the "Content-Type" header to "text/html").

Types

This section is empty.

Jump to

Keyboard shortcuts

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