markup

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package markup strips HTML/XML markup, leaving normalized plain text.

Unlike formatting-oriented html2text converters, StripTags produces strictly normalized text under normtext's determinism and golden-freeze guarantees: tags dropped, entities decoded, block boundaries becoming single newlines, script/style/title contents dropped. It is not a boilerplate or readability extractor — structural stripping only.

Behavior is pinned by the golang.org/x/net version in go.mod (its tokenizer and entity table are the Unicode-dependent surface here).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func StripTags

func StripTags() normtext.Transform

StripTags returns a Transform that removes HTML/XML tags and decodes entities, leaving plain text. It uses x/net/html tokenization (not regexes), so malformed markup degrades deterministically rather than catastrophically. Rules (frozen):

  • Tag and attribute content, comments, and doctypes are dropped.
  • The contents of the raw-text elements script, style, title, iframe, noembed, and noframes are dropped.
  • Block-level boundaries (p, div, br, li, headings, tr, table, ...) become a single newline; td/th boundaries become a single space; inline tags (span, b, a, ...) add nothing.
  • Entities decode to their characters: "&amp;" → "&", "&lt;" → "<".
  • Text outside tags is preserved verbatim, including whitespace.

NOT idempotent: decoded entities can form new tag-like text ("&lt;b&gt;" → "<b>", which a second application would strip). Apply once. Input containing neither '<' nor '&' passes through allocation-free; input the tokenizer leaves unchanged (e.g. "a < b") returns the original string. Invalid UTF-8 is handled deterministically by the tokenizer.

func StripTagsStep

func StripTagsStep() normtext.Step

StripTagsStep is StripTags as a Pipeline step, named "markup/striptags".

Types

This section is empty.

Jump to

Keyboard shortcuts

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