govuk_markdown 2.0.3 → 2.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3752fe30f06aa219d8980f67f509d424bf2151237a26a3ead62cca2357fa5b28
4
- data.tar.gz: 60c9c9ae54297729fb5f7392cdfef6e39e8842524b32b08fa81fcc546787dcfa
3
+ metadata.gz: 12e676d3536a62d66092d85e357f8c3e7315c99dfba63908658b7258bc2c2429
4
+ data.tar.gz: 8d687183bc7ea570bebaed9ac81616fa11e1d3f8c5e32ef3b9b6c6cf2cac68c7
5
5
  SHA512:
6
- metadata.gz: 5c598babbcffaf1dd479ccc45f1df91a793af4915f07f17dfbd59b3d7e3716d026cd63dfb84e2a4064915eeae9d152f48e68da0b716e6264f66475f77d93ad7e
7
- data.tar.gz: 8515582240378e430d5c81281aabf84a278fe646df72da79707c636608ead74693193525f0373640f63fb20b583c123d58ae4f7affcb4f8befd1a0e2831d7462
6
+ metadata.gz: 748c789cdaa0f0d14eb7ed72b3f7720c1fe6184898afff0f9a6aa07c636be0c24def03328cfdd174f1ff9cf70aa960bda3b45b9ae640117866e95f2235d02f47
7
+ data.tar.gz: 24ff957175a76b434a18aeac4f221e857ab37e179efc9c6f07635cc959b67ecfa34e3aef16c64202b50d42e7d43da31dc56f9d0d1b5f291d943668a76bb9db90
@@ -0,0 +1,97 @@
1
+ module GovukMarkdown
2
+ # Renderer::Mixin overrides methods in Redcarpet::Render::HTML.
3
+ # See `GovukMarkdown::Renderer` for an example of how to include it.
4
+ module Renderer::Mixin
5
+ def table(header, body)
6
+ <<~HTML
7
+ <table class='govuk-table'>
8
+ <thead class='govuk-table__head'>
9
+ #{header}
10
+ </thead>
11
+ <tbody class='govuk-table__body'>
12
+ #{body}
13
+ </tbody>
14
+ </table>
15
+ HTML
16
+ end
17
+
18
+ def table_row(content)
19
+ <<~HTML
20
+ <tr class='govuk-table__row'>
21
+ #{content}
22
+ </tr>
23
+ HTML
24
+ end
25
+
26
+ def table_cell(content, _alignment, header)
27
+ if header
28
+ <<~HTML
29
+ <th class='govuk-table__header'>
30
+ #{content}
31
+ </th>
32
+ HTML
33
+ else
34
+ <<~HTML
35
+ <td class='govuk-table__cell'>
36
+ #{content}
37
+ </td>
38
+ HTML
39
+ end
40
+ end
41
+
42
+ def header(text, header_level)
43
+ valid_header_sizes = %w[xl l m s].freeze
44
+
45
+ start_size = valid_header_sizes.include?(@headings_start_with) ? @headings_start_with : "xl"
46
+
47
+ start_size_index = valid_header_sizes.find_index(start_size)
48
+
49
+ header_size = valid_header_sizes[start_size_index + header_level - 1] || "s"
50
+
51
+ id_attribute = @options[:with_toc_data] ? " id=\"#{text.parameterize}\"" : ""
52
+ <<~HTML
53
+ <h#{header_level}#{id_attribute} class="govuk-heading-#{header_size}">#{text}</h#{header_level}>
54
+ HTML
55
+ end
56
+
57
+ def paragraph(text)
58
+ <<~HTML
59
+ <p class="govuk-body-m">#{text}</p>
60
+ HTML
61
+ end
62
+
63
+ def list(contents, list_type)
64
+ case list_type
65
+ when :unordered
66
+ <<~HTML
67
+ <ul class="govuk-list govuk-list--bullet">
68
+ #{contents}
69
+ </ul>
70
+ HTML
71
+ when :ordered
72
+ <<~HTML
73
+ <ol class="govuk-list govuk-list--number">
74
+ #{contents}
75
+ </ol>
76
+ HTML
77
+ else
78
+ raise "Unexpected type #{list_type.inspect}"
79
+ end
80
+ end
81
+
82
+ def hrule
83
+ <<~HTML
84
+ <hr class="govuk-section-break govuk-section-break--xl govuk-section-break--visible">
85
+ HTML
86
+ end
87
+
88
+ def preprocess(document)
89
+ Preprocessor
90
+ .new(document)
91
+ .inject_inset_text
92
+ .inject_details
93
+ .strip_front_matter(@strip_front_matter)
94
+ .output
95
+ end
96
+ end
97
+ end
@@ -1,6 +1,9 @@
1
1
  module GovukMarkdown
