Class: Glossarist::Validators::NoRawHtml

Inherits:
Object
  • Object
show all
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

/<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

Class Method Details

.call(text) ⇒ Array<Hash>

Returns issues with severity, match, suggestion, message.

Parameters:

  • text (String)

    the concept text to check

Returns:

  • (Array<Hash>)

    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