asciidoctor-rouge 0.2.0 → 0.3.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
- SHA1:
3
- metadata.gz: 7baa8b7c49247f40e58fd422dd7fd460a543562b
4
- data.tar.gz: 0b8ad27e185a07a2812fdc072c1c296631672fb7
2
+ SHA256:
3
+ metadata.gz: f17d5f09f366075fcf74b6c8a78c5d63d3ae5a5b75955ef5472b7720a77dcc42
4
+ data.tar.gz: a5c4a90b5cc7d94c1484218bd6d6141a0507e2700f4e9496211f4677bdf37b14
5
5
  SHA512:
6
- metadata.gz: 02566ec5a875e6881edbc2bc6da92cb45c320c40f9414a53d5ba4c76bfafbc23a6ee42c0ed20091598535264a09bd6b157de46dabf788dfb9971783d7c4953be
7
- data.tar.gz: d69c5765a92aaad6b80765070b88370c70b8937bb6551ad13716655bae5968dd83daacd0f280dbcea1e141dee1a2e547ae7627436ce0a867b7690ee3a0eb8003
6
+ metadata.gz: 0bde3c8cf4e5fdeaea5a06d36464b3d64bb372f18cdc93da8539632265022c69a6f44d7e0ef90a3e710ae736299ccce4d669cc715181a68cedb41f4d6f988796
7
+ data.tar.gz: caaae8119525e79da84ec7c072bed0a35bf34196feb95f7efa0b619317d9b6340b9b7d81b1bd264b1e66ad0c0b95df499560e4d394de2c1b94b6084b1d1cd5e8
data/README.adoc CHANGED
@@ -2,7 +2,7 @@
2
2
  :source-language: shell
3
3
  // custom
4
4
  :gem-name: asciidoctor-rouge
5
- :gem-version: 0.2.0
5
+ :gem-version: 0.3.0
6
6
  :gh-name: jirutka/{gem-name}
7
7
  :gh-branch: master
8
8
  :codacy-id: d2ed58f5f3f949a19bab7637fe7d0bdb
@@ -59,6 +59,9 @@ rouge-theme::
59
59
  Look into https://github.com/jneen/rouge/tree/master/lib/rouge/themes[lib/rouge/themes] in the Rouge repository for a list of available themes.
60
60
  Default is `github`.
61
61
 
