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 +4 -4
- data/README.md +30 -3
- data/doc/0140_code_include.rb +1 -1
- data/doc/0220_text_oneline.rb +1 -1
- data/doc/0230_text_squish.rb +18 -0
- data/doc/0240_text_hankaku_kana.rb +15 -0
- data/examples/type_text.rb +38 -1
- data/lib/source2md/cli.rb +2 -0
- data/lib/source2md/code_block.rb +5 -5
- data/lib/source2md/element.rb +1 -1
- data/lib/source2md/formatter/type_text.rb +6 -4
- data/lib/source2md/generator.rb +6 -0
- data/lib/source2md/scanner.rb +0 -3
- data/lib/source2md/text_helper.rb +9 -1
- data/lib/source2md/version.rb +1 -1
- data/lib/source2md.rb +1 -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: f07581e2e1a43897fbabf84171220745ae7ca72f96a19fd0f56e9aac6e73bd5d
|
4
|
+
data.tar.gz: 62e064eaf58861b1abf0b04739e54715a2efbcc74ced61fb0c949e232bf6e3a0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
#+
|
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.
|
data/doc/0140_code_include.rb
CHANGED
data/doc/0220_text_oneline.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
|
+
# > ```
|
data/examples/type_text.rb
CHANGED
@@ -2,13 +2,28 @@
|
|
2
2
|
require "./setup"
|
3
3
|
|
4
4
|
puts Source2MD::Element.new(<<~EOS).to_md
|
5
|
-
#+
|
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
|
data/lib/source2md/code_block.rb
CHANGED
@@ -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
|
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,
|
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.
|
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
|
data/lib/source2md/element.rb
CHANGED
@@ -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/generator.rb
CHANGED
data/lib/source2md/scanner.rb
CHANGED
@@ -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
|
data/lib/source2md/version.rb
CHANGED
data/lib/source2md.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.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-
|
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/
|
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.18
|
250
252
|
signing_key:
|
251
253
|
specification_version: 4
|
252
254
|
summary: Markdown generator from source code
|
File without changes
|