ass_parse_text
Tokenize an ASS line into ordered text segments and override tags, mapping plain characters to raw indices. Use raw text or a document line index for inspection.
Instructions
Tokenise an ASS line into its ordered segments and override tags.
Args:
text: a raw ASS Text field (tags included). Use this to inspect a
line that is not (yet) in a document.
index: 0-based line index in doc_id; the line's current Text
field is read from the document.
doc_id: document holding index; the current document when omitted.
Passing both text and index is an error.
Returns a dict with:
source/index/doc_id
which input was used ("text" or "line").
raw, raw_length
the line exactly as stored (raw index space).
plain_text, plain_length, characters
the visible text and, for every visible character, its index in both
spaces: {"plain_index": i, "char": c, "raw_index": r}.
segments
ordered alternating text runs and {...} blocks. A text segment
carries text plus start/end (raw indices) and
plain_start/plain_end. A block segment carries raw
(including braces), inner, block (0-based block number),
is_override (True when it holds at least one \ tag; a block
without tags is an ASS comment block), the same four offset fields
(plain_start == plain_end for blocks) and tags.
tags
the flat list of every tag in line order, each with name (canonical,
lowercase, e.g. kf for \K), argument ("" for
valueless tags), raw (exact source text), paren (whether the
argument was written in parentheses), is_override and block.
Every parsed tag has is_override True because only
backslash-prefixed content is parsed as a tag; see the block-level flag
for comment blocks.
summary
per-line flags: blocks, tags, tag_names (histogram),
tag_groups (histogram by tag family), has_drawing (drawing mode
is still active at the end of the line, i.e. an unmatched \p),
drawing_state, has_karaoke, has_transform, has_clip and
plain_length. Use tag_names["p"]/tag_groups["drawing"] to
detect a drawing that is switched off again by \p0.
Read-only; no snapshot. start/end are raw indices, everything with
plain in its name is a plain (visible character) index.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| text | No | ||
| index | No | ||
| doc_id | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||