source2md 0.0.5 → 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: f98d5b2f1f4a15eb936a3fa1fabbc4e38316b01f65bf317253cbdf6b3e8d79f5
4
- data.tar.gz: 9383810a16af7443690a4de9e2528f30d916319129f3bde75da1905325924048
3
+ metadata.gz: a21ad256d10d0e8ac822542cfd3b1487ac15ce8e24e9ca7d49b79b8ebef0a29c
4
+ data.tar.gz: d437547f1970f22495788b9a39df4c4c953a90a567765181c8ba3fad37dbc095
5
5
  SHA512:
6
- metadata.gz: db0be63ef5b74fc60841e4f3db52c928ece933c170580f28d5e8892c41f1bad662e68519d80ddf20fe325d840a7f93ffc59bb2a522532485afb581b6d1af637b
7
- data.tar.gz: 4c3f17eff3f140510e33061340fbecec8e909c9ac869324446f5c737d1d457f42c59477b278446e482d99f9e320e441ffa00318b3b543afac184f32557845bae
6
+ metadata.gz: '0920cf0732141436270a375f378a2981b28fcbcefb58e74c4eca9d29fb83e3473ccbc161c956cef54c24ab998d62c618c38fcca6c66cb63422ea6458363448dd'
7
+ data.tar.gz: e25345a90c1e3d46899a762a87582b3c9c6e2ec398d38a2a1c815af4fe03094ec823ef840b97a24e7089c3636280f940c5192751213e2e7eecfdfcec8ac74e97
data/README.md CHANGED
@@ -72,20 +72,12 @@ EOS
72
72
  puts Source2MD::Section.new(<<~EOS).to_md
73
73
  #+hidden: true
74
74
  p "This paragraph is not displayed"
75
-
76
- p "This paragraph is displayed"
77
75
  EOS
78
76
  ```
79
77
 
80
- > ```ruby
81
- > p "This paragraph is displayed"
82
- > ```
83
-
84
78
  ### Code include ###
85
79
 
86
- ```ruby
87
80
  Insert inside the code block.
88
- ```
89
81
 
90
82
  ```ruby
91
83
  File.write("/tmp/hello.html", "<p>Hello</p>")
@@ -291,6 +283,35 @@ EOS
291
283
  > Lorem ipsum dolor sit amet, consectetur adipisicing elit,sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
292
284
  > ```
293
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
+
294
315
  ### Parse include ###
295
316
 
296
317
  Paste the results of processing other files with the same rules.
data/doc/0130_hidden.rb CHANGED
@@ -7,11 +7,13 @@ require "./setup"
7
7
  puts Source2MD::Section.new(<<~EOS).to_md
8
8
  #+hidden: true
9
9
  p "This paragraph is not displayed"
10
-
11
- p "This paragraph is displayed"
12
10
  EOS
13
11
  #+END_SRC
14
12
 
15
- # > ```ruby
16
- # > p "This paragraph is displayed"
17
- # > ```
13
+ #+BEGIN_SRC
14
+ puts Source2MD::Section.new(<<~EOS).to_md
15
+ #+BEGIN_SRC hidden!
16
+ p "This paragraph is not displayed"
17
+ #+END_SRC
18
+ EOS
19
+ #+END_SRC
@@ -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
+ # > アア
@@ -7,15 +7,20 @@ puts Source2MD::Element.new(<<~EOS).to_md
7
7
  #+name:
8
8
 
9
9
  EOS
10
- # ~> /Users/ikeda/src/source2md/lib/source2md/part/type_include.rb:27:in `read': No such file or directory @ rb_sysopen - /Users/ikeda/src/source2md/examples/input.yml diff xxx:yyy (Errno::ENOENT)
11
- # ~> from /Users/ikeda/src/source2md/lib/source2md/part/type_include.rb:27:in `read'
12
- # ~> from /Users/ikeda/src/source2md/lib/source2md/part/type_include.rb:27:in `body'
13
- # ~> from /Users/ikeda/src/source2md/lib/source2md/part/type_include.rb:17:in `to_md'
14
- # ~> from /Users/ikeda/src/source2md/lib/source2md/part/base.rb:25:in `block in initialize'
15
- # ~> from /opt/rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/activesupport-7.0.6/lib/active_support/logger_thread_safe_level.rb:58:in `add'
16
- # ~> from /opt/rbenv/versions/3.2.2/lib/ruby/3.2.0/logger.rb:689:in `debug'
17
- # ~> from /Users/ikeda/src/source2md/lib/source2md/part/base.rb:13:in `initialize'
18
- # ~> from /Users/ikeda/src/source2md/lib/source2md/part/type_include.rb:9:in `initialize'
19
- # ~> from /Users/ikeda/src/source2md/lib/source2md/element.rb:27:in `new'
20
- # ~> from /Users/ikeda/src/source2md/lib/source2md/element.rb:27:in `to_md'
21
- # ~> from -:3:in `<main>'
10
+ # >> > -------------------------------------------------------------------------------- Source2MD::Formatter::TypeCodeInclude
11
+ # >> > {"code_include"=>"input.yml", "name"=>""}
12
+ # >> > ------------------------------------------------------------ in
13
+ # >> >
14
+ # >> >
15
+ # >> > ------------------------------------------------------------ out
16
+ # >> > ```yml:
17
+ # >> > ---
18
+ # >> > one:
19
+ # >> > foo: 1
20
+ # >> > ```
21
+ # >> > ------------------------------------------------------------
22
+ # >> ```yml:
23
+ # >> ---
24
+ # >> one:
25
+ # >> foo: 1
26
+ # >> ```
@@ -2,28 +2,18 @@
2
2
  require "./setup"
