-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move lua files to lua folder. classify pandoc2review.
- Loading branch information
Showing
6 changed files
with
88 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters