Class: GovukMarkdown::Preprocessor

Inherits:
Object
  • Object
show all
Defined in:
lib/govuk_markdown/preprocessor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(document) ⇒ Preprocessor

Returns a new instance of Preprocessor.



5
6
7
# File 'lib/govuk_markdown/preprocessor.rb', line 5

def initialize(document)
  @output = document
end

Instance Attribute Details

#outputObject (readonly)

Returns the value of attribute output.



3
4
5
# File 'lib/govuk_markdown/preprocessor.rb', line 3

def output
  @output
end

Instance Method Details

#inject_detailsObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/govuk_markdown/preprocessor.rb', line 20

def inject_details
  @output = output.gsub(build_regexp("details")) do
    summary, details = *construct_details_from(Regexp.last_match(1))

    <<~HTML
      <details class="govuk-details" data-module="govuk-details">
        <summary class="govuk-details__summary">
          <span class="govuk-details__summary-text">
          #{summary}
          </span>
        </summary>
        <div class="govuk-details__text">
          #{nested_markdown(details)}
        </div>
      </details>
    HTML
  end
  self
end

#inject_inset_textObject



9
10
11
12
13
14
15
16
17
18
# File 'lib/govuk_markdown/preprocessor.rb', line 9

def inject_inset_text
  @output = output.gsub(build_regexp("inset-text")) do
    <<~HTML
      <div class="govuk-inset-text">
        #{nested_markdown(Regexp.last_match(1))}
      </div>
    HTML
  end
  self
end