DialectoInContext.Marker (dialecto_in_context v0.1.0)

Copy Markdown View Source

The in-context marker codec v1 (spec-0016 ยง3), byte-identical to the overlay's codec.js and the Astro add-on's encoder.

A marked text is OPEN + header + HEADER_END + text + CLOSE. The header is the UTF-8 payload domain US key US locale (optionally RS argsJSON), each byte written as four base-4 digits, most significant first. Every marker codepoint is Default_Ignorable, so the text renders unchanged; they are written here by number, never as literal invisible characters.

Summary

Types

One marked segment found by parse/1.

Functions

The CLOSE codepoint.

The four digit codepoints, values 0โ€“3.

The HEADER_END codepoint.

text wrapped in a marker for {domain, key, locale}. args_json, when given, is recorded after U+001E in the header (it must be JSON, which never holds a raw U+001E).

True when text holds a marker opening.

The OPEN codepoint.

Every well-formed marked segment of text, outer before inner, with its clean text. Malformed headers and unbalanced CLOSEs are ignored; an OPEN never closed extends to the end and is flagged open: true.

Everything that precedes the marked text: OPEN, the header digits, HEADER_END.

text without markers. Digit codepoints outside a header (a real ZWJ in an emoji) are kept, like the overlay's stripMarks.

Types

segment()

@type segment() :: %{
  domain: String.t(),
  key: String.t(),
  locale: String.t(),
  args: map() | nil,
  text: String.t(),
  open: boolean()
}

One marked segment found by parse/1.

Functions

close()

The CLOSE codepoint.

digits()

The four digit codepoints, values 0โ€“3.

header_end()

The HEADER_END codepoint.

mark(domain, key, locale, text, args_json \\ nil)

@spec mark(String.t(), String.t(), String.t(), String.t(), String.t() | nil) ::
  String.t()

text wrapped in a marker for {domain, key, locale}. args_json, when given, is recorded after U+001E in the header (it must be JSON, which never holds a raw U+001E).

marked?(text)

@spec marked?(term()) :: boolean()

True when text holds a marker opening.

open()

The OPEN codepoint.

parse(text)

@spec parse(String.t()) :: [segment()]

Every well-formed marked segment of text, outer before inner, with its clean text. Malformed headers and unbalanced CLOSEs are ignored; an OPEN never closed extends to the end and is flagged open: true.

prefix(domain, key, locale, args_json \\ nil)

@spec prefix(String.t(), String.t(), String.t(), String.t() | nil) :: String.t()

Everything that precedes the marked text: OPEN, the header digits, HEADER_END.

strip(text)

@spec strip(String.t()) :: String.t()

text without markers. Digit codepoints outside a header (a real ZWJ in an emoji) are kept, like the overlay's stripMarks.