Module: Glossarist::MentionParser
- Defined in:
- lib/glossarist/mention_parser.rb
Overview
Parsed mention result — a plain Hash with symbol keys. Built by Glossarist.parse_mention. The shape per kind is documented on MentionKinds constants above.
Examples:
Glossarist.parse_mention("{{link:https://example.com, click here}}")
# => { kind: "link-ref", uri: "https://example.com", label: "click here" }
Glossarist.parse_mention("{{image:diagram.png, The diagram}}")
# => { kind: "image-ref", src: "diagram.png", alt: "The diagram" }
Glossarist.parse_mention("{{bib:ref_1, ISO 704}}")
# => { kind: "bib-ref", id: "ref_1", label: "ISO 704" }
Class Method Summary collapse
-
.parse_content(content) ⇒ Object
Parse the inside of a {...} mention (without the braces).
-
.parse_mention(text) ⇒ Object
Parse a single {...} mention into a canonical Hash.
Class Method Details
.parse_content(content) ⇒ Object
Parse the inside of a {...} mention (without the braces).
83 84 85 86 87 88 89 |
# File 'lib/glossarist/mention_parser.rb', line 83 def parse_content(content) content = content.to_s.strip return nil if content.empty? identifier, label = split_identifier_and_label(content) dispatch_by_identifier(identifier, label) end |
.parse_mention(text) ⇒ Object
Parse a single {...} mention into a canonical Hash.
Returns nil if the input is not a valid mention string. Raises ArgumentError if the mention is malformed (e.g., unknown kind prefix).
72 73 74 75 76 77 78 79 80 |
# File 'lib/glossarist/mention_parser.rb', line 72 def parse_mention(text) return nil unless text.is_a?(String) match = text.match(/\A\s*\{\{([^}]+)\}\}\s*\z/) return nil unless match content = match[1].strip parse_content(content) end |