source2md 0.0.6 → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 45ea284efbf369a44f443d19ad9efef483c50d71b7d0a6a3061e22fd0a844ab4
4
- data.tar.gz: f5e5ae8ac1275e92d6a09161f6561e3ca3ed39e13b821d69a3b5ceae53d23467
3
+ metadata.gz: f07581e2e1a43897fbabf84171220745ae7ca72f96a19fd0f56e9aac6e73bd5d
4
+ data.tar.gz: 62e064eaf58861b1abf0b04739e54715a2efbcc74ced61fb0c949e232bf6e3a0
5
5
  SHA512:
6
- metadata.gz: 9b801b23ca8be860c0f76bbc6e3184b79ee9872b424108b83598dc23362667e00c21eb857c2995698addee97f85bd2995dc421b4f2d6dadd871e7f3db80eb6d0
7
- data.tar.gz: 4972b72106e655da9078ce8962eb4bd32fbecccd520c1d7d0bd24b7e1029b6d9fa1aa2775ce9b9a4a980fd7af9d373d35be8c1666d67868eb1a04d5589f036cf
6
+ metadata.gz: b426db58ee1eda88c7c9174867cdb6dd9e67d951605a74dc0c2fbcaf8d3464819a84042822fc7d99d78513762be1c3de491af6a2f61dd2d755f8a268fcd58bde
7
+ data.tar.gz: 2d97f41bc6ab44b7a2019c2008a4845f879c7b91e82a68ed5fc98e158eebb9a660fe7a34ebfc9a7ef2551c389fc0a84360bc67bd57de56e465900f717a6544c1
data/README.md CHANGED
@@ -77,9 +77,7 @@ EOS
77
77
 
78
78
  ### Code include ###
79
79
 
80
- ```ruby
81
80
  Insert inside the code block.
82
- ```
83
81
 
84
82
  ```ruby
85
83
  File.write("/tmp/hello.html", "<p>Hello</p>")
@@ -275,7 +273,7 @@ Using this option allows you to split a line regardless of the markdown library.
275
273
 
276
274
  ```ruby
277
275
  puts Source2MD::Section.new(<<~EOS).to_md
278
- #+oneline: true
276
+ #+squish: true
279
277
  # Lorem ipsum dolor sit amet, consectetur adipisicing elit,
280
278
  # sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
281
279
  EOS
@@ -285,6 +283,35 @@ EOS
285
283
  > Lorem ipsum dolor sit amet, consectetur adipisicing elit,sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
286
284
  > ```
287
285
 
286
+ ### Squish Text ###
287
+
288
+ Single spaces for line breaks and consecutive spaces.
289
+
290
+ ```ruby
291
+ puts Source2MD::Section.new(<<~EOS).to_md
292
+ #+squish: true
293
+ # Lorem ipsum dolor sit amet, consectetur adipisicing elit,
294
+ # sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
295
+ EOS
296
+ ```
297
+
298
+ > ```
299
+ > Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
300
+ > ```
301
+
302
+ ### Hankaku Kana ###
303
+
304
+ JISX0208 Katakana to JISX0201 Katakana.
305
+
306
+ ```ruby
307
+ puts Source2MD::Section.new(<<~EOS).to_md
308
+ #+hankaku_kana: true
309
+ # アア
310
+ EOS
311
+ ```
312
+
313
+ > アア
314
+
288
315
  ### Parse include ###
289
316
 
290
317
  Paste the results of processing other files with the same rules.
@@ -3,7 +3,7 @@ require "./setup"
3
3
 
4
4
  ### Code include ###
5
5
 
6
- Insert inside the code block.
6
+ # Insert inside the code block.
7
7
 
8
8
  #+BEGIN_SRC
9
9
  File.write("/tmp/hello.html", "<p>Hello</p>")
@@ -7,7 +7,7 @@ require "./setup"
7
7
 
8
8
  #+BEGIN_SRC
9
9
  puts Source2MD::Section.new(<<~EOS).to_md
10
- #+oneline: true
10
+ #+squish: true
11
11
  # Lorem ipsum dolor sit amet, consectetur adipisicing elit,
12
12
  # sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
13
13
  EOS
@@ -0,0 +1,18 @@
1
+ #+hidden: true
2
+ require "./setup"
3
+
4
+ ### Squish Text ###
5
+
6
+ # Single spaces for line breaks and consecutive spaces.
7
+
8
+ #+BEGIN_SRC
9
+ puts Source2MD::Section.new(<<~EOS).to_md
10
+ #+squish: true
11
+ # Lorem ipsum dolor sit amet, consectetur adipisicing elit,
12
+ # sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
13
+ EOS
14
+ #+END_SRC
15
+
16
+ # > ```
17
+ # > Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
18
+ # > ```
@@ -0,0 +1,15 @@
1
+ #+hidden: true
2
+ require "./setup"
3
+
4
+ ### Hankaku Kana ###
5
+
6
+ # JISX0208 Katakana to JISX0201 Katakana.
7
+
8
+ #+BEGIN_SRC
9
+ puts Source2MD::Section.new(<<~EOS).to_md
10
+ #+hankaku_kana: true
11
+ # アア
12
+ EOS
13
+ #+END_SRC
14
+
15
+ # > アア
@@ -2,13 +2,28 @@
2
2
  require "./setup"
