raindown 0.21.3 → 0.22.0

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: 714d64b4843d94b4752da53527dcc7c2f3e1fe77ce4aea56aec0ca0b76dfaa6a
4
- data.tar.gz: be27d12a02197bcac1b2ef6f404779de9a47a3d8047787db4291731e4ff3cbc9
3
+ metadata.gz: 96b04a893baf519b6fe2a26bb1d4a27c90a030e7b0be6d754696860495db7e08
4
+ data.tar.gz: 5f43ba40f8569ae40697c3207fec8fc698328d28089502177c55d63471218323
5
5
  SHA512:
6
- metadata.gz: b90a67a177422426703135277ab357e1d332968303ca4adaca91043f99b8ae70f91ab52de03097d1f307ea52519ef687edce28f4b08eafd9d69b0a6caf8b9885
7
- data.tar.gz: 6d1e00f5edcdaabeecc8bb87b2a9854f075649efe4dee83447156eaff48c5c3f4d58ae4ba88a0ab8bfd21f69902b10cc0996f8f5969ae2d3c2276999b1506d99
6
+ metadata.gz: 63b1e3a97e370a10ac1880aa108263b89d862244804c886f0d729c2f5e3dcaf3ae53abfeda7ce81c8fd13212207de6cce89d3f9a7eaf5621fe1deef9462f3e75
7
+ data.tar.gz: 2c8f75f680a003171854195b33d37e82c532858d0f5d82547750a2af24066eadedc445a1ca31a7e3fb22e14d0da56b7d7126758f939abe4ebf4ed4b0167b5a19
data/lib/raindown/code.rb CHANGED
@@ -5,8 +5,9 @@ require_relative 'code_blocks'
5
5
  module Raindown
6
6
  # Finds code in Markdown the way Commonmarker reads it: code spans and fenced, indented or quoted code blocks.
7
7
  module Code
8
- # A code span on one line, like `{x}`, between runs of the same number of backticks.
9
- SPAN = /(?<!`)(`+)(?!`).+?(?<!`)\1(?!`)/n
8
+ # A code span on one line, like `{x}`, between runs of the same number of backticks, from the run it opens with.
9
+ SPAN = /\G(`+)(?!`).+?(?<!`)\1(?!`)/n
10
+ NOT_BACKTICK = /[^`]/n
10
11
 
11
12
  module_function
12
13
 
@@ -47,8 +48,19 @@ module Raindown
47
48
  ranges
48
49
  end
49
50
 
51
+ # The line's spans, each matched from its next run of backticks, which byteindex finds without a regex, so the
52
+ # text between spans is never scanned, and nor is a line without a backtick, as most are. A run that opens no span
53
+ # is passed over whole.
50
54
  def span_ranges(line, start)
51
- line.b.to_enum(:scan, SPAN).map { (start + ::Regexp.last_match.begin(0))...(start + ::Regexp.last_match.end(0)) }
55
+ bytes = line.b
56
+ ranges = []
57
+ from = 0
58
+ while (open = bytes.byteindex('`', from))
59
+ from = SPAN.match(bytes, open)&.end(0)
60
+ ranges << ((start + open)...(start + from)) if from
61
+ from ||= bytes.byteindex(NOT_BACKTICK, open) || break
62
+ end
63
+ ranges
52
64
  end
53
65
 
54
66
  def range(position, line_offsets)
@@ -15,8 +15,10 @@ module Raindown
15
15
 
16
16
  # The block opening at index, closed by a fence of the same character that's at least as long.
17
17
  def at(lines, index)
18
- fence, language = lines[index]&.match(FENCE)&.captures
19
- return unless fence
18
+ # Most lines open no fence, and match? makes no match to find that out.
19
+ return unless lines[index]&.match?(FENCE)
20
+
21
+ fence, language = lines[index].match(FENCE).captures
20
22
 
21
23
  close = (index + 1...lines.length).find { |i| lines[i].match?(CLOSINGS[fence]) }
22
24
  { open: index, close:, language:, body: lines[index + 1...close].join } if close
data/lib/raindown.rb CHANGED
@@ -70,7 +70,8 @@ module Raindown
70
70
  output = Directives.render("#{html.chomp}\n")
71
71
  next output if commonmark
72
72
 
73
- output.gsub(/[\u{E000}\u{E001}]/, CODE_BRACES.invert)
73
+ # With tr, as a regex of the placeholders reads the output a character at a time, taking three times as long.
74
+ output.tr(CODE_BRACES.values.join, CODE_BRACES.keys.join)
74
75
  end
75
76
  end
76
77
  end
@@ -119,8 +120,9 @@ module Raindown
119
120
  preserve_code(doc:)
120
121
 
121
122
  html = highlight_code? ? doc.to_html(options: HTML_OPTIONS) : unhighlighted_html(doc:)
122
- html.gsub('<!-- ANTLERS', '<{').gsub('ANTLERS -->', '}>')
123
- .gsub(/[\u{E000}\u{E001}]/, CODE_BRACE_ENTITIES)
123
+ html = html.gsub('<!-- ANTLERS', '<{').gsub('ANTLERS -->', '}>')
124
+ # Each placeholder's found as text, which is several times faster than a regex of both.
125
+ CODE_BRACE_ENTITIES.reduce(html) { |text, (brace, entity)| text.gsub(brace, entity) }
124
126
  end
125
127
 
126
128
  # Code blocks without highlighting, with a language class for highlighting in the browser.
data/lib/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Raindown
4
- VERSION = '0.21.3'
4
+ VERSION = '0.22.0'
5
5
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: raindown
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.21.3
4
+ version: 0.22.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - maedi
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2026-11-14 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: antlers
@@ -381,14 +381,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
381
381
  requirements:
382
382
  - - ">="
383
383
  - !ruby/object:Gem::Version
384
- version: 3.4.2
384
+ version: 4.0.0
385
385
  required_rubygems_version: !ruby/object:Gem::Requirement
386
386
  requirements:
387
387
  - - ">="
388
388
  - !ruby/object:Gem::Version
389
389
  version: '0'
390
390
  requirements: []
391
- rubygems_version: 3.6.2
391
+ rubygems_version: 4.0.20
392
392
  specification_version: 4
393
393
  summary: Markup your markdown with a template and annotation layer
394
394
  test_files: []