Class: Glossarist::Validators::NoRawHtml
- Inherits:
-
Object
- Object
- Glossarist::Validators::NoRawHtml
- Defined in:
- lib/glossarist/validators/no_raw_html.rb
Overview
Flags raw HTML in concept text that should be expressed as typed mention syntax instead. Raw HTML bypasses the renderer, is brittle, has no accessibility contract, and can embed deployment-specific URLs.
Suggested replacements:
<a href="URL">label</a> → {{link:URL, label}}
<a href="URL">URL</a> → {{link:URL}}
<img src="SRC"> → {{image:SRC}}
<img src="SRC" alt="ALT">→ {{image:SRC, ALT}}
<iframe src="URL"> → {{link:URL}}
Usage:
issues = Glossarist::Validators::NoRawHtml.call(concept_text)
issues.each { |i| warn i[:message] }
Constant Summary collapse
- LINK_PATTERN =
Patterns are intentionally conservative — only tags that have a direct typed-mention replacement. Other HTML tags (, , , etc.) are left to the renderer's HTML sanitiser.
/<a\s+href="([^"]+)"[^>]*>([^<]*)<\/a>/i.freeze
- IMAGE_PATTERN =
/<img\s+src="([^"]+)"(?:\s+alt="([^"]*)")?[^>]*>/i.freeze
- IFRAME_PATTERN =
/<iframe\s+src="([^"]+)"[^>]*>/i.freeze
Class Method Summary collapse
-
.call(text) ⇒ Array<Hash>
Issues with severity, match, suggestion, message.
Class Method Details
.call(text) ⇒ Array<Hash>
Returns issues with severity, match, suggestion, message.
32 33 34 35 36 37 38 39 40 |
# File 'lib/glossarist/validators/no_raw_html.rb', line 32 def call(text) return [] unless text.is_a?(String) [].tap do |issues| scan_links(text, issues) scan_images(text, issues) scan_iframes(text, issues) end end |