3
3
 
4
4
  puts Source2MD::Element.new(<<~EOS).to_md
5
- #+BEGIN_SRC diff xxx:yyy
5
+ #+BEGIN_SRC diff xxx:yyy hidden!
6
6
  (foo)
7
7
  #+END_SRC
8
8
  EOS
9
- # >> --------------------------------------------------------------------------------
10
- # >> Source2MD::Part::TypeSourceBlock
9
+ # >> > -------------------------------------------------------------------------------- Source2MD::Formatter::TypeSourceBlock
10
+ # >> > {}
11
+ # >> > ------------------------------------------------------------ in
12
+ # >> > #+BEGIN_SRC diff xxx:yyy hidden!
13
+ # >> > (foo)
14
+ # >> > #+END_SRC
15
+ # >> >
16
+ # >> > ------------------------------------------------------------ out
17
+ # >> >
18
+ # >> > ------------------------------------------------------------
11
19
  # >>
12
- # >> head:
13
- # >> {}
14
- # >>
15
- # >> in:
16
- # >> #+BEGIN_SRC diff xxx:yyy
17
- # >> (foo)
18
- # >> #+END_SRC
19
- # >>
20
- # >> out:
21
- # >> ```diff xxx:yyy
22
- # >> diff xxx:yyy
23
- # >> (foo)
24
- # >> ```
25
- # >> --------------------------------------------------------------------------------
26
- # >> ```diff xxx:yyy
27
- # >> diff xxx:yyy
28
- # >> (foo)
29
- # >> ```
@@ -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
+ # >> アア
@@ -6,6 +6,9 @@ module Source2MD
6
6
  end
7
7
 
8
8
  def to_md
9
+ if code_block_desc_keywords.include?("hidden!")
10
+ return ""
11
+ end
9
12
  CodeBlock.new(body, desc: code_block_desc).to_md
10
13
  end
11
14
 
@@ -20,6 +23,10 @@ module Source2MD
20
23
  md.captures.first.strip
21
24
  end
22
25
  end
26
+
27
+ def code_block_desc_keywords
28
+ code_block_desc.to_s.split(/\s+/).to_set
29
+ end
23
30
  end
24
31
  end
25
32
  end
@@ -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
@@ -1,19 +1,16 @@
1
1
  module Source2MD
2
2
  class Scanner
3
- SEPARATOR = "\\R{2,}"
3
+ SEPARATOR = "\\R{2,}"
4
4
 
5
- # MD_CODE_BLOCK_REGEXP = /^# ```.*?^# ```/m
5
+ SRC_BEGIN_KEY = "BEGIN_SRC"
6
+ SRC_END_KEY = "END_SRC"
7
+ SRC_BLOCK_RE = /^#\+#{SRC_BEGIN_KEY}.*?^#\+#{SRC_END_KEY}/m
6
8
 
7
- BEGIN_KEY = "BEGIN_SRC"
8
- END_KEY = "END_SRC"
9
- SOURCE_BLOCK_REGEXP = /^#\+#{BEGIN_KEY}.*?^#\+#{END_KEY}/m
9
+ NORMAL_BLOCK_RE = /.*?#{SEPARATOR}/m
10
10
 
11
- NORMAL_BLOCK_REGEXP = /.*?#{SEPARATOR}/m
12
-
13
- PARAGRAPH_REGEXP = Regexp.union [
14
- # MD_CODE_BLOCK_REGEXP,
15
- SOURCE_BLOCK_REGEXP,
16
- NORMAL_BLOCK_REGEXP,
11
+ PARAGRAPH_RE = Regexp.union [
12
+ SRC_BLOCK_RE,
13
+ NORMAL_BLOCK_RE,
17
14
  ]
18
15
 
19
16
  def initialize(content)
@@ -26,7 +23,7 @@ module Source2MD
26
23
  v = v.remove(/^# >>.*$/)
27
24
  end
28
25
  v = v + "\n\n"
29
- v = v.scan(PARAGRAPH_REGEXP)
26
+ v = v.scan(PARAGRAPH_RE)
30
27
  v = v.collect(&:strip)
31
28
  v = v.find_all(&:present?)
32
29
  end
@@ -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.5"
2
+ VERSION = "0.0.7"
3
3
  end
@@ -27,5 +27,14 @@ module Source2MD
27
27
  ```
28
28
  EOS
29
29
  end
30
+
31
+ it "works" do
32
+ actual = Element.new(<<~EOS).to_md
33
+ #+BEGIN_SRC diff xxx:yyy hidden!
34
+ (foo)
35
+ #+END_SRC
36
+ EOS
37
+ actual.should == ""
38
+ end
30
39
  end
31
40
  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.5
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