pandoc2review 1.6.0 → 2.0.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: 4cfd0215db986170226f60ea72af5f323ca588196b0622cfaddd14fe16dbbd0e
4
- data.tar.gz: b14fcc9ad8b5146dcbb13fe6e5f3bea7eb66d991596bef2f20fd6c649af4e1b8
3
+ metadata.gz: 5920e240b004f5ddbbdad1773109673183325ea838daf3a96dc140156c1995fa
4
+ data.tar.gz: c13ded6150f3a5f64fec9845cc3195c33b7601dd4326245195e66ff754959866
5
5
  SHA512:
6
- metadata.gz: 1c441ec53f24068da40cbb31c83a0adce2a80c38c6dcb705227d4a147f019be367bd79b7d9afa7482ecd06d976e2503f5f4ca33cda6af85d63a14994875248fa
7
- data.tar.gz: 68f1bfaece899793dc563c423387da38d73574122d90cb98fca45d807f0e35e855eb3d2d67f898965f38f337c6c59dbe219cf37ff41c2f52362e4989dc28e663
6
+ metadata.gz: 40d92ef8d7e3cf1534c579a1bfd783d4971af5ecc570644da20515a0117e1ae2ba1dd46cde9bf07e56adf30a512561fe9b888b47756f68babb3b13ecacc6ba87
7
+ data.tar.gz: 210316797f1fa487b619f42da293cda5a57129a04dacfee1d2b8b0d7695fa6818823f3fa481a1745b834bfaa78609e8cdb0b8129a8758f300b9881954138be14
@@ -0,0 +1,14 @@
1
+ name: Lint
2
+
3
+ on: [push, pull_request]
4
+
5
+ jobs:
6
+ stylua:
7
+ runs-on: ubuntu-latest
8
+ steps:
9
+ - uses: actions/checkout@v3
10
+ - uses: JohnnyMorganz/stylua-action@v3
11
+ with:
12
+ token: ${{ secrets.GITHUB_TOKEN }}
13
+ version: latest
14
+ args: --check .
@@ -21,4 +21,4 @@ jobs:
21
21
  - run: |
22
22
  gem install bundler --no-document
23
23
  bundle install --retry 3
