asciidoctor-rouge 0.3.2 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8550bd537204c089e6c1a1241cc7dc665713ffb80a112baf376a6897af4dbb98
4
- data.tar.gz: c36d182b935a74840a575e6cd3f5c6586330c966bbf302a030be8d99afc9ab34
3
+ metadata.gz: f2caf58ed658bc1fb15cc640aad7ba7c8c782aea88c475f457f0121219a85fd1
4
+ data.tar.gz: 542083c67d842f909970791f283fe30b7335533d0ed89525d3fab45ae8f8bfa4
5
5
  SHA512:
6
- metadata.gz: 734a92927a6d7520f47d79a528c5e455795fbeee40bd775107beb1b131e24eac36ee17ba2fce82552fd0d84a54bb8656136c2f474f71c9a498e2ab77aaa9ef3e
7
- data.tar.gz: ca991c647f4b5920ddee1e4c4800e34f2540849f293165557dc20b55278e2faf263053021fff4c77f8a51cddbd3b781cee100566c8f7b639e0894f86b4136c9b
6
+ metadata.gz: 84df699e7fde56a7a03770d22fd158fb3f0f06b833a22b8b99ab1cb984e75fb7779caa71240ed06f9371275ab12eaf850808f9579544f59b5e42faaebd68181c
7
+ data.tar.gz: caa3e9ddd3fd96f33b7eb02ad6c325e8f8cc2a18e3086d26c1e92ceacd5c7026b1c3bb7c55e15b223c91d8656372111b1cbaf122110001dde4148d0b3e5fa284
@@ -2,7 +2,7 @@
2
2
  :source-language: shell
3
3
  // custom
4
4
  :gem-name: asciidoctor-rouge
5
- :gem-version: 0.3.2
5
+ :gem-version: 0.4.0
6
6
  :gh-name: jirutka/{gem-name}
7
7
  :gh-branch: master
8
8
  :codacy-id: d2ed58f5f3f949a19bab7637fe7d0bdb
@@ -15,8 +15,8 @@ Gem::Specification.new do |s|
15
15
 
16
16
  s.required_ruby_version = '>= 2.1'
17
17
 
18
- s.add_runtime_dependency 'asciidoctor', '~> 1.5.6'
19
- s.add_runtime_dependency 'rouge', '~> 2.2', '< 4'
18
+ s.add_runtime_dependency 'asciidoctor', '>= 1.5.6', '< 2.1'
19
+ s.add_runtime_dependency 'rouge', '>= 2.2', '< 4'
20
20
 
21
21
  s.add_development_dependency 'corefines', '~> 1.11'
22
22
  s.add_development_dependency 'kramdown', '~> 1.16'
@@ -65,9 +65,11 @@ module Asciidoctor::Rouge
65
65
 
66
66
  @callout_rx = if node.attr? 'line-comment'
67
67
  comment_rx = ::Regexp.escape(node.attr('line-comment'))
68
- /(?:#{comment_rx} )?#{::Asciidoctor::CalloutExtractRxt}/
68
+ # Copied from Asciidoctor::CalloutExtractRxt (0db74cd)
69
+ /(?:#{comment_rx} )?(\\)?<()(\d+|\.)>(?=(?: ?\\?<(?:\d+|\.)>)*$)/
69
70
  else
70
- ::Asciidoctor::CalloutExtractRx
71
+ # Copied from Asciidoctor::CalloutExtractRx (0db74cd)
72
+ %r((?:(?://|#|--|;;) ?)?(\\)?<!?(|--)(\d+|\.)\2>(?=(?: ?\\?<!?\2(?:\d+|\.)\2>)*$))
71
73
  end
72
74
  end
73
75
 
@@ -71,9 +71,6 @@ module Asciidoctor::Rouge
71
71
  subs = block.subs # Array<Symbol>
72
72
  opts = {}
73
73
 
74
- # Don't escape special characters, Rouge will take care of it.
75
- subs.delete(:specialcharacters)
76
-
77
74
  if subs.delete(:macros)
78
75
  passthroughs = @passthroughs_sub.create(block)
79
76
  source = passthroughs.extract(source)
@@ -84,8 +81,13 @@ module Asciidoctor::Rouge
84
81
  source = callouts.extract(source)
85
82
  end
86
83
 
87
- source = block.apply_subs(source, subs)
88
- subs.clear
84
+ # Apply subs before :specialcharacters, keep subs after :specialcharacters.
85
+ # We don't escape special characters, Rouge will take care of it.
86
+ # See https://github.com/asciidoctor/asciidoctor/blob/v1.5.7.1/lib/asciidoctor/substitutors.rb#L1618-L1622
87
+ if (subs_before = subs.slice!(0, subs.index(:specialcharacters) || -1))
88
+ subs.delete(:specialcharacters)
89
+ source = block.apply_subs(source, subs_before)
90
+ end
89
91
 
90
92
  lang = block.attr('language', 'plaintext', false)
91
93
  lexer = find_lexer(lang)
@@ -100,8 +102,7 @@ module Asciidoctor::Rouge
100
102
  end
101
103
 
102
104
  if block.attr?('highlight', nil, false)
103
- highlight = block.attr('highlight', '', false)
104
- opts[:highlighted_lines] = block.resolve_highlight_lines(highlight)
105
+ opts[:highlighted_lines] = resolve_lines_to_highlight(block, source)
105
106
  end
106
107
 
107
108
  opts[:callout_markers] = callouts.method(:convert_line) if callouts
@@ -132,5 +133,20 @@ module Asciidoctor::Rouge
132
133
  @formatter.format(tokens)
133
134
  end
134
135
  end
136
+
137
+ # @param block [Asciidoctor::Block] the listing block.
138
+ # @param source [String] the source of the *block*.
139
+ # @return [Array<Integer>] an array of line numbers to highlight.
140
+ def resolve_lines_to_highlight(block, source)
141
+ highlight = block.attr('highlight', '', false)
142
+
143
+ # Asciidoctor < 1.5.8
144
+ if block.respond_to?(:resolve_highlight_lines)
145
+ block.resolve_highlight_lines(highlight)
146
+ # Asciidoctor >= 1.5.8
147
+ else
148
+ block.resolve_lines_to_highlight(source, highlight)
149
+ end
150
+ end
135
151
  end
136
152
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Asciidoctor
4
4
  module Rouge
5
- VERSION = '0.3.2'.freeze
5
+ VERSION = '0.4.0'.freeze
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,34 +1,40 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: asciidoctor-rouge
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jakub Jirutka
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-09-26 00:00:00.000000000 Z
11
+ date: 2018-11-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: asciidoctor
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: 1.5.6
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '2.1'
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
- - - "~>"
27
+ - - ">="
25
28
  - !ruby/object:Gem::Version
26
29
  version: 1.5.6
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '2.1'
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: rouge
29
35
  requirement: !ruby/object:Gem::Requirement
30
36
  requirements:
31
- - - "~>"
37
+ - - ">="
32
38
  - !ruby/object:Gem::Version
33
39
  version: '2.2'
34
40
  - - "<"
@@ -38,7 +44,7 @@ dependencies:
38
44
  prerelease: false
39
45
  version_requirements: !ruby/object:Gem::Requirement
40
46
  requirements:
41
- - - "~>"
47
+ - - ">="
42
48
  - !ruby/object:Gem::Version
43
49
  version: '2.2'
44
50
  - - "<"
@@ -180,7 +186,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
180
186
  version: '0'
181
187
  requirements: []
182
188
  rubyforge_project:
183
- rubygems_version: 2.7.7
189
+ rubygems_version: 2.7.8
184
190
  signing_key:
185
191
  specification_version: 4
186
192
  summary: Rouge code highlighter support for Asciidoctor