source2md 0.0.15 → 0.0.16
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/.gitignore +1 -0
- data/examples/type_partial_code.rb +4 -2
- data/examples/type_source_block.rb +26 -3
- data/lib/source2md/formatter/type_partial_code.rb +2 -2
- data/lib/source2md/formatter/type_source_block.rb +28 -6
- data/lib/source2md/formatter/type_text.rb +6 -3
- data/lib/source2md/regexp_builder.rb +1 -0
- data/lib/source2md/text_helper.rb +4 -0
- data/lib/source2md/version.rb +1 -1
- data/spec/formatter/type_partial_code_spec.rb +1 -0
- data/spec/formatter/type_source_block_spec.rb +37 -0
- data/spec/spec_helper.rb +1 -1
- data/spec/text_helper_spec.rb +4 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f98cf52536b132ac7b8a7ed2b99653c0b1c668c0d3b7bd3681e898854fa00b8a
|
4
|
+
data.tar.gz: e78fa6dbddfefd98ee5757ca3f41911568df9825c332e1e1453e0df3ff0d7b7f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a9844d91a277c17f86037ab84efbf5b1f0bcd627fbb00ef16188f19b0e90716b0d7402644b7b60f5975919d7b194851d762463b93a7a50461e09b1eb5459d95f
|
7
|
+
data.tar.gz: 8d18aeff6e37f72c9c18c8187d64a62e9078cd534e280ef4c165a99c973f6bf079a610b57d86d8fe9d2b7abc8143ce7a9acbedbce2f710dcb537467358acddf4
|
data/.gitignore
CHANGED
@@ -5,15 +5,17 @@ Source2MD.data_block_exclude = true
|
|
5
5
|
|
6
6
|
puts Source2MD::Element.new(<<~EOS).to_md
|
7
7
|
#+partial_code_name: foo
|
8
|
+
#+data_block_exclude: true
|
8
9
|
a
|
9
10
|
b
|
10
11
|
c
|
11
12
|
__END__
|
12
13
|
foo
|
13
14
|
EOS
|
14
|
-
# >> head: {"partial_code_name"=>"foo"}
|
15
|
+
# >> head: {"partial_code_name"=>"foo", "data_block_exclude"=>"true"}
|
15
16
|
# >> body: "a\n b\nc\n__END__\nfoo\n"
|
16
17
|
# >> Source2MD::Formatter::TypeHidden => false
|
18
|
+
# >> Source2MD::Formatter::TypeEval =>
|
17
19
|
# >> Source2MD::Formatter::TypeCodeInclude =>
|
18
20
|
# >> Source2MD::Formatter::TypeRawInclude =>
|
19
21
|
# >> Source2MD::Formatter::TypeParseInclude =>
|
@@ -26,7 +28,7 @@ EOS
|
|
26
28
|
# >> Source2MD::Formatter::TypeText => false
|
27
29
|
# >> Source2MD::Formatter::TypePartialCode => true
|
28
30
|
# >> > -------------------------------------------------------------------------------- Source2MD::Formatter::TypePartialCode
|
29
|
-
# >> > {"partial_code_name"=>"foo"}
|
31
|
+
# >> > {"partial_code_name"=>"foo", "data_block_exclude"=>"true"}
|
30
32
|
# >> > ------------------------------------------------------------ in
|
31
33
|
# >> > a
|
32
34
|
# >> > b
|
@@ -2,18 +2,41 @@
|
|
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 data_block_exclude!
|
6
6
|
(foo)
|
7
|
+
__END__
|
8
|
+
xxx
|
7
9
|
#+END_SRC
|
8
10
|
EOS
|
11
|
+
# >> head: {}
|
12
|
+
# >> body: "#+BEGIN_SRC diff xxx:yyy data_block_exclude!\n(foo)\n__END__\nxxx\n#+END_SRC\n"
|
13
|
+
# >> Source2MD::Formatter::TypeHidden => false
|
14
|
+
# >> Source2MD::Formatter::TypeEval =>
|
15
|
+
# >> Source2MD::Formatter::TypeCodeInclude =>
|
16
|
+
# >> Source2MD::Formatter::TypeRawInclude =>
|
17
|
+
# >> Source2MD::Formatter::TypeParseInclude =>
|
18
|
+
# >> Source2MD::Formatter::TypeTitle => false
|
19
|
+
# >> Source2MD::Formatter::TypeWarn =>
|
20
|
+
# >> Source2MD::Formatter::TypeAlert =>
|
21
|
+
# >> Source2MD::Formatter::TypeMethod =>
|
22
|
+
# >> Source2MD::Formatter::TypeTable => false
|
23
|
+
# >> Source2MD::Formatter::TypeSourceBlock => true
|
9
24
|
# >> > -------------------------------------------------------------------------------- Source2MD::Formatter::TypeSourceBlock
|
10
25
|
# >> > {}
|
11
26
|
# >> > ------------------------------------------------------------ in
|
12
|
-
# >> > #+BEGIN_SRC diff xxx:yyy
|
27
|
+
# >> > #+BEGIN_SRC diff xxx:yyy data_block_exclude!
|
13
28
|
# >> > (foo)
|
29
|
+
# >> > __END__
|
30
|
+
# >> > xxx
|
14
31
|
# >> > #+END_SRC
|
15
32
|
# >> >
|
33
|
+
# >> >
|
16
34
|
# >> > ------------------------------------------------------------ out
|
35
|
+
# >> > ```diff xxx:yyy
|
36
|
+
# >> > (foo)
|
37
|
+
# >> > ```
|
17
38
|
# >> >
|
18
39
|
# >> > ------------------------------------------------------------
|
19
|
-
# >>
|
40
|
+
# >> ```diff xxx:yyy
|
41
|
+
# >> (foo)
|
42
|
+
# >> ```
|
@@ -12,8 +12,8 @@ module Source2MD
|
|
12
12
|
private
|
13
13
|
|
14
14
|
def body
|
15
|
-
if Source2MD.data_block_exclude
|
16
|
-
element.body
|
15
|
+
if element.head["data_block_exclude"] || Source2MD.data_block_exclude
|
16
|
+
TextHelper.data_block_exclude(element.body)
|
17
17
|
else
|
18
18
|
element.body
|
19
19
|
end
|
@@ -1,31 +1,53 @@
|
|
1
1
|
module Source2MD
|
2
2
|
module Formatter
|
3
3
|
class TypeSourceBlock < Base
|
4
|
+
OPTION_KEYS = [
|
5
|
+
"hidden!",
|
6
|
+
"data_block_exclude!",
|
7
|
+
]
|
8
|
+
|
4
9
|
def self.accept?(element)
|
5
10
|
element.body.match?(%r{#{RE.meta_re}\+BEGIN_SRC})
|
6
11
|
end
|
7
12
|
|
8
13
|
def to_md
|
9
|
-
if
|
14
|
+
if option_list.include?("hidden!")
|
10
15
|
return ""
|
11
16
|
end
|
12
|
-
CodeBlock.new(body, desc:
|
17
|
+
CodeBlock.new(body, desc: clean_descs.join(" ").presence).to_md
|
13
18
|
end
|
14
19
|
|
15
20
|
private
|
16
21
|
|
17
22
|
def body
|
18
|
-
element.body.match(%r{#{RE.meta_re}\+BEGIN_SRC.*?\R(.*)#{RE.meta_re}\+END_SRC}m).captures.first
|
23
|
+
content = element.body.match(%r{#{RE.meta_re}\+BEGIN_SRC.*?\R(.*)#{RE.meta_re}\+END_SRC}m).captures.first
|
24
|
+
data_block_exclude(content)
|
19
25
|
end
|
20
26
|
|
21
|
-
def
|
27
|
+
def desc_line
|
22
28
|
if md = element.body.match(%r{#{RE.meta_re}\+BEGIN_SRC (.+)\R})
|
23
29
|
md.captures.first
|
24
30
|
end
|
25
31
|
end
|
26
32
|
|
27
|
-
def
|
28
|
-
|
33
|
+
def option_list
|
34
|
+
@option_list ||= desc_line.to_s.split(/\s+/).to_set
|
35
|
+
end
|
36
|
+
|
37
|
+
def data_block_exclude(content)
|
38
|
+
if data_block_exclude?
|
39
|
+
TextHelper.data_block_exclude(content)
|
40
|
+
else
|
41
|
+
content
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def data_block_exclude?
|
46
|
+
option_list.include?("data_block_exclude!") || Source2MD.data_block_exclude
|
47
|
+
end
|
48
|
+
|
49
|
+
def clean_descs
|
50
|
+
option_list - OPTION_KEYS
|
29
51
|
end
|
30
52
|
end
|
31
53
|
end
|
@@ -1,13 +1,16 @@
|
|
1
1
|
module Source2MD
|
2
2
|
module Formatter
|
3
3
|
class TypeText < Base
|
4
|
+
|
4
5
|
# "# xxx"
|
5
6
|
# "#"
|
6
|
-
|
7
|
+
def self.regexp
|
8
|
+
%r{#{RE.meta_re}( |$)}
|
9
|
+
end
|
7
10
|
|
8
11
|
def self.accept?(element)
|
9
12
|
if element.body.present?
|
10
|
-
element.body.lines.all? { |e| e.match?(
|
13
|
+
element.body.lines.all? { |e| e.match?(regexp) }
|
11
14
|
end
|
12
15
|
end
|
13
16
|
|
@@ -18,7 +21,7 @@ module Source2MD
|
|
18
21
|
private
|
19
22
|
|
20
23
|
def body
|
21
|
-
s = element.body.remove(
|
24
|
+
s = element.body.remove(self.class.regexp)
|
22
25
|
if element.head["squish"] == "true"
|
23
26
|
s = TextHelper.squish(s)
|
24
27
|
end
|
data/lib/source2md/version.rb
CHANGED
@@ -36,5 +36,42 @@ module Source2MD
|
|
36
36
|
EOS
|
37
37
|
actual.should == ""
|
38
38
|
end
|
39
|
+
|
40
|
+
it "works" do
|
41
|
+
actual = Element.new(<<~EOS).to_md
|
42
|
+
#+BEGIN_SRC xxx:yyy data_block_exclude!
|
43
|
+
(foo)
|
44
|
+
__END__
|
45
|
+
xxx
|
46
|
+
#+END_SRC
|
47
|
+
EOS
|
48
|
+
actual.should == <<~EOS
|
49
|
+
```xxx:yyy
|
50
|
+
(foo)
|
51
|
+
```
|
52
|
+
EOS
|
53
|
+
end
|
39
54
|
end
|
40
55
|
end
|
56
|
+
# >> ...F
|
57
|
+
# >>
|
58
|
+
# >> Failures:
|
59
|
+
# >>
|
60
|
+
# >> 1) works
|
61
|
+
# >> Failure/Error: Unable to find - to read failed line
|
62
|
+
# >>
|
63
|
+
# >> expected: ""
|
64
|
+
# >> got: "```xxx:yyy data_block_exclude\n```\n" (using ==)
|
65
|
+
# >> Diff:
|
66
|
+
# >> @@ -1,2 +1,4 @@
|
67
|
+
# >> +```xxx:yyy data_block_exclude
|
68
|
+
# >> +```
|
69
|
+
# >> # -:47:in `block (2 levels) in <module:Source2MD>'
|
70
|
+
# >>
|
71
|
+
# >> Finished in 0.01747 seconds (files took 0.33507 seconds to load)
|
72
|
+
# >> 4 examples, 1 failure
|
73
|
+
# >>
|
74
|
+
# >> Failed examples:
|
75
|
+
# >>
|
76
|
+
# >> rspec -:40 # works
|
77
|
+
# >>
|
data/spec/spec_helper.rb
CHANGED
data/spec/text_helper_spec.rb
CHANGED
@@ -19,5 +19,9 @@ module Source2MD
|
|
19
19
|
assert { TextHelper.space_prefix_remove(" a\n b\n") == "a\n b\n" }
|
20
20
|
assert { TextHelper.space_prefix_remove(" a\n\n b\n") == "a\n\n b\n" }
|
21
21
|
end
|
22
|
+
|
23
|
+
it "data_block_exclude" do
|
24
|
+
assert { TextHelper.data_block_exclude("(before)\n__END__\n(after)") == "(before)\n" }
|
25
|
+
end
|
22
26
|
end
|
23
27
|
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.16
|
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-12-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|