qwik2md 1.0.2 → 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
  SHA1:
3
- metadata.gz: 7cb7c43164290355d2e67e91922d0d712ce1b3c1
4
- data.tar.gz: ff38f0a168a6926ca0291a024dfb6597846d19c2
3
+ metadata.gz: f8187e0a84c36ecefdbca49118a54f1fcc2cf82e
4
+ data.tar.gz: a1bc7326eccd49a5b15ee1e74536f9e6a9a81a96
5
5
  SHA512:
6
- metadata.gz: 224639a3f997e4c66f41fef3571fc7cd2125cf54717c1666b53c138d3d40e5a5547d3cbdf3d351643289f8d6143d13ce12c849b5b437218b968a2f3bb1dcd412
7
- data.tar.gz: abd6d006ab76558908ab9f8cb8789734dba501c11b218b94cfb9d1f37944d171011dae0d186fa4a8c4edafab04c353ab7a85befceea1c9b2693e0ac391a55d62
6
+ metadata.gz: 6df6a5b1399fd05759dcee826befe749d0af54dbe05042305aa9bc69dcc96332918d2de638cd629391da4840bd6e6b71a9700a242c5fc9246b3a21f95dc3ab8c
7
+ data.tar.gz: 7d53f7418c4f10f0c2964a2fcb9a2b942699b998e9ecd5ca1f9cff8850b381ab45d5476a7d80bfafb016aeed98740806fad328a93437b66e757e3f18cd53a63c
data/exe/qwik2md CHANGED
@@ -9,9 +9,17 @@ end
9
9
 
10
10
  require "qwik2md"
11
11
  require "optparse"
12
+ require "pathname"
12
13
 
14
+ options = {}
13
15
  OptionParser.new {|opts|
14
16
  opts.banner = "Usage: qwik2md [options] <file>"
17
+
18
+ opts.on("-bBASE", "--base=BASE", "Base path for files (ex. `-b path/to/base` will convert `{{file(a.jpg)}}` to `path/to/base.files/a.jpg`)") do |b|
19
+ options[:base] = b
20
+ end
15
21
  }.parse!
16
22
 
17
- puts Qwik2md.convert(ARGF.read)
23
+ file = Pathname.new(ARGV[0])
24
+ base = options.fetch(:base, file.dirname.join(file.basename('.*')))
25
+ puts Qwik2md.convert(ARGF.read, base: base)
@@ -1,3 +1,3 @@
1
1
  module Qwik2md
2
- VERSION = "1.0.2"
2
+ VERSION = "2.0.0"
3
3
  end
data/lib/qwik2md.rb CHANGED
@@ -1,9 +1,9 @@
1
1
  require "qwik2md/version"
2
+
2
3
  require "qwik/parser-emode"
3
4
  require "qwik/tokenizer"
4
5
  require "qwik/parser"
5
6
  require 'qwik/wabisabi-format-xml'
6
- require 'reverse_markdown'
7
7
  require 'qwik/action'
8
8
  require 'qwik/loadlib'
9
9
  require 'qwik/config'
@@ -15,12 +15,16 @@ require 'qwik/test-module-path'
15
15
  require 'webrick'
16
16
  require 'logger'
17
17
 
18
+ require 'reverse_markdown'
19
+ require 'charlock_holmes'
20
+
18
21
  Qwik::LoadLibrary.load_libs_here('qwik/act-*')
19
22
 
20
23
  module Qwik2md
21
24
  class Action
22
- def initialize(dir)
25
+ def initialize(dir, base)
23
26
  @dir = dir
27
+ @base = base
24
28
  end
25
29
 
26
30
  def resolve_all_plugin(tree)
@@ -58,7 +62,9 @@ module Qwik2md
58
62
  end
59
63
 
60
64
  def req
61
- @req ||= Qwik::Request.new(config)
65
+ @req ||= Qwik::Request.new(config).tap do |req|
66
+ req.base = @base
67
+ end
62
68
  end
63
69
 
64
70
  def res
@@ -95,14 +101,16 @@ module Qwik2md
95
101
  end
96
102
 
97
103
  class << self
98
- def convert(qwik_str)
99
- Converter.new(qwik_str).convert
104
+ def convert(qwik_str, base:)
105
+ Converter.new(qwik_str, base: base).convert
100
106
  end
101
107
  end
102
108
 
103
109
  class Converter
104
- def initialize(qwik_str)
105
- @qwik_str = qwik_str
110
+ def initialize(qwik_str, base:)
111
+ detection = CharlockHolmes::EncodingDetector.detect(qwik_str)
112
+ @qwik_str = CharlockHolmes::Converter.convert(qwik_str, detection[:encoding], 'UTF-8')
113
+ @base = base
106
114
  end
107
115
 
108
116
  def convert
@@ -123,7 +131,7 @@ module Qwik2md
123
131
 
124
132
  tokens = Qwik::TextTokenizer.tokenize(str)
125
133
  tree = Qwik::TextParser.make_tree(tokens)
126
- action = Action.new(dir)
134
+ action = Action.new(dir, @base)
127
135
  tree = action.resolve_all_plugin(tree)
128
136
  tree.format_xml
129
137
  end
data/qwik2md.gemspec CHANGED
@@ -22,6 +22,7 @@ Gem::Specification.new do |spec|
22
22
  spec.add_dependency "algorithm-diff", "~> 0.1"
23
23
  spec.add_dependency "iconv", "~> 1.0"
24
24
  spec.add_dependency "reverse_markdown", "~> 1.0"
25
+ spec.add_dependency "charlock_holmes", "~> 0.7"
25
26
 
26
27
  spec.add_development_dependency "bundler", "~> 1.11"
27
28
  spec.add_development_dependency "rake", "~> 10.0"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: qwik2md
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fumiaki MATSUSHIMA
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '1.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: charlock_holmes
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.7'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.7'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: bundler
71
85
  requirement: !ruby/object:Gem::Requirement