Pipeline
The grammar pipeline connects go-html rendering to go-i18n's reversal engine, enabling semantic verification of rendered output via GrammarImprint.
See also: Home | Architecture | Node-API | WebAssembly | Code-Generation
Pipeline Flow
Node Tree
│
▼ Render(ctx)
HTML String
│
▼ StripTags()
Plain Text
│
▼ reversal.NewTokeniser().Tokenise()
[]Token
│
▼ reversal.NewImprint().Build()
GrammarImprint
The pipeline transforms rendered HTML into a grammar fingerprint that captures the linguistic structure of the content without preserving the actual words.
StripTags
func StripTags(html string) string
Removes all HTML tags and collapses whitespace. Handles nested elements, void tags, and attribute content. Used as the bridge between HTML rendering and grammar analysis.
text := html.StripTags("<h1>Hello <em>World</em></h1>")
// "Hello World"
Imprint
func Imprint(node Node, ctx *Context) reversal.GrammarImprint
Runs the full pipeline: render → strip tags → tokenise → build imprint. Returns a GrammarImprint from go-i18n's reversal engine.
node := html.El("p", html.Text("page.greeting"))
imprint := html.Imprint(node, ctx)
// imprint is a lossy feature vector of the grammar structure
What GrammarImprint Captures
The imprint records grammar features without content:
| Feature | Example |
|---|---|
| Verb tenses | "built" → past tense detected |
| Noun forms | "tests" → plural detected |
| Article usage | "an API" → indefinite article |
| Sentence structure | SVO ordering, clause boundaries |
| Token distribution | Ratio of verbs/nouns/articles/unknown |
The imprint is lossy — you cannot reconstruct the original text from it. This is by design: it's a privacy-preserving grammar fingerprint.
CompareVariants
func CompareVariants(r *Responsive, ctx *Context) map[string]float64
Renders all variants of a Responsive layout, computes GrammarImprint for each, and returns pairwise similarity scores.
resp := html.NewResponsive().
Variant("desktop", desktopLayout).
Variant("mobile", mobileLayout)
scores := html.CompareVariants(resp, ctx)
// {"desktop:mobile": 0.85}
Use Cases
- Content parity testing — Verify that mobile and desktop variants render linguistically equivalent content
- A/B testing grammar — Compare how different layouts affect text structure
- Regression detection — Alert when a layout change significantly alters the grammar profile
- Poindexter integration — Feed imprint distances into the Lethean analysis layer
Integration with go-i18n
The pipeline depends on go-i18n's reversal engine:
| go-i18n Component | Role in Pipeline |
|---|---|
i18n.Service |
Text lookup and grammar composition |
reversal.Tokeniser |
Classifies words as verb/noun/article/unknown |
reversal.GrammarImprint |
Lossy feature vector projection |
reversal.Multiplier |
Training data augmentation (not used in pipeline, but available) |
The Context.Service field carries the i18n service. When nil, Text() nodes return the raw key string, and Imprint() still works (tokenising the key names instead of localised text).