Skip to content

Commit

Permalink
move lua files to lua folder. classify pandoc2review.
Browse files Browse the repository at this point in the history
  • Loading branch information
kmuto committed Jan 4, 2021
1 parent 074dde9 commit bcf5b10
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 79 deletions.
11 changes: 9 additions & 2 deletions exe/pandoc2review
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
# Copyright 2020 Kenshi Muto
# Copyright 2020-2021 Kenshi Muto

require 'pathname'
bindir = Pathname.new(__FILE__).realpath.dirname
$LOAD_PATH.unshift((bindir + '../lib').realpath)

require 'pandoc2review'
main

p2r = Pandoc2ReVIEW.new
p2r.main
145 changes: 73 additions & 72 deletions lib/pandoc2review.rb
Original file line number Diff line number Diff line change
@@ -1,98 +1,99 @@
# -*- coding: utf-8 -*-
# Copyright 2020 Kenshi Muto
# Copyright 2020-2021 Kenshi Muto
require 'optparse'
require 'unicode/eaw'
require 'pathname'
require 'open3'

def main
luadir = Pathname.new(__FILE__).realpath.dirname
class Pandoc2ReVIEW
def main
luadir = ((Pathname.new(__FILE__)).realpath.dirname + '../lua').realpath
parse_args

parse_args
ARGV.each do |file|
unless File.exist?(file)
puts "#{file} not exist. skip."
next
end
args = ['pandoc', '-t', File.join(luadir, 'review.lua'), '--lua-filter', File.join(luadir, 'filters.lua')]

ARGV.each do |file|
unless File.exist?(file)
puts "#{file} not exist. skip."
next
end
args = ['pandoc', '-t', File.join(luadir, 'review.lua'), '--lua-filter', File.join(luadir, 'filters.lua')]
if file =~ /\.md$/i
args += ['-f', 'markdown-auto_identifiers-smart+east_asian_line_breaks']

if file =~ /\.md$/i
args += ['-f', 'markdown-auto_identifiers-smart+east_asian_line_breaks']
if @disableeaw
args += ['-M', "softbreak:true"]
end

if @disableeaw
args += ['-M', "softbreak:true"]
if @hideraw
args += ['-M', "hideraw:true"]
end
end

if @hideraw
args += ['-M', "hideraw:true"]
if @heading
args += ["--shift-heading-level-by=#{@heading}"]
end
end

if @heading
args += ["--shift-heading-level-by=#{@heading}"]
end

args.push(file)
args.push(file)

stdout, stderr, status = Open3.capture3(*args)
unless status.success?
STDERR.puts stderr
exit 1
stdout, stderr, status = Open3.capture3(*args)
unless status.success?
STDERR.puts stderr
exit 1
end
print modify_result(stdout)
end
print modify_result(stdout)
end
end

def parse_args
@heading = nil
@disableeaw = nil
@hideraw = nil
opts = OptionParser.new
opts.banner = 'Usage: pandoc2review [option] file [file ...]'
opts.version = '1.0'

opts.on('--help', 'Prints this message and quit.') do
puts opts.help
exit 0
end
opts.on('--shiftheading num', 'Add <num> to heading level.') do |v|
@heading = v
end
opts.on('--disable-eaw', "Disable compositing a paragraph with Ruby's EAW library.") do
@disableeaw = true
end
opts.on('--hideraw', "Hide raw inline/block with no review format specified.") do
@hideraw = true
end
def parse_args
@heading = nil
@disableeaw = nil
@hideraw = nil
opts = OptionParser.new
opts.banner = 'Usage: pandoc2review [option] file [file ...]'
opts.version = '1.2'

opts.on('--help', 'Prints this message and quit.') do
puts opts.help
exit 0
end
opts.on('--shiftheading num', 'Add <num> to heading level.') do |v|
@heading = v
end
opts.on('--disable-eaw', "Disable compositing a paragraph with Ruby's EAW library.") do
@disableeaw = true
end
opts.on('--hideraw', "Hide raw inline/block with no review format specified.") do
@hideraw = true
end

opts.parse!(ARGV)
if ARGV.size != 1
puts opts.help
exit 0
opts.parse!(ARGV)
if ARGV.size != 1
puts opts.help
exit 0
end
end
end

def modify_result(s)
s.gsub('<P2RBR/>') do
tail = $`[-1]
head = $'[0]
return '' if tail.nil? || head.nil?
def modify_result(s)
s.gsub('<P2RBR/>') do
tail = $`[-1]
head = $'[0]
return '' if tail.nil? || head.nil?

space = ' '
if %i[F W H].include?(Unicode::Eaw.property(tail)) &&
%i[F W H].include?(Unicode::Eaw.property(head)) &&
tail !~ /\p{Hangul}/ && head !~ /\p{Hangul}/
space = ''
end

space = ' '
if %i[F W H].include?(Unicode::Eaw.property(tail)) &&
%i[F W H].include?(Unicode::Eaw.property(head)) &&
tail !~ /\p{Hangul}/ && head !~ /\p{Hangul}/
space = ''
end
if (%i[F W H].include?(Unicode::Eaw.property(tail)) &&
tail !~ /\p{Hangul}/) ||
(%i[F W H].include?(Unicode::Eaw.property(head)) &&
head !~ /\p{Hangul}/)
space = ''
end

if (%i[F W H].include?(Unicode::Eaw.property(tail)) &&
tail !~ /\p{Hangul}/) ||
(%i[F W H].include?(Unicode::Eaw.property(head)) &&
head !~ /\p{Hangul}/)
space = ''
space
end

space
end
end
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions pandoc2review.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Gem::Specification.new do |spec|
# spec.version = Pandoc2review::VERSION
spec.version = "1.1.0"
spec.authors = ["kmuto"]
spec.email = ["kmuto@debian.org"]
spec.email = ["kmuto@kmuto.jp"]

spec.summary = %q{Re:VIEW Filter/Writer for Pandoc.}
spec.description = %q{Re:VIEW Filter/Writer for Pandoc.}
Expand All @@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
end
spec.bindir = "exe"
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]
spec.require_paths = ["lib", "lua"]

spec.add_dependency('unicode-eaw')
spec.add_development_dependency('simplecov')
Expand Down
7 changes: 4 additions & 3 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@
require 'open3'

def pandoc(src, opts: nil, err: nil)
args = 'pandoc -t lib/review.lua --lua-filter=lib/filters.lua -f markdown-auto_identifiers-smart+east_asian_line_breaks'
args = 'pandoc -t lua/review.lua --lua-filter=lua/filters.lua -f markdown-auto_identifiers-smart+east_asian_line_breaks'
p2r = Pandoc2ReVIEW.new
if opts
args += ' ' + opts
end
if err
stdout, stderr, status = Open3.capture3(args, stdin_data: src)
return modify_result(stdout), stderr
[p2r.modify_result(stdout), stderr]
else
stdout, status = Open3.capture2(args, stdin_data: src)
modify_result(stdout)
p2r.modify_result(stdout)
end
end

0 comments on commit bcf5b10

Please sign in to comment.