govuk_markdown 0.4.0 → 2.0.0b1

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: 587d477359637429b19f4b8657940ad42c53ef5d1e7566432c89ded9e08edad3
4
- data.tar.gz: c52c08b4ce188235ba63c2445e372320cfdaafcd2c7be44faf052e1fec80a05d
3
+ metadata.gz: cf2eeb05a74d3e6dac921b756a58192707d5c4edbb0d706b8d79dbf735dd3279
4
+ data.tar.gz: 319c0f2a286dd65829c3b08c93f6a6492748445b82c223b60e8120f4285855f7
5
5
  SHA512:
6
- metadata.gz: c1c54cd75ccfab04de4b900c61802a3a36f9b0e525baa36303c5be7f0a859c1cbbf443467a130b5c322f00be3cd511915f03cd07ba272450a5530802d80c2467
7
- data.tar.gz: 1dc06a438f269eabf63de6bb2baa27ff221ffb019c2dcd990e7122dc8b27fbf77202cf80ced11ce2e204aeef5d090e5c742352b54c05b22126b7324404500fe5
6
+ metadata.gz: 4ba28fd33999e3201ce352baabd21c5a9f3f9959133401cacf39902b8c97259e3dd7ff4aac71db4de31154546f06b61599705e74cab88555f9c357d4cf760345
7
+ data.tar.gz: 90e4c6e7edea3656159d6532452d4bef11f292a0a9682a661ffcb0ea4e31d88c62efc87b22db3135b54852c02bdb0aff223ddec8119934a5f346a8278aa9ef63
@@ -1,28 +1,30 @@
1
+ name: Publish gem
1
2
  on:
2
- - push
3
-
3
+ workflow_dispatch:
4
+ inputs:
5
+ tag:
6
+ description: Tag
7
+ required: true
4
8
  jobs:
5
9
  build:
10
+ name: Publish to RubyGems.org
6
11
  runs-on: ubuntu-latest
7
- if: ${{ github.ref == 'refs/heads/main' }}
8
12
  steps:
9
13
  - uses: actions/checkout@v2
10
- - uses: ruby/setup-ruby@v1
11
- - name: Install dependencies
12
- run: gem update --system
14
+ with:
15
+ ref: ${{ github.event.inputs.tag }}
13
16
 
14
- - env:
15
- GEM_HOST_API_KEY: ${{ secrets.RUBYGEMS_API_KEY }}
16
- name: Push a new gem version to Rubygems
17
+ - name: Set up Ruby
18
+ uses: ruby/setup-ruby@v1
19
+ with:
20
+ ruby-version: '2.7.6'
21
+
22
+ - name: Install dependencies
17
23
  run: |
18
- CURRENT_VERSION=$(rake gem_version)
19
- PUBLISHED_GEM_VERSION=$(gem list --exact --remote govuk_markdown)
24
+ gem install bundler
25
+ bundle install --jobs 4 --retry 3
20
26
 
21
- if [ "${PUBLISHED_GEM_VERSION}" != "govuk_markdown (${CURRENT_VERSION})" ]; then
22
- gem build govuk_markdown.gemspec
23
- gem push "govuk_markdown-${CURRENT_VERSION}.gem"
24
- fi
25
- if ! git ls-remote --tags --exit-code origin v${CURRENT_VERSION}; then
26
- git tag v${CURRENT_VERSION}
27
- git push --tags
28
- fi
27
+ - name: Publish gem
28
+ uses: dawidd6/action-publish-gem@v1
29
+ with:
30
+ api_key: ${{ secrets.RUBYGEMS_API_KEY }}
@@ -1,22 +1,26 @@
1
1
  name: Ruby
2
-
3
2
  on:
4
3
  - pull_request
5
-
6
4
  jobs:
7
- test:
8
-
5
+ rspec:
6
+ strategy:
7
+ fail-fast: false
8
+ matrix:
9
+ ruby: ['2.7.6', '3.0.4', '3.1.2']
9
10
  runs-on: ubuntu-latest
10
-
11
11
  steps:
12
12
  - uses: actions/checkout@v2
13
+
13
14
  - name: Set up Ruby
14
15
  uses: ruby/setup-ruby@v1
15
16
  with:
16
- ruby-version: 2.7
17
+ ruby-version: ${{ matrix.ruby }}
18
+
17
19
  - name: Install dependencies
18
20
  run: bundle install --jobs 4 --retry 3
21
+
19
22
  - name: Run linter
20
23
  run: bundle exec rubocop .
24
+
21
25
  - name: Run tests
22
26
  run: bundle exec rake
data/CHANGELOG.md CHANGED
@@ -1,11 +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
+
1
7
  ## 0.4.0
2
8
 
