From b0d4c92400fe088897b96af33b4e64bb4e2816c7 Mon Sep 17 00:00:00 2001 From: Patrick Cherry Date: Thu, 12 Feb 2026 15:24:46 +0000 Subject: [PATCH 1/8] Upgrade kramdown_rpf ruby version and deps --- .rubocop.yml | 15 +++++-- .tool-versions | 2 +- Gemfile | 8 ++++ kramdown_rpf.gemspec | 14 +++---- lib/kramdown_rpf.rb | 1 - lib/kramdown_rpf/kramdown.rb | 27 +++++++------ lib/kramdown_rpf/rpf.rb | 20 +++++----- lib/kramdown_rpf/version.rb | 4 +- spec/errors_spec.rb | 20 +++++----- spec/i18n_spec.rb | 62 ++++++++++++++++------------- spec/kramdown_rpf_spec.rb | 77 +++++++++++------------------------- 11 files changed, 123 insertions(+), 127 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 148986c..9c761de 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,5 +1,12 @@ -AllCops: - TargetRubyVersion: 2.5 +# RPF Digital Products house styles +inherit_from: + - https://raspberrypifoundation.github.io/digital-engineering/configs/rubocop-base.yml + - https://raspberrypifoundation.github.io/digital-engineering/configs/rubocop-performance.yml + - https://raspberrypifoundation.github.io/digital-engineering/configs/rubocop-rspec.yml + - .rubocop_todo.yml + +# Allow the Exclude arrays to be merged. +inherit_mode: + merge: + - Exclude -Metrics/LineLength: - Max: 120 diff --git a/.tool-versions b/.tool-versions index 9eb38ed..9c68d12 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1 +1 @@ -ruby 2.7.2 +ruby 3.2.7 diff --git a/Gemfile b/Gemfile index adc17f5..fdd3940 100644 --- a/Gemfile +++ b/Gemfile @@ -4,3 +4,11 @@ source 'https://rubygems.org' # Specify your gem's dependencies in kramdown_rpf.gemspec gemspec + +group :development do + gem 'byebug', require: false + gem 'rspec', require: false + gem 'rubocop', require: false + gem 'rubocop-performance', require: false + gem 'rubocop-rspec', require: false +end diff --git a/kramdown_rpf.gemspec b/kramdown_rpf.gemspec index 98ecc8d..2684871 100644 --- a/kramdown_rpf.gemspec +++ b/kramdown_rpf.gemspec @@ -7,7 +7,7 @@ require 'kramdown_rpf/version' Gem::Specification.new do |spec| spec.name = 'kramdown-rpf' spec.version = KramdownRPF::VERSION - spec.authors = ['Raspberry Pi Foundation Web Team'] + spec.authors = ['Raspberry Pi Foundation Digital Products Team'] spec.email = ['web@raspberrypi.org'] spec.summary = "Kramdown extensions for the Raspberry Pi Foundation's resources website." spec.homepage = 'https://projects.raspberrypi.org' @@ -19,7 +19,7 @@ Gem::Specification.new do |spec| spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'" else raise 'RubyGems 2.0 or newer is required to protect against ' \ - 'public gem pushes.' + 'public gem pushes.' end spec.files = `git ls-files -z`.split("\x0").reject do |f| @@ -29,11 +29,9 @@ Gem::Specification.new do |spec| spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } spec.require_paths = ['lib'] - spec.add_dependency 'i18n', '0.8.6' - spec.add_dependency 'kramdown', '~> 1.2', '>= 1.2.0' + spec.add_dependency 'i18n' + spec.add_dependency 'kramdown', '~> 2.5' + spec.add_dependency 'kramdown-parser-gfm' - spec.add_development_dependency 'bundler' - spec.add_development_dependency 'byebug' - spec.add_development_dependency 'rake' - spec.add_development_dependency 'rspec' + spec.metadata['rubygems_mfa_required'] = 'true' end diff --git a/lib/kramdown_rpf.rb b/lib/kramdown_rpf.rb index 731797d..a85e959 100644 --- a/lib/kramdown_rpf.rb +++ b/lib/kramdown_rpf.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true require 'i18n' -require 'kramdown' require_relative 'kramdown_rpf/version' require_relative 'kramdown_rpf/kramdown' diff --git a/lib/kramdown_rpf/kramdown.rb b/lib/kramdown_rpf/kramdown.rb index 1fdb293..ad5d001 100644 --- a/lib/kramdown_rpf/kramdown.rb +++ b/lib/kramdown_rpf/kramdown.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true require 'kramdown' +require 'kramdown/parser/gfm' require_relative 'rpf' module Kramdown @@ -80,7 +81,7 @@ def convert_task(element, _indent) end module RaiseNotImplementedForUndefinedConvertMethods - def method_missing(method_name, *args, &block) + def method_missing(method_name, *args, &) raise NotImplementedError if method_name.to_s.start_with?('convert_') super @@ -116,18 +117,18 @@ class KramdownRPF < ::Kramdown::Parser::GFM task ].freeze - CHALLENGE_PATTERN = %r{^#{OPT_SPACE}---[ \t]*challenge[ \t]*---(.*?)---[ \t]*\/challenge[ \t]*---}m.freeze - CODE_PATTERN = %r{^#{OPT_SPACE}---[ \t]*code[ \t]*---(.*?)---[ \t]*\/code[ \t]*---}m.freeze - COLLAPSE_PATTERN = %r{^#{OPT_SPACE}---[ \t]*collapse[ \t]*---(.*?)---[ \t]*\/collapse[ \t]*---}m.freeze - HINT_PATTERN = %r{^#{OPT_SPACE}---[ \t]*hint[ \t]*---(.*?)---[ \t]*\/hint[ \t]*---}m.freeze - HINTS_PATTERN = %r{^#{OPT_SPACE}---[ \t]*hints[ \t]*---(.*?)---[ \t]*\/hints[ \t]*---}m.freeze - NEW_PAGE_PATTERN = /^#{OPT_SPACE}---[ \t]*new-page[ \t]*---/m.freeze - NO_PRINT_PATTERN = %r{^#{OPT_SPACE}---[ \t]*no-print[ \t]*---(.*?)---[ \t]*\/no-print[ \t]*---}m.freeze - PRINT_ONLY_PATTERN = %r{^#{OPT_SPACE}---[ \t]*print-only[ \t]*---(.*?)---[ \t]*\/print-only[ \t]*---}m.freeze - KNOWLEDGE_QUIZ_QUESTION_PATTERN = %r{^#{OPT_SPACE}---[ \t]*question[ \t]*---(.*?)---[ \t]*\/question[ \t]*---}m.freeze - QUIZ_PATTERN = %r{^#{OPT_SPACE}---[ \t]*quiz[ \t]*---(.*?)---[ \t]*\/quiz[ \t]*---}m.freeze - SAVE_PATTERN = /^#{OPT_SPACE}---[ \t]*save[ \t]*---/m.freeze - TASK_PATTERN = %r{^#{OPT_SPACE}---[ \t]*task[ \t]*---(.*?)---[ \t]*\/task[ \t]*---}m.freeze + CHALLENGE_PATTERN = %r{^#{OPT_SPACE}---[ \t]*challenge[ \t]*---(.*?)---[ \t]*/challenge[ \t]*---}m + CODE_PATTERN = %r{^#{OPT_SPACE}---[ \t]*code[ \t]*---(.*?)---[ \t]*/code[ \t]*---}m + COLLAPSE_PATTERN = %r{^#{OPT_SPACE}---[ \t]*collapse[ \t]*---(.*?)---[ \t]*/collapse[ \t]*---}m + HINT_PATTERN = %r{^#{OPT_SPACE}---[ \t]*hint[ \t]*---(.*?)---[ \t]*/hint[ \t]*---}m + HINTS_PATTERN = %r{^#{OPT_SPACE}---[ \t]*hints[ \t]*---(.*?)---[ \t]*/hints[ \t]*---}m + NEW_PAGE_PATTERN = /^#{OPT_SPACE}---[ \t]*new-page[ \t]*---/m + NO_PRINT_PATTERN = %r{^#{OPT_SPACE}---[ \t]*no-print[ \t]*---(.*?)---[ \t]*/no-print[ \t]*---}m + PRINT_ONLY_PATTERN = %r{^#{OPT_SPACE}---[ \t]*print-only[ \t]*---(.*?)---[ \t]*/print-only[ \t]*---}m + KNOWLEDGE_QUIZ_QUESTION_PATTERN = %r{^#{OPT_SPACE}---[ \t]*question[ \t]*---(.*?)---[ \t]*/question[ \t]*---}m + QUIZ_PATTERN = %r{^#{OPT_SPACE}---[ \t]*quiz[ \t]*---(.*?)---[ \t]*/quiz[ \t]*---}m + SAVE_PATTERN = /^#{OPT_SPACE}---[ \t]*save[ \t]*---/m + TASK_PATTERN = %r{^#{OPT_SPACE}---[ \t]*task[ \t]*---(.*?)---[ \t]*/task[ \t]*---}m def initialize(source, options) super diff --git a/lib/kramdown_rpf/rpf.rb b/lib/kramdown_rpf/rpf.rb index 794eca4..ad0a4a3 100644 --- a/lib/kramdown_rpf/rpf.rb +++ b/lib/kramdown_rpf/rpf.rb @@ -5,13 +5,13 @@ module RPF module Plugin module Kramdown - YAML_FRONT_MATTER_REGEXP = /\n\s*---\s*\n(.*?)---(.*)/m.freeze + YAML_FRONT_MATTER_REGEXP = /\n\s*---\s*\n(.*?)---(.*)/m VALID_CHECK_MARKS = %w[* x].freeze - QUESTION_REGEXP = %r{(.*?)^#{::Kramdown::Parser::Kramdown::OPT_SPACE}---[ \t]*choices[ \t]*---(.*?)---[ \t]*\/choices[ \t]*---}m.freeze - RADIO_REGEXP = /\((?:\s?|(?[#{VALID_CHECK_MARKS.join}]?))\)\s*(?.*)/m.freeze - CHOICE_BLOCK_REGEXP = /^(?=#{::Kramdown::Parser::Kramdown::OPT_SPACE}- \([\s#{VALID_CHECK_MARKS.join}]?\)\s*.*)/m.freeze - CHOICE_FEEDBACK_REGEXP = %r{#{::Kramdown::Parser::Kramdown::OPT_SPACE}---[ \t]*feedback[ \t]*---(.*?)---[ \t]*\/feedback[ \t]*---}m.freeze - SINGLE_FEEDBACK_REGEXP = /\A#{CHOICE_FEEDBACK_REGEXP}/m.freeze + QUESTION_REGEXP = %r{(.*?)^#{::Kramdown::Parser::Kramdown::OPT_SPACE}---[ \t]*choices[ \t]*---(.*?)---[ \t]*/choices[ \t]*---}m + RADIO_REGEXP = /\((?:\s?|(?[#{VALID_CHECK_MARKS.join}]?))\)\s*(?.*)/m + CHOICE_BLOCK_REGEXP = /^(?=#{::Kramdown::Parser::Kramdown::OPT_SPACE}- \([\s#{VALID_CHECK_MARKS.join}]?\)\s*.*)/m + CHOICE_FEEDBACK_REGEXP = %r{#{::Kramdown::Parser::Kramdown::OPT_SPACE}---[ \t]*feedback[ \t]*---(.*?)---[ \t]*/feedback[ \t]*---}m + SINGLE_FEEDBACK_REGEXP = /\A#{CHOICE_FEEDBACK_REGEXP}/m KRAMDOWN_OPTIONS = { input: 'KramdownRPF', @@ -38,11 +38,11 @@ def self.convert_code_to_html(code_block) if filename filename_html = <<~HEREDOC -
+
#{filename}
HEREDOC - .strip + .strip end if line_numbers @@ -54,7 +54,7 @@ def self.convert_code_to_html(code_block) pre_attrs << "data-line-offset=\"#{line_number_start}\"" if line_highlights && line_number_start pre_attrs << "data-line=\"#{line_highlights}\"" if line_highlights - pre_attrs_html = ' ' + pre_attrs.join(' ') if pre_attrs.size.positive? + pre_attrs_html = " #{pre_attrs.join(' ')}" if pre_attrs.size.positive? <<~HEREDOC #{filename_html} @@ -234,7 +234,7 @@ def self.convert_label_to_html(label, index, checked) number = index + 1 <<~HEREDOC
- +
HEREDOC diff --git a/lib/kramdown_rpf/version.rb b/lib/kramdown_rpf/version.rb index 48cdd67..9ce8605 100644 --- a/lib/kramdown_rpf/version.rb +++ b/lib/kramdown_rpf/version.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module KramdownRPF - VERSION = '0.11.8'.freeze + VERSION = '0.11.8' end diff --git a/spec/errors_spec.rb b/spec/errors_spec.rb index 0adcd11..f2378ae 100644 --- a/spec/errors_spec.rb +++ b/spec/errors_spec.rb @@ -3,18 +3,20 @@ require 'spec_helper' RSpec.describe KramdownRPF do - KRAMDOWN_OPTIONS = { - input: 'KramdownRPF', - parse_block_html: true, - syntax_highlighter: nil - }.freeze + let(:kramdown_options) do + { + input: 'KramdownRPF', + parse_block_html: true, + syntax_highlighter: nil + } + end describe 'with incomplete markup' do - it 'should raise an exception' do + it 'raises an exception' do I18n.locale = 'en' test_result = Kramdown::Document.new( File.read('examples/errors/collapse.md'), - KRAMDOWN_OPTIONS + kramdown_options ) expect { test_result.to_html }.to raise_error(Kramdown::ParseError) @@ -22,11 +24,11 @@ end describe 'with valid markup' do - it 'should not raise any errors' do + it 'does not raise any errors' do I18n.locale = 'en' test_result = Kramdown::Document.new( File.read('examples/collapse/collapse.md'), - KRAMDOWN_OPTIONS + kramdown_options ) expect { test_result.to_html }.not_to raise_error diff --git a/spec/i18n_spec.rb b/spec/i18n_spec.rb index c090e45..76ab680 100644 --- a/spec/i18n_spec.rb +++ b/spec/i18n_spec.rb @@ -2,44 +2,52 @@ require 'spec_helper' -RSpec.describe 'i18n' do - KRAMDOWN_OPTIONS = { - input: 'KramdownRPF', - parse_block_html: true, - syntax_highlighter: nil - }.freeze - - LOCALES_DIR = File.join(File.absolute_path('../..', __FILE__), 'locales').freeze - LOCALES_FILES = File.join(LOCALES_DIR, '*.yml').freeze - LOCALES = {}.freeze - - Dir.glob(LOCALES_FILES).each do |file| - file_contents = YAML.load_file(file).first - locale = file_contents[0] - values = file_contents[1]['kramdown_rpf'] +RSpec.describe 'KramdownRPF' do + let(:kramdown_options) do { + } + end + + locales_dir = File.join(File.absolute_path('../..', __FILE__), 'locales').freeze + locales_files = File.join(locales_dir, '*.yml').freeze + shared_examples 'i18n' do |locale, values| context("with #{locale} locale") do - before(:all) do + subject(:test_result) do + Kramdown::Document.new( + File.read(test_name), + input: 'KramdownRPF', + parse_block_html: true, + syntax_highlighter: nil + ).to_html + end + + before do I18n.locale = locale end - it('should convert hint title') do - test_result = Kramdown::Document.new( - File.read('examples/i18n/hints.md'), - KRAMDOWN_OPTIONS - ).to_html + context('with hint title') do + let(:test_name) { 'examples/i18n/hint.md' } + it('converts hint title') do expect(test_result).to(include(values['hint_title'])) end - it('should convert save prompt') do - test_result = Kramdown::Document.new( - File.read('examples/i18n/save.md'), - KRAMDOWN_OPTIONS - ).to_html + context ('with save prompt') do + let(:test_name) { 'examples/i18n/save.md' } - expect(test_result).to(include(values['save'])) + it('converts save prompt') do + expect(test_result).to(include(values['save'])) + end end end end + + + Dir.glob(locales_files).each do |file| + file_contents = YAML.load_file(file).first + locale = file_contents[0] + values = file_contents[1]['kramdown_rpf'] + + it_behaves_like 'i18n', locale, values + end end diff --git a/spec/kramdown_rpf_spec.rb b/spec/kramdown_rpf_spec.rb index 068ae01..cc0635a 100644 --- a/spec/kramdown_rpf_spec.rb +++ b/spec/kramdown_rpf_spec.rb @@ -3,65 +3,36 @@ require 'spec_helper' RSpec.describe KramdownRPF do - KRAMDOWN_OPTIONS = { - input: 'KramdownRPF', - parse_block_html: true, - syntax_highlighter: nil - }.freeze - - CONVERSION_TESTS = %w[ - challenge/challenge - code/code - code/code_default - code/code_with_all_features - code/code_with_angle_brackets - code/code_with_filename - code/code_with_line_numbers - code/code_with_no_line_numbers - code/code_with_line_highlights - collapse/collapse - collapse/collapse_in_challenge - collapse/collapse_music_box - collapse/collapse_with_code - collapse/collapse_with_space - hint/hint - hint/hints - knowledge_quiz/example_question - knowledge_quiz/question_blocks_in_feedback - knowledge_quiz/question_single_feedback - microbit/microbit - new_page/new_page - no_print/no_print - print_only/print_only - quiz/quiz - save/save - scratch/scratch2 - scratch/scratch3 - task/task - task/task_with_hints - task/task_with_ingredient - ].freeze - it 'has a version number' do - expect(KramdownRPF::VERSION).not_to be nil + expect(KramdownRPF::VERSION).not_to be_nil + end + + conversion_tests = Dir.glob('examples/**/*.html').select do |f| + File.exist?(f.sub('.html', '.md')) end - describe 'conversions' do - CONVERSION_TESTS.each do |test_name| - context test_name do - reference_result = File.read "examples/#{test_name}.html" + shared_examples 'a successful conversion' do |test_name| + subject(:test_result) do + Kramdown::Document.new( + File.read(test_name.sub('.html', '.md')), + input: 'KramdownRPF', + parse_block_html: true, + syntax_highlighter: nil + ).to_html.strip + end + + let(:reference_result) { File.read(test_name).strip } - it 'should be correctly converted' do - I18n.locale = 'en' + before { I18n.locale = :en } - test_result = Kramdown::Document.new( - File.read("examples/#{test_name}.md"), - KRAMDOWN_OPTIONS - ).to_html + it 'produces the expected HTML output' do + expect(test_result).to eq(reference_result) + end + end - expect(test_result.strip).to eq(reference_result.strip) - end - end + conversion_tests.each do |test_name| + context "when converting #{test_name.sub('.html', '.md')}" do + it_behaves_like 'a successful conversion', test_name end end end From 14bac8c797a55ca5e47e7ca885caad1ac678c4b6 Mon Sep 17 00:00:00 2001 From: Patrick Cherry Date: Fri, 13 Feb 2026 08:50:11 +0000 Subject: [PATCH 2/8] Fix CI yaml --- .github/workflows/ci.yml | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b11a6e8..d3f6866 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -3,6 +3,7 @@ name: CI on: push: branches: [ main ] + tags: [ 'v*' ] pull_request: branches: [ main ] @@ -70,8 +71,8 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - name: Create GitHub Release - uses: softprops/action-gh-release@v1 - with: - files: pkg/*.gem - generate_release_notes: true + - name: Create GitHub Release + uses: softprops/action-gh-release@v1 + with: + files: pkg/*.gem + generate_release_notes: true From bce74d4798f5b0ccf938fcbb1e6c82145e84cda1 Mon Sep 17 00:00:00 2001 From: Patrick Cherry Date: Fri, 13 Feb 2026 08:51:12 +0000 Subject: [PATCH 3/8] Fix again --- .github/workflows/ci.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d3f6866..f8b37f6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -72,7 +72,7 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Create GitHub Release - uses: softprops/action-gh-release@v1 - with: - files: pkg/*.gem - generate_release_notes: true + uses: softprops/action-gh-release@v1 + with: + files: pkg/*.gem + generate_release_notes: true From 9496ecf3bec4d5452a1b23e00a37d93dcf7ff47a Mon Sep 17 00:00:00 2001 From: Patrick Cherry Date: Fri, 13 Feb 2026 08:52:53 +0000 Subject: [PATCH 4/8] Fix Rubocop some more --- .rubocop.yml | 5 ++++- Gemfile | 2 +- kramdown_rpf.gemspec | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index ded7982..f18058c 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -8,4 +8,7 @@ inherit_from: # Allow the Exclude arrays to be merged. inherit_mode: merge: - - Exclude \ No newline at end of file + - Exclude + +AllCops: + NewCops: enable diff --git a/Gemfile b/Gemfile index 2383b43..0de2cdc 100644 --- a/Gemfile +++ b/Gemfile @@ -10,4 +10,4 @@ group :development do gem 'rubocop', require: false gem 'rubocop-performance', require: false gem 'rubocop-rspec', require: false -end \ No newline at end of file +end diff --git a/kramdown_rpf.gemspec b/kramdown_rpf.gemspec index e490cac..421a18b 100644 --- a/kramdown_rpf.gemspec +++ b/kramdown_rpf.gemspec @@ -33,4 +33,4 @@ Gem::Specification.new do |spec| spec.add_dependency 'i18n' spec.add_dependency 'kramdown', '~> 2.5' spec.add_dependency 'kramdown-parser-gfm' -end \ No newline at end of file +end From 3b46704d7b3a42f5248d691f91b9e1e9a986544a Mon Sep 17 00:00:00 2001 From: Patrick Cherry Date: Fri, 13 Feb 2026 08:54:23 +0000 Subject: [PATCH 5/8] Add rake dev dependency --- Gemfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Gemfile b/Gemfile index 0de2cdc..5417310 100644 --- a/Gemfile +++ b/Gemfile @@ -6,6 +6,7 @@ source 'https://rubygems.org' gemspec group :development do + gem 'rake' gem 'rspec', require: false gem 'rubocop', require: false gem 'rubocop-performance', require: false From 817960548defc73c24db3cb07b64ef251b30a625 Mon Sep 17 00:00:00 2001 From: Patrick Cherry Date: Fri, 13 Feb 2026 09:07:39 +0000 Subject: [PATCH 6/8] Revert tests; add required ruby version --- kramdown_rpf.gemspec | 5 +-- spec/i18n_spec.rb | 62 ++++++++++++++----------------- spec/kramdown_rpf_spec.rb | 77 +++++++++++++++++++++++++++------------ spec/spec_helper.rb | 1 - 4 files changed, 82 insertions(+), 63 deletions(-) diff --git a/kramdown_rpf.gemspec b/kramdown_rpf.gemspec index 421a18b..9acda90 100644 --- a/kramdown_rpf.gemspec +++ b/kramdown_rpf.gemspec @@ -1,8 +1,6 @@ # frozen_string_literal: true -lib = File.expand_path('lib', __dir__) -$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) -require 'kramdown_rpf/version' +require_relative 'lib/kramdown_rpf/version' Gem::Specification.new do |spec| spec.name = 'kramdown-rpf' @@ -12,6 +10,7 @@ Gem::Specification.new do |spec| spec.summary = "Kramdown extensions for the Raspberry Pi Foundation's resources website." spec.homepage = 'https://projects.raspberrypi.org' spec.license = 'MIT' + spec.required_ruby_version = '>= 3.2.0' # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host' # to allow pushing to a single host or delete this section to allow pushing to any host. diff --git a/spec/i18n_spec.rb b/spec/i18n_spec.rb index 76ab680..c090e45 100644 --- a/spec/i18n_spec.rb +++ b/spec/i18n_spec.rb @@ -2,52 +2,44 @@ require 'spec_helper' -RSpec.describe 'KramdownRPF' do - let(:kramdown_options) do { - } - end - - locales_dir = File.join(File.absolute_path('../..', __FILE__), 'locales').freeze - locales_files = File.join(locales_dir, '*.yml').freeze +RSpec.describe 'i18n' do + KRAMDOWN_OPTIONS = { + input: 'KramdownRPF', + parse_block_html: true, + syntax_highlighter: nil + }.freeze + + LOCALES_DIR = File.join(File.absolute_path('../..', __FILE__), 'locales').freeze + LOCALES_FILES = File.join(LOCALES_DIR, '*.yml').freeze + LOCALES = {}.freeze + + Dir.glob(LOCALES_FILES).each do |file| + file_contents = YAML.load_file(file).first + locale = file_contents[0] + values = file_contents[1]['kramdown_rpf'] - shared_examples 'i18n' do |locale, values| context("with #{locale} locale") do - subject(:test_result) do - Kramdown::Document.new( - File.read(test_name), - input: 'KramdownRPF', - parse_block_html: true, - syntax_highlighter: nil - ).to_html - end - - before do + before(:all) do I18n.locale = locale end - context('with hint title') do - let(:test_name) { 'examples/i18n/hint.md' } + it('should convert hint title') do + test_result = Kramdown::Document.new( + File.read('examples/i18n/hints.md'), + KRAMDOWN_OPTIONS + ).to_html - it('converts hint title') do expect(test_result).to(include(values['hint_title'])) end - context ('with save prompt') do - let(:test_name) { 'examples/i18n/save.md' } + it('should convert save prompt') do + test_result = Kramdown::Document.new( + File.read('examples/i18n/save.md'), + KRAMDOWN_OPTIONS + ).to_html - it('converts save prompt') do - expect(test_result).to(include(values['save'])) - end + expect(test_result).to(include(values['save'])) end end end - - - Dir.glob(locales_files).each do |file| - file_contents = YAML.load_file(file).first - locale = file_contents[0] - values = file_contents[1]['kramdown_rpf'] - - it_behaves_like 'i18n', locale, values - end end diff --git a/spec/kramdown_rpf_spec.rb b/spec/kramdown_rpf_spec.rb index cc0635a..068ae01 100644 --- a/spec/kramdown_rpf_spec.rb +++ b/spec/kramdown_rpf_spec.rb @@ -3,36 +3,65 @@ require 'spec_helper' RSpec.describe KramdownRPF do - it 'has a version number' do - expect(KramdownRPF::VERSION).not_to be_nil - end + KRAMDOWN_OPTIONS = { + input: 'KramdownRPF', + parse_block_html: true, + syntax_highlighter: nil + }.freeze - conversion_tests = Dir.glob('examples/**/*.html').select do |f| - File.exist?(f.sub('.html', '.md')) - end + CONVERSION_TESTS = %w[ + challenge/challenge + code/code + code/code_default + code/code_with_all_features + code/code_with_angle_brackets + code/code_with_filename + code/code_with_line_numbers + code/code_with_no_line_numbers + code/code_with_line_highlights + collapse/collapse + collapse/collapse_in_challenge + collapse/collapse_music_box + collapse/collapse_with_code + collapse/collapse_with_space + hint/hint + hint/hints + knowledge_quiz/example_question + knowledge_quiz/question_blocks_in_feedback + knowledge_quiz/question_single_feedback + microbit/microbit + new_page/new_page + no_print/no_print + print_only/print_only + quiz/quiz + save/save + scratch/scratch2 + scratch/scratch3 + task/task + task/task_with_hints + task/task_with_ingredient + ].freeze - shared_examples 'a successful conversion' do |test_name| - subject(:test_result) do - Kramdown::Document.new( - File.read(test_name.sub('.html', '.md')), - input: 'KramdownRPF', - parse_block_html: true, - syntax_highlighter: nil - ).to_html.strip - end + it 'has a version number' do + expect(KramdownRPF::VERSION).not_to be nil + end - let(:reference_result) { File.read(test_name).strip } + describe 'conversions' do + CONVERSION_TESTS.each do |test_name| + context test_name do + reference_result = File.read "examples/#{test_name}.html" - before { I18n.locale = :en } + it 'should be correctly converted' do + I18n.locale = 'en' - it 'produces the expected HTML output' do - expect(test_result).to eq(reference_result) - end - end + test_result = Kramdown::Document.new( + File.read("examples/#{test_name}.md"), + KRAMDOWN_OPTIONS + ).to_html - conversion_tests.each do |test_name| - context "when converting #{test_name.sub('.html', '.md')}" do - it_behaves_like 'a successful conversion', test_name + expect(test_result.strip).to eq(reference_result.strip) + end + end end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 62a1b2f..6efd082 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -2,7 +2,6 @@ require 'bundler/setup' require 'kramdown_rpf' -require 'byebug' RSpec.configure do |config| # Enable flags like --only-failures and --next-failure From d049c933e9a7190c1f0d8c4f13ada80930fe7bdd Mon Sep 17 00:00:00 2001 From: Patrick Cherry Date: Fri, 13 Feb 2026 09:13:54 +0000 Subject: [PATCH 7/8] Rubocop fixes --- .rubocop_todo.yml | 57 ++++++++++++--------------------------- spec/errors_spec.rb | 4 +-- spec/i18n_spec.rb | 29 ++++++++++---------- spec/kramdown_rpf_spec.rb | 30 ++++++++++----------- 4 files changed, 48 insertions(+), 72 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 90db122..1cfc462 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,53 +1,21 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2026-02-12 17:07:44 UTC using RuboCop version 1.84.2. +# on 2026-02-13 09:13:39 UTC using RuboCop version 1.84.2. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# Offense count: 4 -# Configuration parameters: EnforcedStyle, AllowedGems. -# SupportedStyles: Gemfile, gems.rb, gemspec -Gemspec/DevelopmentDependencies: - Exclude: - - 'kramdown_rpf.gemspec' - -# Offense count: 1 -Gemspec/RequiredRubyVersion: - Exclude: - - 'kramdown_rpf.gemspec' - -# Offense count: 7 -# Configuration parameters: AllowedMethods. -# AllowedMethods: enums -Lint/ConstantDefinitionInBlock: - Exclude: - - 'spec/errors_spec.rb' - - 'spec/i18n_spec.rb' - - 'spec/kramdown_rpf_spec.rb' - # Offense count: 3 # Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes. Metrics/AbcSize: Max: 33 -# Offense count: 2 -# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns. -# AllowedMethods: refine -Metrics/BlockLength: - Max: 55 - # Offense count: 1 # Configuration parameters: AllowedMethods, AllowedPatterns. Metrics/CyclomaticComplexity: Max: 13 -# Offense count: 8 -# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns. -Metrics/MethodLength: - Max: 29 - # Offense count: 1 # Configuration parameters: CountComments, CountAsOne. Metrics/ModuleLength: @@ -58,14 +26,23 @@ Metrics/ModuleLength: Metrics/PerceivedComplexity: Max: 14 -# Offense count: 6 -# Configuration parameters: AllowedConstants. -Style/Documentation: +# Offense count: 1 +# Configuration parameters: IgnoredMetadata. +RSpec/DescribeClass: + Exclude: + - 'spec/i18n_spec.rb' + +# Offense count: 2 +RSpec/LeakyLocalVariable: Exclude: - - 'spec/**/*' - - 'test/**/*' - - 'lib/kramdown_rpf/kramdown.rb' - - 'lib/kramdown_rpf/rpf.rb' + - 'spec/i18n_spec.rb' + +# Offense count: 1 +# Configuration parameters: CustomTransform, IgnoreMethods, IgnoreMetadata, InflectorPath, EnforcedInflector. +# SupportedInflectors: default, active_support +RSpec/SpecFilePathFormat: + Exclude: + - 'spec/errors_spec.rb' # Offense count: 2 # This cop supports safe autocorrection (--autocorrect). diff --git a/spec/errors_spec.rb b/spec/errors_spec.rb index f2378ae..449e295 100644 --- a/spec/errors_spec.rb +++ b/spec/errors_spec.rb @@ -11,9 +11,10 @@ } end + before { I18n.locale = 'en' } + describe 'with incomplete markup' do it 'raises an exception' do - I18n.locale = 'en' test_result = Kramdown::Document.new( File.read('examples/errors/collapse.md'), kramdown_options @@ -25,7 +26,6 @@ describe 'with valid markup' do it 'does not raise any errors' do - I18n.locale = 'en' test_result = Kramdown::Document.new( File.read('examples/collapse/collapse.md'), kramdown_options diff --git a/spec/i18n_spec.rb b/spec/i18n_spec.rb index c090e45..7de937a 100644 --- a/spec/i18n_spec.rb +++ b/spec/i18n_spec.rb @@ -3,39 +3,40 @@ require 'spec_helper' RSpec.describe 'i18n' do - KRAMDOWN_OPTIONS = { - input: 'KramdownRPF', - parse_block_html: true, - syntax_highlighter: nil - }.freeze + let(:kramdown_options) do + { + input: 'KramdownRPF', + parse_block_html: true, + syntax_highlighter: nil + } + end - LOCALES_DIR = File.join(File.absolute_path('../..', __FILE__), 'locales').freeze - LOCALES_FILES = File.join(LOCALES_DIR, '*.yml').freeze - LOCALES = {}.freeze + locales_dir = File.join(File.absolute_path('../..', __FILE__), 'locales').freeze + locales_files = File.join(locales_dir, '*.yml').freeze - Dir.glob(LOCALES_FILES).each do |file| + Dir.glob(locales_files).each do |file| file_contents = YAML.load_file(file).first locale = file_contents[0] values = file_contents[1]['kramdown_rpf'] context("with #{locale} locale") do - before(:all) do + before do I18n.locale = locale end - it('should convert hint title') do + it('converts hint title') do test_result = Kramdown::Document.new( File.read('examples/i18n/hints.md'), - KRAMDOWN_OPTIONS + kramdown_options ).to_html expect(test_result).to(include(values['hint_title'])) end - it('should convert save prompt') do + it('converts save prompt') do test_result = Kramdown::Document.new( File.read('examples/i18n/save.md'), - KRAMDOWN_OPTIONS + kramdown_options ).to_html expect(test_result).to(include(values['save'])) diff --git a/spec/kramdown_rpf_spec.rb b/spec/kramdown_rpf_spec.rb index 068ae01..97e5e24 100644 --- a/spec/kramdown_rpf_spec.rb +++ b/spec/kramdown_rpf_spec.rb @@ -3,13 +3,7 @@ require 'spec_helper' RSpec.describe KramdownRPF do - KRAMDOWN_OPTIONS = { - input: 'KramdownRPF', - parse_block_html: true, - syntax_highlighter: nil - }.freeze - - CONVERSION_TESTS = %w[ + conversion_tests = %w[ challenge/challenge code/code code/code_default @@ -43,22 +37,26 @@ ].freeze it 'has a version number' do - expect(KramdownRPF::VERSION).not_to be nil + expect(KramdownRPF::VERSION).not_to be_nil end describe 'conversions' do - CONVERSION_TESTS.each do |test_name| + conversion_tests.each do |test_name| context test_name do - reference_result = File.read "examples/#{test_name}.html" - - it 'should be correctly converted' do - I18n.locale = 'en' - - test_result = Kramdown::Document.new( + subject(:test_result) do + Kramdown::Document.new( File.read("examples/#{test_name}.md"), - KRAMDOWN_OPTIONS + input: 'KramdownRPF', + parse_block_html: true, + syntax_highlighter: nil ).to_html + end + + let(:reference_result) { File.read "examples/#{test_name}.html" } + + before { I18n.locale = 'en' } + it 'is correctly converted' do expect(test_result.strip).to eq(reference_result.strip) end end From bf1a82c6924b9e7615534352e713b4aec41a55fa Mon Sep 17 00:00:00 2001 From: Patrick Cherry Date: Fri, 13 Feb 2026 09:18:30 +0000 Subject: [PATCH 8/8] Add more stuff to gitignore --- .gitignore | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.gitignore b/.gitignore index 120858d..6cb429a 100644 --- a/.gitignore +++ b/.gitignore @@ -7,9 +7,13 @@ /pkg/ /spec/reports/ /tmp/ +/vendor/ .vscode/ # rspec failure tracking .rspec_status +# Ignore downloaded style files +.rubocop-http* + .byebug_history