module

Hwaro::Content::Processors::MarkdownAttributes

Constants

CLASS_ATTR_RE = /(?<![\w-])class\s*=\s*"([^"]*)"/i
ID_ATTR_RE = /(?<![\w-])id\s*=\s*"[^"]*"/i

(?&lt;![\w-]) guards keep data-id=/data-class= from counting as the element's own id/class.

ID_PRESENT_RE = /(?<![\w-])id\s*=/i
TOKEN_RE = /\G\s*(?:(\#[A-Za-z][\w:-]*)|(\.[A-Za-z_][\w-]*)|([A-Za-z_][\w-]*)=("([^"{}]*)"|[^\s"'`=<>{}]+))/

One token: #id, .class, or key=value/key=&quot;quoted value&quot;. \G anchors each successive match at the end of the previous one (via the pos argument to match), so a run of intervening whitespace is consumed but any OTHER leftover text — a token that matches none of the three forms — breaks the chain and shows up as residue, which invalidates the whole block.

Capture groups: 1 = #id token (with #), 2 = .class token (with .), 3 = kv key, 4 = kv value (quotes included if quoted), 5 = kv value's inner text when quoted (nil when bare).

Instance methods

apply_to_img(img_open : String, parsed : Parsed) : String

Merges parsed into an &lt;img ... tag's opening portion (up to, but NOT including, its /&gt;/&gt; closer — the caller re-appends the original closer so self-closing style is preserved untouched).

Source
apply_to_tag_attrs(existing_attrs : String, parsed : Parsed) : String

Merges id (replace-or-append) and classes (merge-into-existing-or-add) into an existing heading tag's attribute string (e.g. class=&quot;foo&quot;, or &quot;&quot; when the tag had no attributes), matching postprocess_heading_ids's formatting byte-for-byte for the id case.

Source
decode(payload : String) : String | Nil

Inverse of encode. nil on any malformed (odd-length / non-hex) payload — never raises.

Source
encode(block_inner : String) : String

Hex-encodes block_inner (the RAW, still-unparsed {...} contents) so it can ride through Markd's render inside an HTML comment without needing its own comment-safe escaping — hex is immune to --&gt;/&lt;/&amp; entirely.

Source
parse(block_inner : String) : Parsed | Nil

Parses the inside of a {...} block (braces already stripped). Returns nil when the block is empty, contains a token matching none of the three forms, or has unconsumed non-whitespace residue between/after valid tokens.

Source

Nested types