62
+ rouge-style::
63
+ Alternative name for the `rouge-theme` for compatibility with _asciidoctor-pdf_ (see https://github.com/{gh-name}/issues/3[#3]).
64
+
62
65
 
63
66
  == License
64
67
 
@@ -19,6 +19,7 @@ Gem::Specification.new do |s|
19
19
  s.add_runtime_dependency 'rouge', '~> 2.2'
20
20
 
21
21
  s.add_development_dependency 'corefines', '~> 1.11'
22
+ s.add_development_dependency 'kramdown', '~> 1.16'
22
23
  s.add_development_dependency 'rake', '~> 12.0'
23
24
  s.add_development_dependency 'rspec', '~> 3.6'
24
25
  s.add_development_dependency 'rubocop', '~> 0.49.0'
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
  require 'asciidoctor/extensions'
3
- require 'asciidoctor/rouge/version'
3
+ require 'asciidoctor/rouge/constants'
4
4
  require 'asciidoctor/rouge/docinfo_processor'
5
5
  require 'asciidoctor/rouge/treeprocessor'
6
6
 
@@ -3,7 +3,7 @@ require 'English'
3
3
  require 'asciidoctor'
4
4
  require 'asciidoctor/inline'
5
5
  require 'asciidoctor/substitutors'
6
- require 'asciidoctor/rouge/version'
6
+ require 'asciidoctor/rouge/constants'
7
7
 
8
8
  module Asciidoctor::Rouge
9
9
  # A substitutor for processing callouts inside a source listing block.
@@ -13,18 +13,18 @@ module Asciidoctor::Rouge
13
13
  attr_reader :callouts
14
14
 
15
15
  # @param node [Asciidoctor::AbstractNode]
16
- # @return [CalloutsSubstitutor] a callouts substitutor for the given _node_.
16
+ # @return [CalloutsSubstitutor] a callouts substitutor for the given *node*.
17
17
  def self.create(node)
18
18
  new(node)
19
19
  end
20
20
 
21
- # Extracts and stashes callout markers from the given _text_ for
21
+ # Extracts and stashes callout markers from the given *text* for
22
22
  # reinsertion after processing.
23
23
  #
24
24
  # This should be used prior passing the source to a code highlighter.
25
25
  #
26
26
  # @param text [#each_line] source of the listing block.
27
- # @return [String] a copy of the _text_ with callout marks removed.
27
+ # @return [String] a copy of the *text* with callout marks removed.
28
28
  def extract(text)
29
29
  escape_char = ::Asciidoctor::Substitutors::RS
30
30
  @callouts.clear
@@ -72,7 +72,7 @@ module Asciidoctor::Rouge
72
72
  end
73
73
 
74
74
  # @param number [Integer] callout number.
75
- # @return [String] an HTML markup of a callout marker with the given _number_.
75
+ # @return [String] an HTML markup of a callout marker with the given *number*.
76
76
  def convert_callout(number)
77
77
  ::Asciidoctor::Inline.new(@node, :callout, number, id: next_callout_id).convert
78
78
  end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+ require 'asciidoctor/rouge/version'
3
+
4
+ module Asciidoctor
5
+ module Rouge
6
+ # Name of the default Rouge theme (style) to use when `rouge-theme` attribute
7
+ # is not specified.
8
+ DEFAULT_THEME = 'github'.freeze
9
+ end
10
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
- require 'asciidoctor/rouge/version'
2
+ require 'asciidoctor/rouge/constants'
3
3
  require 'asciidoctor/extensions'
4
4
  require 'rouge'
5
5
 
@@ -13,7 +13,7 @@ module Asciidoctor::Rouge
13
13
  return unless document.attr?('source-highlighter', 'rouge')
14
14
  return unless document.attr('rouge-css', 'class') == 'class'
15
15
 
16
- if (theme = ::Rouge::Theme.find(document.attr('rouge-theme', 'github')))
16
+ if (theme = ::Rouge::Theme.find(document.attr('rouge-theme', DEFAULT_THEME)))
17
17
  css = theme.render(scope: '.highlight')
18
18
  ['<style>', css, '</style>'].join("\n")
19
19
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
- require 'asciidoctor/rouge/version'
2
+ require 'asciidoctor/rouge/constants'
3
3
  require 'rouge'
4
4
 
5
5
  module Asciidoctor::Rouge
@@ -21,18 +21,18 @@ module Asciidoctor::Rouge
21
21
  # wrapper element). Defaults to empty array.
22
22
  #
23
23
  # @param inline_theme [String, Rouge::Theme, Class<Rouge::Theme>, nil]
24
- # the theme to use for inline styles, or +nil+ to not set inline styles
25
- # (i.e. use classes). This is ignored if _inner_ is not +nil+.
24
+ # the theme to use for inline styles, or `nil` to not set inline styles
25
+ # (i.e. use classes). This is ignored if *inner* is not `nil`.
26
26
  #
27
27
  # @param line_class [String, nil] CSS class to set on a line wrapper
28
- # element, or +nil+ to not set a class. Defaults to "line".
28
+ # element, or `nil` to not set a class. Defaults to "line".
29
29
  #
30
- # @param line_id [String, nil] format string specifying +id+ for each line,
31
- # or +nil+ to omit +id+. Defaults to "L%i".
30
+ # @param line_id [String, nil] format string specifying `id` for each line,
31
+ # or `nil` to omit `id`. Defaults to "L%i".
32
32
  #
33
33
  # @param inner [Rouge::Formatter::HTML, #span, nil] the inner HTML
34
- # formatter to delegate formatting of tokens to, or +nil+ to get
35
- # +html+ or +html_inline+ formatter from the +Rouge::Formatter+'s
34
+ # formatter to delegate formatting of tokens to, or `nil` to get
35
+ # `html` or `html_inline` formatter from the `Rouge::Formatter`'s
36
36
  # registry.
37
37
  #
38
38
  def initialize(callout_markers: nil,
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
  require 'asciidoctor/substitutors'
3
- require 'asciidoctor/rouge/version'
3
+ require 'asciidoctor/rouge/constants'
4
4
 
5
5
  module Asciidoctor::Rouge
6
6
  # A substitutor for processing passthroughs inside listing blocks.
@@ -13,7 +13,7 @@ module Asciidoctor::Rouge
13
13
 
14
14
  # @param node [Asciidoctor::AbstractNode]
15
15
  # @return [PassthroughsSubstitutor] a passthroughs substitutor for
16
- # the given _node_.
16
+ # the given *node*.
17
17
  def self.create(node)
18
18
  new(node)
19
19
  end
@@ -22,7 +22,7 @@ module Asciidoctor::Rouge
22
22
  # after processing.
23
23
  #
24
24
  # @param text [String] the source of the node.
25
- # @return [String] a copy of the _text_ with passthrough regions
25
+ # @return [String] a copy of the *text* with passthrough regions
26
26
  # substituted with placeholders.
27
27
  def extract(text)
28
28
  @node.extract_passthroughs(text)
@@ -32,7 +32,7 @@ module Asciidoctor::Rouge
32
32
  # placeholder positions.
33
33
  #
34
34
  # @param text [String] the text into which to restore the passthroughs.
35
- # @return [String] a copy of the _text_ with restored passthroughs.
35
+ # @return [String] a copy of the *text* with restored passthroughs.
36
36
  def restore(text)
37
37
  return text if @node.passthroughs.empty?
38
38
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
- require 'asciidoctor/rouge/version'
2
+ require 'asciidoctor/rouge/constants'
3
3
  require 'asciidoctor/rouge/callouts_substitutor'
4
4
  require 'asciidoctor/rouge/html_formatter'
5
5
  require 'asciidoctor/rouge/passthroughs_substitutor'
@@ -12,11 +12,11 @@ module Asciidoctor::Rouge
12
12
 
13
13
  # @param formatter [Class<Rouge::Formatter>] the Rouge formatter to use for
14
14
  # formatting a token stream from a Rouge lexer. It must respond to method
15
- # +format+ accepting a token stream and (optionally) a hash of options,
16
- # producing +String+. Defaults to {HtmlFormatter}.
15
+ # `format` accepting a token stream and (optionally) a hash of options,
16
+ # producing `String`. Defaults to {HtmlFormatter}.
17
17
  #
18
- # @param formatter_opts [Hash] options to pass to the _formatter_.
19
- # It's used only if _formatter's_ +format+ method has arity > 1.
18
+ # @param formatter_opts [Hash] options to pass to the *formatter*.
19
+ # It's used only if *formatter's* `format` method has arity > 1.
20
20
  # Defaults to empty hash.
21
21
  #
22
22
  # @param callouts_sub [#create] the callouts substitutor class to use for
@@ -45,6 +45,20 @@ module Asciidoctor::Rouge
45
45
  document.find_by(context: :listing, style: 'source') do |block|
46
46
  process_listing(block)
47
47
  end
48
+
49
+ # Table cells may contain listing, but Document#find_by does not search
50
+ # inside table, so we must handle it specially.
51
+ document.find_by(context: :table) do |table|
52
+ table.rows.body.each do |row|
53
+ row.each do |cell|
54
+ if (inner = cell.inner_document)
55
+ inner.find_by(context: :listing, style: 'source') do |block|
56
+ process_listing(block)
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
48
62
  end
49
63
 
50
64
  protected
@@ -77,7 +91,11 @@ module Asciidoctor::Rouge
77
91
  block.set_attr('language', lexer.tag)
78
92
 
79
93
  if document.attr?('rouge-css', 'style')
80
- opts[:inline_theme] = document.attr('rouge-theme', 'github')
94
+ # 'rouge-style' is alternative name for compatibility with
95
+ # asciidoctor-pdf (see #3).
96
+ opts[:inline_theme] = document.attr('rouge-theme') \
97
+ || document.attr('rouge-style') \
98
+ || DEFAULT_THEME
81
99
  end
82
100
 
83
101
  if block.attr?('highlight', nil, false)
@@ -94,7 +112,7 @@ module Asciidoctor::Rouge
94
112
  end
95
113
 
96
114
  # @param language [String]
97
- # @return [Rouge::Lexer] a lexer for the specified _language_.
115
+ # @return [Rouge::Lexer] a lexer for the specified *language*.
98
116
  def find_lexer(language)
99
117
  (::Rouge::Lexer.find(language) || ::Rouge::Lexers::PlainText).new
100
118
  end
@@ -102,8 +120,8 @@ module Asciidoctor::Rouge
102
120
  # @param source [String] the code to highlight.
103
121
  # @param lexer [Rouge::Lexer] the lexer to use.
104
122
  # @param opts [Hash] extra options for the formatter; it will be merged
105
- # with the +formatter_opts+ (see {#initialize}).
106
- # @return [String] a highlighted and formatted _source_.
123
+ # with the `formatter_opts` (see {#initialize}).
124
+ # @return [String] a highlighted and formatted *source*.
107
125
  def highlight(source, lexer, opts = {})
108
126
  tokens = lexer.lex(source)
109
127
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Asciidoctor
4
4
  module Rouge
5
- VERSION = '0.2.0'.freeze
5
+ VERSION = '0.3.0'.freeze
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: asciidoctor-rouge
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.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: 2017-09-21 00:00:00.000000000 Z
11
+ date: 2018-01-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: asciidoctor
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '1.11'
55
+ - !ruby/object:Gem::Dependency
56
+ name: kramdown
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.16'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.16'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: rake
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -134,6 +148,7 @@ files:
134
148
  - lib/asciidoctor-rouge.rb
135
149
  - lib/asciidoctor/rouge.rb
136
150
  - lib/asciidoctor/rouge/callouts_substitutor.rb
151
+ - lib/asciidoctor/rouge/constants.rb
137
152
  - lib/asciidoctor/rouge/docinfo_processor.rb
138
153
  - lib/asciidoctor/rouge/html_formatter.rb
139
154
  - lib/asciidoctor/rouge/passthroughs_substitutor.rb
@@ -159,7 +174,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
159
174
  version: '0'
160
175
  requirements: []
161
176
  rubyforge_project:
162
- rubygems_version: 2.6.13
177
+ rubygems_version: 2.7.4
163
178
  signing_key:
164
179
  specification_version: 4
165
180
  summary: Rouge code highlighter support for Asciidoctor