3
- This release ensures all links get the `govuk-link` class, no matter which Markdown link syntax is used (#7).
9
+ * Ensure all links get the `govuk-link` class, no matter which Markdown link syntax is used (#7)
4
10
 
5
11
  ## 0.3.0
6
12
 
7
- This release adds support for tables (#3) and avoids the notorious emphasised `snake_cased_words` issue (#4).
13
+ * Add support for tables (#3)
14
+ * Don’t emphasise snake_cased_words (#4)
8
15
 
9
- ## 0.1.0 & 0.2.0
16
+ ## 0.1.0 and 0.2.0
10
17
 
11
- Initial release of the code, written by @benilovj and @fofr for the [Get help with tech project](https://github.com/DFE-Digital/get-help-with-tech/pull/171).
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.lock CHANGED
@@ -1,84 +1,90 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- govuk_markdown (0.4.0)
4
+ govuk_markdown (2.0.0b1)
5
5
  activesupport
6
6
  redcarpet
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- activesupport (6.0.3.4)
11
+ activesupport (6.1.4)
12
12
  concurrent-ruby (~> 1.0, >= 1.0.2)
13
- i18n (>= 0.7, < 2)
14
- minitest (~> 5.1)
15
- tzinfo (~> 1.1)
16
- zeitwerk (~> 2.2, >= 2.2.2)
17
- ast (2.4.1)
18
- concurrent-ruby (1.1.7)
13
+ i18n (>= 1.6, < 2)
14
+ minitest (>= 5.1)
15
+ tzinfo (~> 2.0)
16
+ zeitwerk (~> 2.3)
17
+ ast (2.4.2)
18
+ coderay (1.1.3)
19
+ concurrent-ruby (1.1.9)
19
20
  diff-lcs (1.4.4)
20
- i18n (1.8.5)
21
+ i18n (1.8.10)
21
22
  concurrent-ruby (~> 1.0)
22
- minitest (5.14.2)
23
- parallel (1.19.2)
24
- parser (2.7.2.0)
23
+ method_source (1.0.0)
24
+ minitest (5.14.4)
25
+ parallel (1.20.1)
26
+ parser (3.0.2.0)
25
27
  ast (~> 2.4.1)
26
- rack (2.2.3)
28
+ pry (0.14.1)
29
+ coderay (~> 1.1)
30
+ method_source (~> 1.0)
31
+ rack (3.0.0)
27
32
  rainbow (3.0.0)
28
- rake (13.0.1)
29
- redcarpet (3.5.0)
30
- regexp_parser (1.8.2)
31
- rexml (3.2.4)
33
+ rake (13.0.6)
34
+ redcarpet (3.5.1)
35
+ regexp_parser (2.1.1)
36
+ rexml (3.2.5)
32
37
  rspec (3.10.0)
33
38
  rspec-core (~> 3.10.0)
34
39
  rspec-expectations (~> 3.10.0)
35
40
  rspec-mocks (~> 3.10.0)
36
- rspec-core (3.10.0)
41
+ rspec-core (3.10.1)
37
42
  rspec-support (~> 3.10.0)
38
- rspec-expectations (3.10.0)
43
+ rspec-expectations (3.10.1)
39
44
  diff-lcs (>= 1.2.0, < 2.0)
40
45
  rspec-support (~> 3.10.0)
41
- rspec-mocks (3.10.0)
46
+ rspec-mocks (3.10.2)
42
47
  diff-lcs (>= 1.2.0, < 2.0)
43
48
  rspec-support (~> 3.10.0)
44
- rspec-support (3.10.0)
45
- rubocop (0.87.1)
49
+ rspec-support (3.10.2)
50
+ rubocop (1.15.0)
46
51
  parallel (~> 1.10)
47
- parser (>= 2.7.1.1)
52
+ parser (>= 3.0.0.0)
48
53
  rainbow (>= 2.2.2, < 4.0)
49
- regexp_parser (>= 1.7)
54
+ regexp_parser (>= 1.8, < 3.0)
50
55
  rexml
51
- rubocop-ast (>= 0.1.0, < 1.0)
56
+ rubocop-ast (>= 1.5.0, < 2.0)
52
57
  ruby-progressbar (~> 1.7)
53
- unicode-display_width (>= 1.4.0, < 2.0)
54
- rubocop-ast (0.8.0)
55
- parser (>= 2.7.1.5)
56
- rubocop-govuk (3.17.2)
57
- rubocop (= 0.87.1)
58
- rubocop-ast (= 0.8.0)
59
- rubocop-rails (= 2.8.1)
58
+ unicode-display_width (>= 1.4.0, < 3.0)
59
+ rubocop-ast (1.6.0)
60
+ parser (>= 3.0.1.1)
61
+ rubocop-govuk (4.0.0)
62
+ rubocop (~> 1.15.0)
63
+ rubocop-ast (~> 1.6.0)
64
+ rubocop-rails (~> 2.10.0)
60
65
  rubocop-rake (= 0.5.1)
61
- rubocop-rspec (= 1.42.0)
62
- rubocop-rails (2.8.1)
66
+ rubocop-rspec (~> 2.3.0)
67
+ rubocop-rails (2.10.1)
63
68
  activesupport (>= 4.2.0)
64
69
  rack (>= 1.1)
65
- rubocop (>= 0.87.0)
70
+ rubocop (>= 1.7.0, < 2.0)
66
71
  rubocop-rake (0.5.1)
67
72
  rubocop
68
- rubocop-rspec (1.42.0)
69
- rubocop (>= 0.87.0)
70
- ruby-progressbar (1.10.1)
71
- thread_safe (0.3.6)
72
- tzinfo (1.2.7)
73
- thread_safe (~> 0.1)
74
- unicode-display_width (1.7.0)
75
- zeitwerk (2.4.0)
73
+ rubocop-rspec (2.3.0)
74
+ rubocop (~> 1.0)
75
+ rubocop-ast (>= 1.1.0)
76
+ ruby-progressbar (1.11.0)
77
+ tzinfo (2.0.4)
78
+ concurrent-ruby (~> 1.0)
79
+ unicode-display_width (2.0.0)
80
+ zeitwerk (2.4.2)
76
81
 
77
82
  PLATFORMS
78
83
  ruby
79
84
 
80
85
  DEPENDENCIES
81
86
  govuk_markdown!
87
+ pry
82
88
  rake (~> 13.0)
83
89
  rspec
84
90
  rubocop-govuk
data/README.md CHANGED
@@ -36,17 +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`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
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:
42
-
43
- ```sh
44
- bundle exec rake generate_example
45
- ```
41
+ You can regenerate the example HTML file from Markdown using `bundle exec rake generate_example`.
46
42
 
47
43
  ## Release a new version
48
44
 
49
- Update the version in [lib/govuk_markdown/version.rb](lib/govuk_markdown/version.rb) and merge to main. This will automatically release a new version using GitHub actions.
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.
50
51
 
51
52
  ## Contributing
52
53
 
@@ -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.3.0")
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
@@ -27,6 +27,7 @@ Gem::Specification.new do |spec|
27
27
  spec.add_dependency "activesupport"
28
28
  spec.add_dependency "redcarpet"
29
29
 
30
+ spec.add_development_dependency "pry"
30
31
  spec.add_development_dependency "rake", "~> 13.0"
31
32
  spec.add_development_dependency "rspec"
32
33
  spec.add_development_dependency "rubocop-govuk"
@@ -0,0 +1,64 @@
1
+ module GovukMarkdown
2
+ class Preprocessor
3
+ attr_reader :output
4
+
5
+ def initialize(document)
6
+ @output = document
7
+ end
8
+
9
+ def inject_inset_text
10
+ output.gsub!(build_regexp("inset-text")) do
11
+ <<~HTML
12
+ <div class="govuk-inset-text">
13
+ #{Regexp.last_match(1)}
14
+ </div>
15
+ HTML
16
+ end
17
+ self
18
+ end
19
+
20
+ def inject_details
21
+ output.gsub!(build_regexp("details")) do
22
+ summary, details = *construct_details_from(Regexp.last_match(1))
23
+
24
+ <<~HTML
25
+ <details class="govuk-details" data-module="govuk-details">
26
+ <summary class="govuk-details__summary">
27
+ <span class="govuk-details__summary-text">
28
+ #{summary}
29
+ </span>
30
+ </summary>
31
+ <div class="govuk-details__text">
32
+ #{details}
33
+ </div>
34
+ </details>
35
+ HTML
36
+ end
37
+ self
38
+ end
39
+
40
+ private
41
+
42
+ def build_regexp(tag_name, pre_tag: "{", post_tag: "}", closing: "/")
43
+ start_tag = pre_tag + tag_name + post_tag
44
+ end_tag = pre_tag + closing + tag_name + post_tag
45
+ pattern = [Regexp.quote(start_tag), "(.*?)", Regexp.quote(end_tag)].join
46
+
47
+ Regexp.compile(pattern, Regexp::EXTENDED | Regexp::MULTILINE)
48
+ end
49
+
50
+ def construct_details_from(match_string, partition_characters: %w[? .])
51
+ summary_text, match, details = match_string.partition(Regexp.union(*partition_characters))
52
+
53
+ summary = [summary_text, format_punctuation(match)].compact.join
54
+
55
+ [summary, details].compact.map(&:strip)
56
+ end
57
+
58
+ def format_punctuation(match)
59
+ return if match.include?(".")
60
+
61
+ match
62
+ end
63
+ end
64
+ end
@@ -1,5 +1,10 @@
1
1
  module GovukMarkdown
2
2
  class Renderer < ::Redcarpet::Render::HTML
3
+ def initialize(govuk_options, options = {})
4
+ @headings_start_with = govuk_options[:headings_start_with]
5
+ super options
6
+ end
7
+
3
8
  def table(header, body)
4
9
  <<~HTML
5
10
  <table class='govuk-table'>
@@ -30,16 +35,17 @@ module GovukMarkdown
30
35
  end
31
36
 
32
37
  def header(text, header_level)
33
- heading_size = case header_level
34
- when 1 then "xl"
35
- when 2 then "l"
36
- when 3 then "m"
37
- else "s" end
38
+ valid_header_sizes = %w[xl l m s].freeze
38
39
 
39
- id_attribute = @options[:with_toc_data] ? " id=\"#{text.parameterize}\"" : ""
40
+ start_size = valid_header_sizes.include?(@headings_start_with) ? @headings_start_with : "xl"
41
+
42
+ start_size_index = valid_header_sizes.find_index(start_size)
40
43
 
44
+ header_size = valid_header_sizes[start_size_index + header_level - 1] || "s"
45
+
46
+ id_attribute = @options[:with_toc_data] ? " id=\"#{text.parameterize}\"" : ""
41
47
  <<~HTML
42
- <h#{header_level}#{id_attribute} class="govuk-heading-#{heading_size}">#{text}</h#{header_level}>
48
+ <h#{header_level}#{id_attribute} class="govuk-heading-#{header_size}">#{text}</h#{header_level}>
43
49
  HTML
44
50
  end
45
51
 
@@ -50,13 +56,14 @@ module GovukMarkdown
50
56
  end
51
57
 
52
58
  def list(contents, list_type)
53
- if list_type == :unordered
59
+ case list_type
60
+ when :unordered
54
61
  <<~HTML
55
62
  <ul class="govuk-list govuk-list--bullet">
56
63
  #{contents}
57
64
  </ul>
58
65
  HTML
59
- elsif list_type == :ordered
66
+ when :ordered
60
67
  <<~HTML
61
68
  <ol class="govuk-list govuk-list--number">
62
69
  #{contents}
@@ -72,5 +79,13 @@ module GovukMarkdown
72
79
  <hr class="govuk-section-break govuk-section-break--xl govuk-section-break--visible">
73
80
  HTML
74
81
  end
82
+
83
+ def preprocess(document)
84
+ Preprocessor
85
+ .new(document)
86
+ .inject_inset_text
87
+ .inject_details
88
+ .output
89
+ end
75
90
  end
76
91
  end
@@ -1,3 +1,3 @@
1
1
  module GovukMarkdown
2
- VERSION = "0.4.0".freeze
2
+ VERSION = "2.0.0b1".freeze
3
3
  end
@@ -2,11 +2,12 @@ require "active_support/all"
2
2
  require "redcarpet"
3
3
 
4
4
  require_relative "./govuk_markdown/version"
5
+ require_relative "./govuk_markdown/preprocessor"
5
6
  require_relative "./govuk_markdown/renderer"
6
7
 
7
8
  module GovukMarkdown
8
- def self.render(markdown)
9
- renderer = GovukMarkdown::Renderer.new(with_toc_data: true, link_attributes: { class: "govuk-link" })
9
+ def self.render(markdown, govuk_options = {})
10
+ renderer = GovukMarkdown::Renderer.new(govuk_options, { with_toc_data: true, link_attributes: { class: "govuk-link" } })
10
11
  Redcarpet::Markdown.new(renderer, tables: true, no_intra_emphasis: true).render(markdown).strip
11
12
  end
12
13
  end
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: 0.4.0
4
+ version: 2.0.0b1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tijmen Brommet
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-11-06 00:00:00.000000000 Z
11
+ date: 2023-02-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: rake
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -107,6 +121,7 @@ files:
107
121
  - example/govuk-frontend-3.9.1.min.css
108
122
  - govuk_markdown.gemspec
109
123
  - lib/govuk_markdown.rb
124
+ - lib/govuk_markdown/preprocessor.rb
110
125
  - lib/govuk_markdown/renderer.rb
111
126
  - lib/govuk_markdown/version.rb
112
127
  homepage: https://github.com/DFE-Digital/govuk_markdown
@@ -123,12 +138,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
123
138
  requirements:
124
139
  - - ">="
125
140
  - !ruby/object:Gem::Version
126
- version: 2.3.0
141
+ version: 2.7.0
127
142
  required_rubygems_version: !ruby/object:Gem::Requirement
128
143
  requirements:
129
- - - ">="
144
+ - - ">"
130
145
  - !ruby/object:Gem::Version
131
- version: '0'
146
+ version: 1.3.1
132
147
  requirements: []
133
148
  rubygems_version: 3.1.4
134
149
  signing_key: