govuk_markdown 0.1.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.editorconfig +10 -0
- data/.github/workflows/publish_gem.yml +1 -1
- data/CHANGELOG.md +18 -0
- data/Gemfile +0 -3
- data/Gemfile.lock +43 -45
- data/README.md +10 -5
- data/Rakefile +1 -0
- data/example/example.html +4 -0
- data/example/example.md +8 -0
- data/govuk_markdown.gemspec +1 -2
- data/lib/govuk_markdown.rb +2 -2
- data/lib/govuk_markdown/renderer.rb +32 -7
- data/lib/govuk_markdown/version.rb +1 -1
- metadata +6 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 69f3f17dd960d5db6cb264a91912850a9e294f3a75c1c936044a58c6b36b7c04
|
4
|
+
data.tar.gz: 7d30fe596d4262f8f445c845a7985e9fa1d18740494ca12e0d644a17371e28f2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0a2e32563c6b61b9d51b998a9fa57ed6d5ad5318f080efc4bda6ab27534d7a39f86686407989b5542be205f4e9d60bfd7b169cbceec25b0dd25c627ceb5a6a9b
|
7
|
+
data.tar.gz: abd0235bf969a13863c0dc415c1adefd606c70dda8f857ffd1d39c9126ea9d5334498194bebafa6a7b73b9e627f014cc64f31881989baca2bf973793c73f5207
|
data/.editorconfig
ADDED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
## 1.0.0
|
2
|
+
|
3
|
+
* Increase minimum supported Ruby version to >= 2.7.0
|
4
|
+
* Update dependencies
|
5
|
+
* Fix RuboCop violations
|
6
|
+
|
7
|
+
## 0.4.0
|
8
|
+
|
9
|
+
* Ensure all links get the `govuk-link` class, no matter which Markdown link syntax is used (#7)
|
10
|
+
|
11
|
+
## 0.3.0
|
12
|
+
|
13
|
+
* Add support for tables (#3)
|
14
|
+
* Don’t emphasise snake_cased_words (#4)
|
15
|
+
|
16
|
+
## 0.1.0 and 0.2.0
|
17
|
+
|
18
|
+
Initial release of the code, written by @benilovj and @fofr for the [Get help with technology service](https://github.com/DFE-Digital/get-help-with-tech/pull/171).
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,87 +1,85 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
govuk_markdown (
|
4
|
+
govuk_markdown (1.0.0)
|
5
5
|
activesupport
|
6
|
-
bundler
|
7
6
|
redcarpet
|
8
7
|
|
9
8
|
GEM
|
10
9
|
remote: https://rubygems.org/
|
11
10
|
specs:
|
12
|
-
activesupport (6.
|
11
|
+
activesupport (6.1.4)
|
13
12
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
14
|
-
i18n (>=
|
15
|
-
minitest (
|
16
|
-
tzinfo (~>
|
17
|
-
zeitwerk (~> 2.
|
18
|
-
ast (2.4.
|
19
|
-
concurrent-ruby (1.1.
|
13
|
+
i18n (>= 1.6, < 2)
|
14
|
+
minitest (>= 5.1)
|
15
|
+
tzinfo (~> 2.0)
|
16
|
+
zeitwerk (~> 2.3)
|
17
|
+
ast (2.4.2)
|
18
|
+
concurrent-ruby (1.1.9)
|
20
19
|
diff-lcs (1.4.4)
|
21
|
-
i18n (1.8.
|
20
|
+
i18n (1.8.10)
|
22
21
|
concurrent-ruby (~> 1.0)
|
23
|
-
minitest (5.14.
|
24
|
-
parallel (1.
|
25
|
-
parser (
|
22
|
+
minitest (5.14.4)
|
23
|
+
parallel (1.20.1)
|
24
|
+
parser (3.0.2.0)
|
26
25
|
ast (~> 2.4.1)
|
27
26
|
rack (2.2.3)
|
28
27
|
rainbow (3.0.0)
|
29
|
-
rake (
|
30
|
-
redcarpet (3.5.
|
31
|
-
regexp_parser (1.
|
32
|
-
rexml (3.2.
|
28
|
+
rake (13.0.6)
|
29
|
+
redcarpet (3.5.1)
|
30
|
+
regexp_parser (2.1.1)
|
31
|
+
rexml (3.2.5)
|
33
32
|
rspec (3.10.0)
|
34
33
|
rspec-core (~> 3.10.0)
|
35
34
|
rspec-expectations (~> 3.10.0)
|
36
35
|
rspec-mocks (~> 3.10.0)
|
37
|
-
rspec-core (3.10.
|
36
|
+
rspec-core (3.10.1)
|
38
37
|
rspec-support (~> 3.10.0)
|
39
|
-
rspec-expectations (3.10.
|
38
|
+
rspec-expectations (3.10.1)
|
40
39
|
diff-lcs (>= 1.2.0, < 2.0)
|
41
40
|
rspec-support (~> 3.10.0)
|
42
|
-
rspec-mocks (3.10.
|
41
|
+
rspec-mocks (3.10.2)
|
43
42
|
diff-lcs (>= 1.2.0, < 2.0)
|
44
43
|
rspec-support (~> 3.10.0)
|
45
|
-
rspec-support (3.10.
|
46
|
-
rubocop (
|
44
|
+
rspec-support (3.10.2)
|
45
|
+
rubocop (1.15.0)
|
47
46
|
parallel (~> 1.10)
|
48
|
-
parser (>=
|
47
|
+
parser (>= 3.0.0.0)
|
49
48
|
rainbow (>= 2.2.2, < 4.0)
|
50
|
-
regexp_parser (>= 1.
|
49
|
+
regexp_parser (>= 1.8, < 3.0)
|
51
50
|
rexml
|
52
|
-
rubocop-ast (>=
|
51
|
+
rubocop-ast (>= 1.5.0, < 2.0)
|
53
52
|
ruby-progressbar (~> 1.7)
|
54
|
-
unicode-display_width (>= 1.4.0, <
|
55
|
-
rubocop-ast (
|
56
|
-
parser (>=
|
57
|
-
rubocop-govuk (
|
58
|
-
rubocop (
|
59
|
-
rubocop-ast (
|
60
|
-
rubocop-rails (
|
53
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
54
|
+
rubocop-ast (1.6.0)
|
55
|
+
parser (>= 3.0.1.1)
|
56
|
+
rubocop-govuk (4.0.0)
|
57
|
+
rubocop (~> 1.15.0)
|
58
|
+
rubocop-ast (~> 1.6.0)
|
59
|
+
rubocop-rails (~> 2.10.0)
|
61
60
|
rubocop-rake (= 0.5.1)
|
62
|
-
rubocop-rspec (
|
63
|
-
rubocop-rails (2.
|
61
|
+
rubocop-rspec (~> 2.3.0)
|
62
|
+
rubocop-rails (2.10.1)
|
64
63
|
activesupport (>= 4.2.0)
|
65
64
|
rack (>= 1.1)
|
66
|
-
rubocop (>=
|
65
|
+
rubocop (>= 1.7.0, < 2.0)
|
67
66
|
rubocop-rake (0.5.1)
|
68
67
|
rubocop
|
69
|
-
rubocop-rspec (
|
70
|
-
rubocop (
|
71
|
-
|
72
|
-
|
73
|
-
tzinfo (
|
74
|
-
|
75
|
-
unicode-display_width (
|
76
|
-
zeitwerk (2.4.
|
68
|
+
rubocop-rspec (2.3.0)
|
69
|
+
rubocop (~> 1.0)
|
70
|
+
rubocop-ast (>= 1.1.0)
|
71
|
+
ruby-progressbar (1.11.0)
|
72
|
+
tzinfo (2.0.4)
|
73
|
+
concurrent-ruby (~> 1.0)
|
74
|
+
unicode-display_width (2.0.0)
|
75
|
+
zeitwerk (2.4.2)
|
77
76
|
|
78
77
|
PLATFORMS
|
79
78
|
ruby
|
80
79
|
|
81
80
|
DEPENDENCIES
|
82
|
-
bundler
|
83
81
|
govuk_markdown!
|
84
|
-
rake (~>
|
82
|
+
rake (~> 13.0)
|
85
83
|
rspec
|
86
84
|
rubocop-govuk
|
87
85
|
|
data/README.md
CHANGED
@@ -36,13 +36,18 @@ Will output:
|
|
36
36
|
|
37
37
|
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
38
38
|
|
39
|
-
To install this gem onto your local machine, run `bundle exec rake install`.
|
39
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
40
40
|
|
41
|
-
You can regenerate the example HTML file from Markdown using
|
41
|
+
You can regenerate the example HTML file from Markdown using `bundle exec rake generate_example`.
|
42
42
|
|
43
|
-
|
44
|
-
|
45
|
-
|
43
|
+
## Release a new version
|
44
|
+
|
45
|
+
1. Update the version in [lib/govuk_markdown/version.rb](lib/govuk_markdown/version.rb)
|
46
|
+
2. Run `bundle install`
|
47
|
+
3. Update [CHANGELOG.md](CHANGELOG.md)
|
48
|
+
4. Create a pull request
|
49
|
+
|
50
|
+
When changes are merged into the `main` branch, a new version will be released using a GitHub action.
|
46
51
|
|
47
52
|
## Contributing
|
48
53
|
|
data/Rakefile
CHANGED
data/example/example.html
CHANGED
@@ -40,6 +40,10 @@
|
|
40
40
|
<div class="govuk-width-container">
|
41
41
|
<main class="govuk-main-wrapper" id="main-content" role="main">
|
42
42
|
<h1 id="a-h1-title-header" class="govuk-heading-xl">A h1 title header</h1>
|
43
|
+
<h2 id="links" class="govuk-heading-l">Links</h2>
|
44
|
+
<p class="govuk-body-m">This is <a href="https://gov.uk" class="govuk-link">linked text</a>.</p>
|
45
|
+
<p class="govuk-body-m">This is <a href="https://gov.uk" title="The best place to find government services and information" class="govuk-link">linked text with a title</a>.</p>
|
46
|
+
<p class="govuk-body-m">This is a linked URL <a href="https://www.gov.uk/help" class="govuk-link">https://www.gov.uk/help</a> and this is a linked email address <a href="mailto:noreply@gov.uk" class="govuk-link">noreply@gov.uk</a>.</p>
|
43
47
|
<h2 id="lists" class="govuk-heading-l">Lists</h2>
|
44
48
|
<p class="govuk-body-m">This is a list:</p>
|
45
49
|
<ul class="govuk-list govuk-list--bullet">
|
data/example/example.md
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
# A h1 title header
|
2
2
|
|
3
|
+
## Links
|
4
|
+
|
5
|
+
This is [linked text](https://gov.uk).
|
6
|
+
|
7
|
+
This is [linked text with a title](https://gov.uk "The best place to find government services and information").
|
8
|
+
|
9
|
+
This is a linked URL <https://www.gov.uk/help> and this is a linked email address <noreply@gov.uk>.
|
10
|
+
|
3
11
|
## Lists
|
4
12
|
|
5
13
|
This is a list:
|
data/govuk_markdown.gemspec
CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.summary = "Convert Markdown into GOV.UK styled HTML"
|
10
10
|
spec.description = "Convert Markdown into GOV.UK styled HTML"
|
11
11
|
spec.homepage = "https://github.com/DFE-Digital/govuk_markdown"
|
12
|
-
spec.required_ruby_version = Gem::Requirement.new(">= 2.
|
12
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.7.0")
|
13
13
|
|
14
14
|
spec.metadata["homepage_uri"] = spec.homepage
|
15
15
|
spec.metadata["source_code_uri"] = spec.homepage
|
@@ -26,7 +26,6 @@ Gem::Specification.new do |spec|
|
|
26
26
|
|
27
27
|
spec.add_dependency "activesupport"
|
28
28
|
spec.add_dependency "redcarpet"
|
29
|
-
spec.add_dependency "bundler"
|
30
29
|
|
31
30
|
spec.add_development_dependency "rake", "~> 13.0"
|
32
31
|
spec.add_development_dependency "rspec"
|
data/lib/govuk_markdown.rb
CHANGED
@@ -6,7 +6,7 @@ require_relative "./govuk_markdown/renderer"
|
|
6
6
|
|
7
7
|
module GovukMarkdown
|
8
8
|
def self.render(markdown)
|
9
|
-
renderer = GovukMarkdown::Renderer.new(with_toc_data: true)
|
10
|
-
Redcarpet::Markdown.new(renderer).render(markdown).strip
|
9
|
+
renderer = GovukMarkdown::Renderer.new(with_toc_data: true, link_attributes: { class: "govuk-link" })
|
10
|
+
Redcarpet::Markdown.new(renderer, tables: true, no_intra_emphasis: true).render(markdown).strip
|
11
11
|
end
|
12
12
|
end
|
@@ -1,5 +1,34 @@
|
|
1
1
|
module GovukMarkdown
|
2
2
|
class Renderer < ::Redcarpet::Render::HTML
|
3
|
+
def table(header, body)
|
4
|
+
<<~HTML
|
5
|
+
<table class='govuk-table'>
|
6
|
+
<thead class='govuk-table__head'>
|
7
|
+
#{header}
|
8
|
+
</thead>
|
9
|
+
<tbody class='govuk-table__body'>
|
10
|
+
#{body}
|
11
|
+
</tbody>
|
12
|
+
</table>
|
13
|
+
HTML
|
14
|
+
end
|
15
|
+
|
16
|
+
def table_row(content)
|
17
|
+
<<~HTML
|
18
|
+
<tr class='govuk-table__row'>
|
19
|
+
#{content}
|
20
|
+
</tr>
|
21
|
+
HTML
|
22
|
+
end
|
23
|
+
|
24
|
+
def table_cell(content, _alignment)
|
25
|
+
<<~HTML
|
26
|
+
<td class='govuk-table__cell'>
|
27
|
+
#{content}
|
28
|
+
</td>
|
29
|
+
HTML
|
30
|
+
end
|
31
|
+
|
3
32
|
def header(text, header_level)
|
4
33
|
heading_size = case header_level
|
5
34
|
when 1 then "xl"
|
@@ -21,13 +50,14 @@ module GovukMarkdown
|
|
21
50
|
end
|
22
51
|
|
23
52
|
def list(contents, list_type)
|
24
|
-
|
53
|
+
case list_type
|
54
|
+
when :unordered
|
25
55
|
<<~HTML
|
26
56
|
<ul class="govuk-list govuk-list--bullet">
|
27
57
|
#{contents}
|
28
58
|
</ul>
|
29
59
|
HTML
|
30
|
-
|
60
|
+
when :ordered
|
31
61
|
<<~HTML
|
32
62
|
<ol class="govuk-list govuk-list--number">
|
33
63
|
#{contents}
|
@@ -38,11 +68,6 @@ module GovukMarkdown
|
|
38
68
|
end
|
39
69
|
end
|
40
70
|
|
41
|
-
def link(link, title, content)
|
42
|
-
title_attribute = title.present? ? " title=\"#{title}\"" : ""
|
43
|
-
%(<a href="#{link}" class="govuk-link"#{title_attribute}>#{content}</a>)
|
44
|
-
end
|
45
|
-
|
46
71
|
def hrule
|
47
72
|
<<~HTML
|
48
73
|
<hr class="govuk-section-break govuk-section-break--xl govuk-section-break--visible">
|
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:
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tijmen Brommet
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-07-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -38,20 +38,6 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: bundler
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - ">="
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
48
|
-
type: :runtime
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - ">="
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
55
41
|
- !ruby/object:Gem::Dependency
|
56
42
|
name: rake
|
57
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -101,12 +87,14 @@ executables: []
|
|
101
87
|
extensions: []
|
102
88
|
extra_rdoc_files: []
|
103
89
|
files:
|
90
|
+
- ".editorconfig"
|
104
91
|
- ".github/workflows/publish_gem.yml"
|
105
92
|
- ".github/workflows/tests.yml"
|
106
93
|
- ".gitignore"
|
107
94
|
- ".rspec"
|
108
95
|
- ".rubocop.yml"
|
109
96
|
- ".ruby-version"
|
97
|
+
- CHANGELOG.md
|
110
98
|
- Gemfile
|
111
99
|
- Gemfile.lock
|
112
100
|
- README.md
|
@@ -135,14 +123,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
135
123
|
requirements:
|
136
124
|
- - ">="
|
137
125
|
- !ruby/object:Gem::Version
|
138
|
-
version: 2.
|
126
|
+
version: 2.7.0
|
139
127
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
140
128
|
requirements:
|
141
129
|
- - ">="
|
142
130
|
- !ruby/object:Gem::Version
|
143
131
|
version: '0'
|
144
132
|
requirements: []
|
145
|
-
rubygems_version: 3.
|
133
|
+
rubygems_version: 3.2.24
|
146
134
|
signing_key:
|
147
135
|
specification_version: 4
|
148
136
|
summary: Convert Markdown into GOV.UK styled HTML
|