24
- bundle exec ruby test/run_test.rb
24
+ bundle exec rake
data/.rubocop.yml ADDED
@@ -0,0 +1,305 @@
1
+ AllCops:
2
+ Exclude:
3
+ - samples/**/*
4
+ DisplayCopNames: true
5
+ NewCops: enable
6
+ TargetRubyVersion: 2.7
7
+
8
+ require:
9
+ - rubocop-performance
10
+ - rubocop-rake
11
+
12
+ #### Lint
13
+
14
+ Lint/NestedMethodDefinition:
15
+ Exclude:
16
+ - 'test/*'
17
+
18
+ Lint/AssignmentInCondition:
19
+ Enabled: false
20
+
21
+ Lint/ErbNewArguments:
22
+ Enabled: false
23
+
24
+ # make it enable when supporting only Ruby 3.0 and higher.
25
+ Lint/RedundantDirGlobSort:
26
+ Enabled: false
27
+
28
+ #### Performance
29
+
30
+ Performance/DeletePrefix:
31
+ Enabled: false
32
+
33
+ Performance/StringInclude:
34
+ Enabled: false
35
+
36
+ Performance/CollectionLiteralInLoop:
37
+ Enabled: false
38
+
39
+ Performance/MapCompact:
40
+ Enabled: false
41
+
42
+ #### Style
43
+
44
+ Style/AsciiComments:
45
+ Enabled: false
46
+
47
+ # Use alias_method instead of alias.
48
+ Style/Alias:
49
+ EnforcedStyle: prefer_alias_method
50
+ Enabled: true
51
+
52
+ Style/BarePercentLiterals:
53
+ EnforcedStyle: percent_q
54
+ Enabled: true
55
+
56
+ Style/CommentedKeyword:
57
+ Enabled: false
58
+
59
+ Style/DocumentDynamicEvalDefinition:
60
+ Enabled: false
61
+
62
+ Style/Documentation:
63
+ Enabled: false
64
+
65
+ Style/FormatString:
66
+ EnforcedStyle: sprintf
67
+ Enabled: true
68
+
69
+ Style/FormatStringToken:
70
+ Enabled: false
71
+
72
+ Style/GuardClause:
73
+ Enabled: false
74
+
75
+ Style/IfUnlessModifier:
76
+ Enabled: false
77
+
78
+ Style/MutableConstant:
79
+ Enabled: false
80
+
81
+ Style/ZeroLengthPredicate:
82
+ Enabled: false
83
+
84
+ Style/NumericPredicate:
85
+ EnforcedStyle: comparison
86
+ Enabled: true
87
+
88
+ Style/TernaryParentheses:
89
+ Enabled: false
90
+
91
+ Style/FrozenStringLiteralComment:
92
+ EnforcedStyle: never
93
+ Enabled: true
94
+
95
+ Style/SafeNavigation:
96
+ Enabled: false
97
+
98
+ Style/EmptyMethod:
99
+ EnforcedStyle: expanded
100
+ Enabled: true
101
+
102
+ Style/RescueModifier:
103
+ Enabled: false
104
+
105
+ Style/ClassAndModuleChildren:
106
+ EnforcedStyle: nested
107
+ Enabled: true
108
+
109
+ Style/LineEndConcatenation:
110
+ Enabled: false
111
+
112
+ Style/MethodCallWithArgsParentheses:
113
+ AllowedPatterns:
114
+ - 'require'
115
+ - 'include'
116
+ - 'file'
117
+ - 'task'
118
+ - 'desc'
119
+ - 'info'
120
+ - 'gem'
121
+ - 'exit'
122
+ - 'print'
123
+ - 'puts'
124
+ - 'write'
125
+ - 'warn'
126
+ - 'error'
127
+ - 'error!'
128
+ - 'app_error'
129
+ - 'raise'
130
+ - 'yield'
131
+ - 'source'
132
+ - 'assert'
133
+ - 'assert_equal'
134
+ - 'assert_raise'
135
+ - 'assert_raises'
136
+ - 'assert_nothing_raised'
137
+ - 'sh'
138
+ - 'mv'
139
+ - 'rm_rf'
140
+ Enabled: true
141
+
142
+ Style/MixinUsage:
143
+ Enabled: false
144
+
145
+ Style/NumericLiterals:
146
+ MinDigits: 6
147
+
148
+ Style/PercentQLiterals:
149
+ EnforcedStyle: upper_case_q
150
+ Enabled: true
151
+
152
+ Style/PerlBackrefs:
153
+ Enabled: false
154
+
155
+ Style/RaiseArgs:
156
+ EnforcedStyle: exploded
157
+ Enabled: true
158
+
159
+ Style/RedundantBegin:
160
+ Enabled: false
161
+
162
+ Style/RedundantReturn:
163
+ Enabled: false
164
+
165
+ Style/RedundantSelf:
166
+ Enabled: false
167
+
168
+ Style/StderrPuts:
169
+ Enabled: false
170
+
171
+ Style/WordArray:
172
+ MinSize: 10
173
+
174
+ Style/RedundantPercentQ:
175
+ Enabled: false
176
+
177
+ Style/WhileUntilModifier:
178
+ Enabled: false
179
+
180
+ Style/SlicingWithRange:
181
+ Enabled: false
182
+
183
+ Style/AccessorGrouping:
184
+ Enabled: false
185
+
186
+ Style/CaseLikeIf:
187
+ Enabled: false
188
+
189
+ Style/StringConcatenation:
190
+ Enabled: false
191
+
192
+ Style/OptionalBooleanParameter:
193
+ Enabled: false
194
+
195
+ Style/CombinableLoops:
196
+ Enabled: false
197
+
198
+ Style/FetchEnvVar:
199
+ Enabled: false
200
+
201
+ ### Layout
202
+
203
+ Layout/BlockAlignment:
204
+ Enabled: false
205
+
206
+ Layout/ClosingHeredocIndentation:
207
+ Enabled: false
208
+
209
+ Layout/DotPosition:
210
+ EnforcedStyle: trailing
211
+ Enabled: true
212
+
213
+ Layout/HeredocIndentation:
214
+ Enabled: false
215
+
216
+ Layout/SpaceAroundBlockParameters:
217
+ EnforcedStyleInsidePipes: no_space
218
+ Enabled: true
219
+
220
+ Layout/SpaceInsideStringInterpolation:
221
+ EnforcedStyle: no_space
222
+ Enabled: true
223
+
224
+ Layout/TrailingWhitespace:
225
+ Enabled: true
226
+ AllowInHeredoc: true
227
+
228
+ Layout/LineLength:
229
+ Max: 256
230
+ Exclude:
231
+ - "test/**/*"
232
+
233
+ #### Metrics
234
+
235
+ Metrics/BlockNesting:
236
+ Max: 4
237
+
238
+ Metrics/ModuleLength:
239
+ Max: 300
240
+
241
+ Metrics/ParameterLists:
242
+ Max: 8
243
+
244
+ Metrics/PerceivedComplexity:
245
+ Max: 28
246
+
247
+ Metrics/ClassLength:
248
+ Max: 1500
249
+ Exclude:
250
+ - 'test/*.rb'
251
+
252
+ ### should be < 50
253
+ Metrics/MethodLength:
254
+ Max: 100
255
+ Exclude:
256
+ - "bin/review-*"
257
+ - "bin/review2*"
258
+ - "test/**/*"
259
+
260
+ ### should be < 20
261
+ Metrics/CyclomaticComplexity:
262
+ Max: 25
263
+
264
+ ### should be < 60
265
+ Metrics/AbcSize:
266
+ Max: 120
267
+ Exclude:
268
+ - "bin/review-*"
269
+ - "test/**/*"
270
+
271
+ ### shoud be < 25
272
+ Metrics/BlockLength:
273
+ CountComments: false # count full line comments?
274
+ Max: 62
275
+ Exclude:
276
+ - 'Rakefile'
277
+ - '**/*.rake'
278
+ - 'test/**/*.rb'
279
+
280
+ ## Naming
281
+
282
+ Naming/FileName:
283
+ Enabled: false
284
+
285
+ Naming/HeredocDelimiterNaming:
286
+ Enabled: false
287
+
288
+ Naming/MethodParameterName:
289
+ Enabled: false
290
+
291
+ Naming/VariableNumber:
292
+ EnforcedStyle: normalcase
293
+ Enabled: true
294
+ Exclude:
295
+ - test/*
296
+
297
+ #### Security
298
+
299
+ #### Gemspec
300
+
301
+ Gemspec/RequiredRubyVersion:
302
+ Enabled: false
303
+
304
+ Gemspec/DevelopmentDependencies:
305
+ EnforcedStyle: gemspec
data/Gemfile CHANGED
@@ -2,5 +2,3 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in pandoc2review.gemspec
4
4
  gemspec
5
-
6
- gem "rake", "~> 12.0"
data/README.md CHANGED
@@ -57,6 +57,10 @@ GNU General Public License Version 2
57
57
  - [@takahashim](https://github.com/takahashim)
58
58
 
59
59
  ## Changelog
60
+ ### 2.0.0
61
+ - Full refactoring for Pandoc 3 model. Thanks atusy for your hard work!
62
+ - Introduce rubocop and regression tests.
63
+
60
64
  ### 1.6.0
61
65
  - Fix inline raw.
62
66
  - Refactoring.
@@ -123,6 +127,7 @@ pandoc2review ファイル名 > ファイル名.re
123
127
  - `--shiftheading <数>`: 見出しレベルに <数> だけ加えます (pandoc >= 2.8)
124
128
  - `--disable-eaw`: Ruby の EAW ライブラリを使った段落構築を使いません
125
129
  - `--hideraw`: raw 判定されたインライン・ブロックを出力に含めません
130
+ - `--classic-writer`: Pandoc 3 で Pando 2 互換のクラシックカスタム Writer モードを使います
126
131
 
127
132
  ## 仕様など
128
133
  - [pandoc2review における Markdown 形式処理の注意事項](markdown-format.ja.md)
data/Rakefile CHANGED
@@ -1,5 +1,5 @@
1
- require "bundler/gem_tasks"
2
- require "rake/testtask"
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
3
 
4
4
  desc 'Run tests'
5
5
  task :test, :target do |_, argv|
@@ -10,4 +10,14 @@ task :test, :target do |_, argv|
10
10
  end
11
11
  end
12
12
 
13
- task :default => :test
13
+ desc 'Check with rubocop'
14
+ task :rubocop do
15
+ begin
16
+ require 'rubocop/rake_task'
17
+ RuboCop::RakeTask.new
18
+ rescue LoadError
19
+ $stderr.puts 'rubocop not found'
20
+ end
21
+ end
22
+
23
+ task default: %i[rubocop test]
data/exe/pandoc2review CHANGED
@@ -1,6 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
- # -*- coding: utf-8 -*-
3
- # Copyright 2020-2021 Kenshi Muto
2
+ # Copyright 2020-2023 Kenshi Muto
4
3
 
5
4
  require 'pathname'
6
5
  bindir = Pathname.new(__FILE__).realpath.dirname
data/lib/pandoc2review.rb CHANGED
@@ -1,4 +1,3 @@
1
- # -*- coding: utf-8 -*-
2
1
  # Copyright 2020-2023 Kenshi Muto
3
2
  require 'optparse'
4
3
  require 'unicode/eaw'
@@ -7,7 +6,7 @@ require 'open3'
7
6
 
8
7
  class Pandoc2ReVIEW
9
8
  def main
10
- luadir = ((Pathname.new(__FILE__)).realpath.dirname + '../lua').realpath
9
+ luadir = (Pathname.new(__FILE__).realpath.dirname + '../lua').realpath
11
10
  parse_args
12
11
 
13
12
  ARGV.each do |file|
@@ -17,20 +16,24 @@ class Pandoc2ReVIEW
17
16
  end
18
17
  args = ['pandoc', '-t', File.join(luadir, 'review.lua'), '--lua-filter', File.join(luadir, 'filters.lua')]
19
18
 
20
- if file =~ /\.md$/i
19
+ if file.match?(/\.md$/i)
21
20
  args += ['-f', 'markdown-auto_identifiers-smart+east_asian_line_breaks']
22
21
 
23
22
  if @disableeaw
24
- args += ['-M', "softbreak:true"]
23
+ args += ['-M', 'softbreak:true']
25
24
  end
26
25
 
27
26
  if @hideraw
28
- args += ['-M', "hideraw:true"]
27
+ args += ['-M', 'hideraw:true']
29
28
  end
30
29
  end
31
30
 
32
31
  if @stripemptydev
33
- args += ['-M', "stripemptydev:true"]
32
+ args += ['-M', 'stripemptydev:true']
33
+ end
34
+
35
+ if @classicwriter
36
+ args += ['-M', 'classicwriter:true']
34
37
  end
35
38
 
36
39
  if @heading
@@ -41,7 +44,7 @@ class Pandoc2ReVIEW
41
44
 
42
45
  stdout, stderr, status = Open3.capture3(*args)
43
46
  unless status.success?
44
- STDERR.puts stderr
47
+ $stderr.puts stderr
45
48
  exit 1
46
49
  end
47
50
  print modify_result(stdout)
@@ -53,9 +56,10 @@ class Pandoc2ReVIEW
53
56
  @disableeaw = nil
54
57
  @hideraw = nil
55
58
  @stripemptydev = nil
59
+ @classicwriter = nil
56
60
  opts = OptionParser.new
57
61
  opts.banner = 'Usage: pandoc2review [option] file [file ...]'
58
- opts.version = '1.6'
62
+ opts.version = '2.0'
59
63
 
60
64
  opts.on('--help', 'Prints this message and quit.') do
61
65
  puts opts.help
@@ -67,12 +71,15 @@ class Pandoc2ReVIEW
67
71
  opts.on('--disable-eaw', "Disable compositing a paragraph with Ruby's EAW library.") do
68
72
  @disableeaw = true
69
73
  end
70
- opts.on('--hideraw', "Hide raw inline/block with no review format specified.") do
74
+ opts.on('--hideraw', 'Hide raw inline/block with no review format specified.') do
71
75
  @hideraw = true
72
76
  end
73
- opts.on('--strip-emptydev', "Strip <div> without any id or class") do
77
+ opts.on('--strip-emptydev', 'Strip <div> without any id or class') do
74
78
  @stripemptydev = true
75
79
  end
80
+ opts.on('--classic-writer', 'Prefer classic custom writer on Pandoc 3.x to be compatible with Pandoc 2.x') do
81
+ @classicwriter = true
82
+ end
76
83
 
77
84
  begin
78
85
  opts.parse!(ARGV)
data/lua/filters.lua CHANGED
@@ -1,18 +1,14 @@
1
1
  -- Copyright 2020-2023 atusy and Kenshi Muto
2
2
 
3
3
  local function review_inline(x)
4
- return pandoc.RawInline("review", x)
4
+ return pandoc.RawInline("review", x)
5
5
  end
6
6
 
7
- local beginchild = {pandoc.Plain(review_inline("//beginchild"))}
8
- local endchild = {pandoc.Plain(review_inline("//endchild"))}
7
+ local beginchild = { pandoc.Plain(review_inline("//beginchild")) }
8
+ local endchild = { pandoc.Plain(review_inline("//endchild")) }
9
9
 
10
10
  local function markdown(text)
11
- return pandoc.read(
12
- text,
13
- "markdown-auto_identifiers-smart+east_asian_line_breaks",
14
- PANDOC_READER_OPTIONS
15
- ).blocks[1].content
11
+ return pandoc.read(text, "markdown-auto_identifiers-smart+east_asian_line_breaks", PANDOC_READER_OPTIONS).blocks[1].content
16
12
  end
17
13
 
18
14
  local function support_blankline(constructor)
@@ -24,7 +20,7 @@ local function support_blankline(constructor)
24
20
  ]]
25
21
  local construct = constructor or pandoc.Para
26
22
  return function(x)
27
- local blocks = {construct({})}
23
+ local blocks = { construct({}) }
28
24
  local i = 1
29
25
  local n_break = 0
30
26
  local content = blocks[i].content
@@ -40,8 +36,8 @@ local function support_blankline(constructor)
40
36
  n_break = 0
41
37
  elseif n_break > 1 then
42
38
  -- Convert LineBreak's into //blankline commands
43
- table.insert(blocks, pandoc.Div({}, {blankline = n_break - 1}))
44
- table.insert(blocks, construct({elem}))
39
+ table.insert(blocks, pandoc.Div({}, { blankline = n_break - 1 }))
40
+ table.insert(blocks, construct({ elem }))
45
41
  i = i + 2
46
42
  content = blocks[i].content
47
43
  n_break = 0
@@ -68,7 +64,7 @@ local function nestablelist(elem)
68
64
  elseif second.tag then
69
65
  table.insert(block, 2, pandoc.BulletList(beginchild))
70
66
  else
71
- for _,definition in ipairs(second) do
67
+ for _, definition in ipairs(second) do
72
68
  if definition[2] then
73
69
  table.insert(definition, 2, pandoc.BulletList(beginchild))
74
70
  table.insert(definition, pandoc.BulletList(endchild))
@@ -98,7 +94,7 @@ local function support_strong(child)
98
94
  ]]
99
95
  return function(elem)
100
96
  if (#elem.content == 1) and (elem.content[1].tag == child) then
101
- return pandoc.Span(elem.content[1].content, {class = 'strong'})
97
+ return pandoc.Span(elem.content[1].content, { class = "strong" })
102
98
  end
103
99
  end
104
100
  end
@@ -107,23 +103,21 @@ local function caption_div(div)
107
103
  local class = div.classes[1]
108
104
  local caption = div.attributes.caption
109
105
 
110
- if ((#div.content == 1) and
111
- (div.content[1].content) and
112
- (#div.content[1].content == 1) and
113
- (div.content[1].content[1].tag == "Math") and
114
- (div.identifier)) then
106
+ if
107
+ (#div.content == 1)
108
+ and div.content[1].content
109
+ and (#div.content[1].content == 1)
110
+ and (div.content[1].content[1].tag == "Math")
111
+ and div.identifier
112
+ then
115
113
  class = "texequation[" .. div.identifier .. "]"
116
- local math_text = (div.content[1].content[1].text
117
- ):gsub("^\n+", ""):gsub("\n+$", "")
114
+ local math_text = (div.content[1].content[1].text):gsub("^\n+", ""):gsub("\n+$", "")
118
115
 
119
116
  if caption == nil then
120
- return pandoc.RawBlock(
121
- "review",
122
- "//" .. class .. "{\n" .. math_text .. "\n//}"
123
- )
117
+ return pandoc.RawBlock("review", "//" .. class .. "{\n" .. math_text .. "\n//}")
124
118
  end
125
119
 
126
- div.content = {pandoc.RawBlock("review", math_text)}
120
+ div.content = { pandoc.RawBlock("review", math_text) }
127
121
  end
128
122
 
129
123
  if class == nil then
@@ -136,7 +130,7 @@ local function caption_div(div)
136
130
  table.insert(begin.content, review_inline("]{<P2RREMOVEBELOW/>"))
137
131
  table.insert(div.content, 1, begin)
138
132
  table.insert(div.content, pandoc.RawBlock("review", "<P2RREMOVEABOVE/>//}"))
139
- div.classes = {"review-internal"}
133
+ div.classes = { "review-internal" }
140
134
  return div
141
135
  end
142
136
  end
@@ -144,9 +138,7 @@ end
144
138
  local function noindent(para)
145
139
  local first = para.content[1]
146
140
 
147
- if (first and (first.tag == "RawInline") and
148
- (first.format == "tex") and
149
- (first.text:match("^\\noindent%s*"))) then
141
+ if first and (first.tag == "RawInline") and (first.format == "tex") and (first.text:match("^\\noindent%s*")) then
150
142
  para.content[1] = review_inline("//noindent\n")
151
143
  if para.content[2].tag == "SoftBreak" then
152
144
  table.remove(para.content, 2)
@@ -156,44 +148,15 @@ local function noindent(para)
156
148
  return para
157
149
  end
158
150
 
159
- local function figure(fig)
160
- -- Pandoc 3.x adds pandoc.Figure
161
- if #fig.content > 1 or #fig.content[1].content > 1 then
162
- error("NotImplemented")
163
- end
164
-
165
- local base = fig.content[1].content[1]
166
-
167
- local attr = {}
168
- for k, v in pairs(base.attributes) do
169
- attr[k] = v
170
- end
171
- local classes = {}
172
- for _, v in pairs(base.classes) do
173
- table.insert(classes, "." .. v)
174
- end
175
- attr.classes = table.concat(classes, " ")
176
- attr.identifier = base.attr.identifier
177
- attr.is_figure = "true"
178
-
179
- return pandoc.Image(
180
- base.title,
181
- base.src,
182
- pandoc.utils.stringify(fig.caption),
183
- attr
184
- )
185
- end
186
-
187
151
  return {
188
- {Emph = support_strong("Strong")},
189
- {Strong = support_strong("Emph")},
190
- {Plain = support_blankline(pandoc.Plain)},
191
- {Para = support_blankline(pandoc.Para)},
192
- {Para = noindent},
152
+ { Emph = support_strong("Strong") },
153
+ { Strong = support_strong("Emph") },
154
+ { Plain = support_blankline(pandoc.Plain) },
155
+ { Para = support_blankline(pandoc.Para) },
156
+ { Para = noindent },
193
157
  -- blankline must be processed before lists
194
- {BulletList = nestablelist},
195
- {OrderedList = nestablelist},
196
- {DefinitionList = nestablelist},
197
- {Div = caption_div},
198
- {Figure = figure},
158
+ { BulletList = nestablelist },
159
+ { OrderedList = nestablelist },
160
+ { DefinitionList = nestablelist },
161
+ { Div = caption_div },
199
162
  }