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 +4 -4
- data/README.md +29 -8
- data/doc/0130_hidden.rb +7 -5
- data/doc/0140_code_include.rb +1 -1
- data/doc/0230_text_squish.rb +18 -0
- data/doc/0240_text_hankaku_kana.rb +15 -0
- data/examples/type_code_include.rb +17 -12
- data/examples/type_source_block.rb +11 -21
- data/examples/type_text.rb +37 -0
- data/lib/source2md/formatter/type_source_block.rb +7 -0
- data/lib/source2md/formatter/type_text.rb +6 -4
- data/lib/source2md/scanner.rb +9 -12
- data/lib/source2md/text_helper.rb +9 -1
- data/lib/source2md/version.rb +1 -1
- data/spec/formatter/type_source_block_spec.rb +9 -0
- data/spec/formatter/type_text_spec.rb +23 -1
- data/spec/text_helper_spec.rb +4 -0
- metadata +6 -4
- /data/doc/{0230_parse_include.rb → 0250_parse_include.rb} +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a21ad256d10d0e8ac822542cfd3b1487ac15ce8e24e9ca7d49b79b8ebef0a29c
|
4
|
+
data.tar.gz: d437547f1970f22495788b9a39df4c4c953a90a567765181c8ba3fad37dbc095
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
16
|
-
|
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
|
data/doc/0140_code_include.rb
CHANGED
@@ -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
|
+
# > ```
|
@@ -7,15 +7,20 @@ puts Source2MD::Element.new(<<~EOS).to_md
|
|
7
7
|
#+name:
|
8
8
|
|
9
9
|
EOS
|
10
|
-
#
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
#
|
15
|
-
#
|
16
|
-
#
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
20
|
-
#
|
21
|
-
#
|
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
|
-
# >>
|
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
|
-
# >> ```
|
data/examples/type_text.rb
CHANGED
@@ -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
|
-
|
21
|
-
|
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
|
data/lib/source2md/scanner.rb
CHANGED
@@ -1,19 +1,16 @@
|
|
1
1
|
module Source2MD
|
2
2
|
class Scanner
|
3
|
-
SEPARATOR
|
3
|
+
SEPARATOR = "\\R{2,}"
|
4
4
|
|
5
|
-
|
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
|
-
|
8
|
-
END_KEY = "END_SRC"
|
9
|
-
SOURCE_BLOCK_REGEXP = /^#\+#{BEGIN_KEY}.*?^#\+#{END_KEY}/m
|
9
|
+
NORMAL_BLOCK_RE = /.*?#{SEPARATOR}/m
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
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(
|
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
|
data/lib/source2md/version.rb
CHANGED
@@ -13,7 +13,7 @@ EOS
|
|
13
13
|
EOS
|
14
14
|
end
|
15
15
|
|
16
|
-
it "
|
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
|
data/spec/text_helper_spec.rb
CHANGED
@@ -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.
|
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-
|
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/
|
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.
|
251
|
+
rubygems_version: 3.4.17
|
250
252
|
signing_key:
|
251
253
|
specification_version: 4
|
252
254
|
summary: Markdown generator from source code
|
File without changes
|