3
3
 
4
4
  puts Source2MD::Element.new(<<~EOS).to_md
5
- #+oneline: true
5
+ #+squish: true
6
6
  # a
7
7
  # b
8
8
  #
9
9
  # c
10
10
  # d
11
11
  EOS
12
+
13
+ puts Source2MD::Element.new(<<~EOS).to_md
14
+ #+squish: true
15
+ # a
16
+ # b
17
+ #
18
+ # c
19
+ # d
20
+ EOS
21
+
22
+ puts Source2MD::Element.new(<<~EOS).to_md
23
+ #+hankaku_kana: true
24
+ # アア
25
+ EOS
26
+
12
27
  # >> > -------------------------------------------------------------------------------- Source2MD::Formatter::TypeText
13
28
  # >> > {"oneline"=>"true"}
14
29
  # >> > ------------------------------------------------------------ in
@@ -22,3 +37,25 @@ EOS
22
37
  # >> > abcd
23
38
  # >> > ------------------------------------------------------------
24
39
  # >> abcd
40
+ # >> > -------------------------------------------------------------------------------- Source2MD::Formatter::TypeText
41
+ # >> > {"squish"=>"true"}
42
+ # >> > ------------------------------------------------------------ in
43
+ # >> > # a
44
+ # >> > # b
45
+ # >> > #
46
+ # >> > # c
47
+ # >> > # d
48
+ # >> >
49
+ # >> > ------------------------------------------------------------ out
50
+ # >> > a b c d
51
+ # >> > ------------------------------------------------------------
52
+ # >> a b c d
53
+ # >> > -------------------------------------------------------------------------------- Source2MD::Formatter::TypeText
54
+ # >> > {"hankaku_kana"=>"true"}
55
+ # >> > ------------------------------------------------------------ in
56
+ # >> > # アア
57
+ # >> >
58
+ # >> > ------------------------------------------------------------ out
59
+ # >> > アア
60
+ # >> > ------------------------------------------------------------
61
+ # >> アア
data/lib/source2md/cli.rb CHANGED
@@ -2,6 +2,7 @@ module Source2MD
2
2
  class Cli < Thor
3
3
  class_option :debug, type: :boolean, aliases: "-d", default: false
4
4
  class_option :xmp_out_exclude, type: :boolean, aliases: "-x", default: false
5
+ class_option :readonly, type: :boolean, default: true
5
6
 
6
7
  def initialize(...)
7
8
  super
@@ -12,6 +13,7 @@ module Source2MD
12
13
  end
13
14
 
14
15
  Source2MD.xmp_out_exclude = options[:xmp_out_exclude]
16
+ Source2MD.readonly = options[:readonly]
15
17
 
16
18
  tp Source2MD.config
17
19
  end
@@ -1,7 +1,7 @@
1
1
  module Source2MD
2
2
  class CodeBlock
3
3
  PADDING_KEEP = 2