2
2
  class Renderer < ::Redcarpet::Render::HTML
3
- include Redcarpet::Render::SmartyPants
3
+ autoload :Mixin, "govuk_markdown/renderer/mixin"
4
+
5
+ include ::Redcarpet::Render::SmartyPants
6
+ include Mixin
4
7
 
5
8
  def initialize(govuk_options, options = {})
6
9
  @headings_start_with = govuk_options[:headings_start_with]
@@ -8,97 +11,5 @@ module GovukMarkdown
8
11
 
9
12
  super options
10
13
  end
11
-
12
- def table(header, body)
13
- <<~HTML
14
- <table class='govuk-table'>
15
- <thead class='govuk-table__head'>
16
- #{header}
17
- </thead>
18
- <tbody class='govuk-table__body'>
19
- #{body}
20
- </tbody>
21
- </table>
22
- HTML
23
- end
24
-
25
- def table_row(content)
26
- <<~HTML
27
- <tr class='govuk-table__row'>
28
- #{content}
29
- </tr>
30
- HTML
31
- end
32
-
33
- def table_cell(content, _alignment, header)
34
- if header
35
- <<~HTML
36
- <th class='govuk-table__header'>
37
- #{content}
38
- </th>
39
- HTML
40
- else
41
- <<~HTML
42
- <td class='govuk-table__cell'>
43
- #{content}
44
- </td>
45
- HTML
46
- end
47
- end
48
-
49
- def header(text, header_level)
50
- valid_header_sizes = %w[xl l m s].freeze
51
-
52
- start_size = valid_header_sizes.include?(@headings_start_with) ? @headings_start_with : "xl"
53
-
54
- start_size_index = valid_header_sizes.find_index(start_size)
55
-
56
- header_size = valid_header_sizes[start_size_index + header_level - 1] || "s"
57
-
58
- id_attribute = @options[:with_toc_data] ? " id=\"#{text.parameterize}\"" : ""
59
- <<~HTML
60
- <h#{header_level}#{id_attribute} class="govuk-heading-#{header_size}">#{text}</h#{header_level}>
61
- HTML
62
- end
63
-
64
- def paragraph(text)
65
- <<~HTML
66
- <p class="govuk-body-m">#{text}</p>
67
- HTML
68
- end
69
-
70
- def list(contents, list_type)
71
- case list_type
72
- when :unordered
73
- <<~HTML
74
- <ul class="govuk-list govuk-list--bullet">
75
- #{contents}
76
- </ul>
77
- HTML
78
- when :ordered
79
- <<~HTML
80
- <ol class="govuk-list govuk-list--number">
81
- #{contents}
82
- </ol>
83
- HTML
84
- else
85
- raise "Unexpected type #{list_type.inspect}"
86
- end
87
- end
88
-
89
- def hrule
90
- <<~HTML
91
- <hr class="govuk-section-break govuk-section-break--xl govuk-section-break--visible">
92
- HTML
93
- end
94
-
95
- def preprocess(document)
96
- Preprocessor
97
- .new(document)
98
- .inject_inset_text
99
- .inject_details
100
- .strip_front_matter(@strip_front_matter)
101
- .output
102
- end
103
14
  end
104
15
  end
@@ -1,3 +1,3 @@
1
1
  module GovukMarkdown
2
- VERSION = "2.0.3".freeze
2
+ VERSION = "2.0.4".freeze
3
3
  end
@@ -4,6 +4,7 @@ require "redcarpet"
4
4
  require_relative "./govuk_markdown/version"
5
5
  require_relative "./govuk_markdown/preprocessor"
6
6
  require_relative "./govuk_markdown/renderer"
7
+ require_relative "./govuk_markdown/renderer/mixin"
7
8
 
8
9
  module GovukMarkdown
9
10
  def self.render(markdown, govuk_options = {})
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: govuk_markdown
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.3
4
+ version: 2.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tijmen Brommet
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-04-08 00:00:00.000000000 Z
11
+ date: 2026-03-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -123,6 +123,7 @@ files:
123
123
  - lib/govuk_markdown.rb
124
124
  - lib/govuk_markdown/preprocessor.rb
125
125
  - lib/govuk_markdown/renderer.rb
126
+ - lib/govuk_markdown/renderer/mixin.rb
126
127
  - lib/govuk_markdown/version.rb
127
128
  homepage: https://github.com/DFE-Digital/govuk_markdown
128
129
  licenses: []