diff options
| author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-11-07 03:07:49 +0000 |
|---|---|---|
| committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-11-07 03:07:49 +0000 |
| commit | a31408ba64f61275813cc3ffd5aa9bc9ce9f3319 (patch) | |
| tree | 711e3c6f7ea239e0aedc28a815d7067280399314 /scripts | |
| parent | 175f124d93ba52aeb850b5c032930168612d1e71 (diff) | |
| download | gitlab-ce-a31408ba64f61275813cc3ffd5aa9bc9ce9f3319.tar.gz | |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'scripts')
| -rw-r--r-- | scripts/lib/glfm/constants.rb | 4 | ||||
| -rw-r--r-- | scripts/lib/glfm/parse_examples.rb | 10 | ||||
| -rw-r--r-- | scripts/lib/glfm/update_specification.rb | 14 |
3 files changed, 22 insertions, 6 deletions
diff --git a/scripts/lib/glfm/constants.rb b/scripts/lib/glfm/constants.rb index c4feef8464e..c432e5495dd 100644 --- a/scripts/lib/glfm/constants.rb +++ b/scripts/lib/glfm/constants.rb @@ -42,6 +42,10 @@ module Glfm version: alpha ... MARKDOWN + EXAMPLE_BACKTICKS_LENGTH = 32 + EXAMPLE_BACKTICKS_STRING = '`' * EXAMPLE_BACKTICKS_LENGTH + EXAMPLE_BEGIN_STRING = "#{EXAMPLE_BACKTICKS_STRING} example" + EXAMPLE_END_STRING = EXAMPLE_BACKTICKS_STRING INTRODUCTION_HEADER_LINE_TEXT = '# Introduction' BEGIN_TESTS_COMMENT_LINE_TEXT = '<!-- BEGIN TESTS -->' END_TESTS_COMMENT_LINE_TEXT = '<!-- END TESTS -->' diff --git a/scripts/lib/glfm/parse_examples.rb b/scripts/lib/glfm/parse_examples.rb index a15a6ecc47b..aedca274889 100644 --- a/scripts/lib/glfm/parse_examples.rb +++ b/scripts/lib/glfm/parse_examples.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true +require_relative 'constants' + # This module contains a Ruby port of Python logic from the `get_tests` method of the # `spec_test.py` script (see copy of original code in a comment at the bottom of this file): # https://github.com/github/cmark-gfm/blob/5dfedc7/test/spec_tests.py#L82 @@ -20,11 +22,11 @@ # in `scripts/lib/glfm/update_example_snapshots.rb` module Glfm module ParseExamples + include Constants + REGULAR_TEXT = 0 MARKDOWN_EXAMPLE = 1 HTML_OUTPUT = 2 - EXAMPLE_BACKTICKS_LENGTH = 32 - EXAMPLE_BACKTICKS_STRING = '`' * EXAMPLE_BACKTICKS_LENGTH # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/AbcSize def parse_examples(spec_txt_lines) @@ -47,11 +49,11 @@ module Glfm spec_txt_lines.each do |line| line_number += 1 stripped_line = line.strip - if stripped_line.start_with?("#{EXAMPLE_BACKTICKS_STRING} example") + if stripped_line.start_with?(EXAMPLE_BEGIN_STRING) # If beginning line of an example block... state = MARKDOWN_EXAMPLE extensions = stripped_line[(EXAMPLE_BACKTICKS_LENGTH + " example".length)..].split - elsif stripped_line == EXAMPLE_BACKTICKS_STRING + elsif stripped_line == EXAMPLE_END_STRING # Else if end line of an example block... state = REGULAR_TEXT example_number += 1 diff --git a/scripts/lib/glfm/update_specification.rb b/scripts/lib/glfm/update_specification.rb index 521c0919f64..b87005bdb90 100644 --- a/scripts/lib/glfm/update_specification.rb +++ b/scripts/lib/glfm/update_specification.rb @@ -171,12 +171,15 @@ module Glfm def generate_spec_html_files(spec_txt_string, snapshot_spec_md_string) output("Generating spec.html and snapshot_spec.html from spec.txt and snapshot_spec.md markdown...") + spec_txt_string_split_examples = split_examples_into_html_and_md(spec_txt_string) + snapshot_spec_md_string_split_examples = split_examples_into_html_and_md(snapshot_spec_md_string) + input_markdown_yml_string = <<~MARKDOWN --- spec_txt: | - #{spec_txt_string.gsub(/^/, ' ')} + #{spec_txt_string_split_examples.gsub(/^/, ' ')} snapshot_spec_md: | - #{snapshot_spec_md_string.gsub(/^/, ' ')} + #{snapshot_spec_md_string_split_examples.gsub(/^/, ' ')} MARKDOWN # NOTE: We must copy the input YAML file used by the `render_static_html.rb` @@ -209,6 +212,13 @@ module Glfm [rendered_html_hash.fetch(:spec_txt), rendered_html_hash.fetch(:snapshot_spec_md)] end + def split_examples_into_html_and_md(spec_md_string) + spec_md_string.gsub( + /(^#{EXAMPLE_BEGIN_STRING}.*?$(?:.|\n)*?)^\.$(\n(?:.|\n)*?^#{EXAMPLE_END_STRING}$)/mo, + "\\1#{EXAMPLE_BACKTICKS_STRING}\n\n#{EXAMPLE_BACKTICKS_STRING}\\2" + ) + end + def write_spec_html(spec_html_string) output("Writing #{GLFM_SPEC_TXT_PATH}...") FileUtils.mkdir_p(Pathname.new(GLFM_SPEC_HTML_PATH).dirname) |
