source2md 0.0.6 → 0.0.7

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: a21ad256d10d0e8ac822542cfd3b1487ac15ce8e24e9ca7d49b79b8ebef0a29c
4
+ data.tar.gz: d437547f1970f22495788b9a39df4c4c953a90a567765181c8ba3fad37dbc095
5
5
  SHA512:
6
- metadata.gz: 9b801b23ca8be860c0f76bbc6e3184b79ee9872b424108b83598dc23362667e00c21eb857c2995698addee97f85bd2995dc421b4f2d6dadd871e7f3db80eb6d0
7
- data.tar.gz: 4972b72106e655da9078ce8962eb4bd32fbecccd520c1d7d0bd24b7e1029b6d9fa1aa2775ce9b9a4a980fd7af9d373d35be8c1666d67868eb1a04d5589f036cf
6
+ metadata.gz: '0920cf0732141436270a375f378a2981b28fcbcefb58e74c4eca9d29fb83e3473ccbc161c956cef54c24ab998d62c618c38fcca6c66cb63422ea6458363448dd'
7
+ data.tar.gz: e25345a90c1e3d46899a762a87582b3c9c6e2ec398d38a2a1c815af4fe03094ec823ef840b97a24e7089c3636280f940c5192751213e2e7eecfdfcec8ac74e97
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>")
@@ -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>")
@@ -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
+ # > アア
@@ -9,6 +9,21 @@ puts Source2MD::Element.new(<<~EOS).to_md
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
+ # >> アア
@@ -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
@@ -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.7"
3
3
  end
@@ -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.7
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-07-28 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.17
250
252
  signing_key:
251
253
  specification_version: 4
252
254
  summary: Markdown generator from source code