4
- MARK = "# =>"
4
+ MARK = /(?:#|\/\/) =>/
5
5
 
6
6
  attr_accessor :code
7
7
 
@@ -58,10 +58,10 @@ module Source2MD
58
58
  # end
59
59
 
60
60
  def comment_mark_justfiy(line)
61
- line.gsub(/(.*?)\s*#{MARK}(.*)/) {
62
- a, b = Regexp.last_match.captures
61
+ line.gsub(/(.*?)\s*(#{MARK})(.*)/) {
62
+ a, b, c = Regexp.last_match.captures
63
63
  space = " " * (PADDING_KEEP + (max - a.size))
64
- [a, space, MARK, b].join
64
+ [a, space, b, c].join
65
65
  }
66
66
  end
67
67
 
@@ -72,7 +72,7 @@ module Source2MD
72
72
  def max
73
73
  @max ||= yield_self do
74
74
  av = lines
75
- av = av.find_all { |e| e.include?(MARK) }
75
+ av = av.find_all { |e| e.match?(MARK) }
76
76
  av = av.collect { |e| e.gsub(/\s*#{MARK}.*/, "").size }
77
77
  av.max
78
78
  end
@@ -1,6 +1,6 @@
1
1
  module Source2MD
2
2
  class Element
3
- KEY_VALUE_REGEXP = /^#\+(\S+):\s*(.*)\R?/ # #+key: value
3
+ KEY_VALUE_REGEXP = /^(?:#|\/\/)\+(\S+):\s*(.*)\R?/ # #+key: value
4
4
 
5
5
  PLUGINS = [
6
6
  Formatter::TypeHidden, # #+hidden: true
@@ -17,13 +17,15 @@ module Source2MD
17
17
 
18
18
  def body
19
19
  s = element.body.remove(REGEXP)
20
- s = oneline(s)
21
- end
22
-
23
- def oneline(s)
20
+ if element.head["squish"] == "true"
21
+ s = TextHelper.squish(s)
22
+ end
24
23
  if element.head["oneline"] == "true"
25
24
  s = TextHelper.oneline(s)
26
25
  end
26
+ if element.head["hankaku_kana"] == "true"
27
+ s = TextHelper.hankaku_kana(s)
28
+ end
27
29
  s
28
30
  end
29
31
  end
@@ -7,7 +7,13 @@ module Source2MD
7
7
  end
8
8
 
9
9
  def call
10
+ if output_file.exist?
11
+ FileUtils.chmod("a+w", output_file)
12
+ end
10
13
  output_file.write(to_md)
14
+ if Source2MD.readonly
15
+ FileUtils.chmod("a-w", output_file)
16
+ end
11
17
  puts "write: #{output_file}"
12
18
  end
13
19
 
@@ -2,8 +2,6 @@ module Source2MD
2
2
  class Scanner
3
3
  SEPARATOR = "\\R{2,}"
4
4
 
5
- # MD_CODE_BLOCK_RE = /^# ```.*?^# ```/m
6
-
7
5
  SRC_BEGIN_KEY = "BEGIN_SRC"
8
6
  SRC_END_KEY = "END_SRC"
9
7
  SRC_BLOCK_RE = /^#\+#{SRC_BEGIN_KEY}.*?^#\+#{SRC_END_KEY}/m
@@ -11,7 +9,6 @@ module Source2MD
11
9
  NORMAL_BLOCK_RE = /.*?#{SEPARATOR}/m
12
10
 
13
11
  PARAGRAPH_RE = Regexp.union [
14
- # MD_CODE_BLOCK_RE,
15
12
  SRC_BLOCK_RE,
16
13
  NORMAL_BLOCK_RE,
17
14
  ]
@@ -11,7 +11,15 @@ module Source2MD
11
11
  end
12
12
 
13
13
  def oneline(text)
14
- text.remove(/\R/)
14
+ text.remove(/\R+/)
15
+ end
16
+
17
+ def squish(text)
18
+ text.gsub(/[[:space:]]+/, " ").strip
19
+ end
20
+
21
+ def hankaku_kana(text)
22
+ NKF.nkf("-wxZ4", text)
15
23
  end
16
24
  end
17
25
  end
@@ -1,3 +1,3 @@
1
1
  module Source2MD
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.8"
3
3
  end
data/lib/source2md.rb CHANGED
@@ -14,6 +14,7 @@ module Source2MD
14
14
  include ActiveSupport::Configurable
15
15
  config_accessor(:debug) { false }
16
16
  config_accessor(:xmp_out_exclude) { false }
17
+ config_accessor(:readonly) { true }
17
18
  end
18
19
 
19
20
  require "zeitwerk"
@@ -13,7 +13,7 @@ EOS
13
13
  EOS
14
14
  end
15
15
 
16
- it "works" do
16
+ it "oneline" do
17
17
  actual = Element.new(<<~EOS).to_md
18
18
  #+oneline: true
19
19
  # a
@@ -26,5 +26,27 @@ EOS
26
26
  abcd
27
27
  EOS
28
28
  end
29
+
30
+ it "squish" do
31
+ actual = Element.new(<<~EOS).to_md
32
+ #+squish: true
33
+ # a
34
+ # b
35
+ #
36
+ # c
37
+ # d
38
+ EOS
39
+ actual.should == <<~EOS.strip
40
+ a b c d
41
+ EOS
42
+ end
43
+
44
+ it "hankaku_kana" do
45
+ actual = Element.new(<<~EOS).to_md
46
+ #+hankaku_kana: true
47
+ # アア
48
+ EOS
49
+ actual.should == "アア"
50
+ end
29
51
  end
30
52
  end
@@ -11,5 +11,9 @@ module Source2MD
11
11
  assert { TextHelper.add_newline_at_end_of_text("A\n") == "A\n" }
12
12
  assert { TextHelper.add_newline_at_end_of_text("A\n\n") == "A\n" }
13
13
  end
14
+
15
+ it "hankaku_kana" do
16
+ assert { TextHelper.hankaku_kana("アア") == "アア" }
17
+ end
14
18
  end
15
19
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: source2md
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Akira Ikeda
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-07-22 00:00:00.000000000 Z
11
+ date: 2023-08-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -161,7 +161,9 @@ files:
161
161
  - doc/0200_alert.rb
162
162
  - doc/0210_text.rb
163
163
  - doc/0220_text_oneline.rb
164
- - doc/0230_parse_include.rb
164
+ - doc/0230_text_squish.rb
165
+ - doc/0240_text_hankaku_kana.rb
166
+ - doc/0250_parse_include.rb
165
167
  - doc/setup.rb
166
168
  - examples/cli.rb
167
169
  - examples/element_text.rb
@@ -246,7 +248,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
246
248
  - !ruby/object:Gem::Version
247
249
  version: '0'
248
250
  requirements: []
249
- rubygems_version: 3.4.16
251
+ rubygems_version: 3.4.18
250
252
  signing_key:
251
253
  specification_version: 4
252
254
  summary: Markdown generator from source code