source2md 0.0.15 → 0.0.17
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/examples/type_code_block.rb +41 -0
- data/examples/type_code_include.rb +10 -4
- data/examples/type_md_header.rb +43 -0
- data/examples/type_partial_code.rb +4 -2
- data/examples/type_quote.rb +34 -0
- data/examples/type_source_block.rb +26 -3
- data/lib/source2md/cli.rb +2 -0
- data/lib/source2md/element.rb +13 -1
- data/lib/source2md/formatter/type_code_block.rb +19 -0
- data/lib/source2md/formatter/type_list.rb +20 -0
- data/lib/source2md/formatter/type_md_header.rb +17 -0
- data/lib/source2md/formatter/type_partial_code.rb +2 -2
- data/lib/source2md/formatter/type_quote.rb +17 -0
- data/lib/source2md/formatter/type_source_block.rb +28 -6
- data/lib/source2md/formatter/type_text.rb +11 -4
- data/lib/source2md/regexp_builder.rb +1 -0
- data/lib/source2md/text_helper.rb +6 -1
- data/lib/source2md/version.rb +1 -1
- data/lib/source2md.rb +1 -0
- data/spec/formatter/type_code_block_spec.rb +23 -0
- data/spec/formatter/type_md_header_spec.rb +23 -0
- data/spec/formatter/type_partial_code_spec.rb +1 -0
- data/spec/formatter/type_quote_spec.rb +19 -0
- data/spec/formatter/type_source_block_spec.rb +37 -0
- data/spec/spec_helper.rb +1 -1
- data/spec/text_helper_spec.rb +8 -0
- metadata +16 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2d239ae5a48c121dc61a4fcd811cf6572f32b1ee793bae58a2a6c69f4e815d0f
|
4
|
+
data.tar.gz: 748a3da2af4129d894031af00b71b0e4553e4a21018b84a2d12e0f646ab1ce12
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4fa15b238f101e8da2f2f2f8a997e98697c032af2b6674b7896ae7ce0b325f695e213c1b321b8989bc58a9a448bc9d030dccd0251b2473f738ac5e0a0e920957
|
7
|
+
data.tar.gz: a7d8ca07d2bd122437b711b9ce90387783e1d96a560b422c1c83cd745f062656c4ab0cde8239532c611fb898fcb7d98396bd3d447975b558e93713bf85cd2d4d
|
data/.gitignore
CHANGED
@@ -0,0 +1,41 @@
|
|
1
|
+
#+hidden: true
|
2
|
+
require "./setup"
|
3
|
+
|
4
|
+
puts Source2MD::Element.new(<<~EOS).to_md
|
5
|
+
# ```
|
6
|
+
# foo
|
7
|
+
# ```
|
8
|
+
EOS
|
9
|
+
|
10
|
+
# >> head: {}
|
11
|
+
# >> body: "# ```\n# foo\n# ```\n"
|
12
|
+
# >> Source2MD::Formatter::TypeHidden => false
|
13
|
+
# >> Source2MD::Formatter::TypeEval =>
|
14
|
+
# >> Source2MD::Formatter::TypeCodeInclude =>
|
15
|
+
# >> Source2MD::Formatter::TypeRawInclude =>
|
16
|
+
# >> Source2MD::Formatter::TypeParseInclude =>
|
17
|
+
# >> Source2MD::Formatter::TypeTitle => false
|
18
|
+
# >> Source2MD::Formatter::TypeWarn =>
|
19
|
+
# >> Source2MD::Formatter::TypeAlert =>
|
20
|
+
# >> Source2MD::Formatter::TypeMethod =>
|
21
|
+
# >> Source2MD::Formatter::TypeTable => false
|
22
|
+
# >> Source2MD::Formatter::TypeSourceBlock => false
|
23
|
+
# >> Source2MD::Formatter::TypeMdHeader =>
|
24
|
+
# >> Source2MD::Formatter::TypeCodeBlock => true
|
25
|
+
# >> > -------------------------------------------------------------------------------- Source2MD::Formatter::TypeCodeBlock
|
26
|
+
# >> > {}
|
27
|
+
# >> > ------------------------------------------------------------ in
|
28
|
+
# >> > # ```
|
29
|
+
# >> > # foo
|
30
|
+
# >> > # ```
|
31
|
+
# >> >
|
32
|
+
# >> >
|
33
|
+
# >> > ------------------------------------------------------------ out
|
34
|
+
# >> > ```
|
35
|
+
# >> > foo
|
36
|
+
# >> > ```
|
37
|
+
# >> >
|
38
|
+
# >> > ------------------------------------------------------------
|
39
|
+
# >> ```
|
40
|
+
# >> foo
|
41
|
+
# >> ```
|
@@ -3,23 +3,29 @@ require "./setup"
|
|
3
3
|
|
4
4
|
puts Source2MD::Element.new(<<~EOS).to_md
|
5
5
|
|
6
|
-
#+code_include: input.yml
|
6
|
+
#+code_include: input.yml ruby:abc (AC)
|
7
7
|
#+name:
|
8
8
|
|
9
9
|
EOS
|
10
|
+
# >> head: {"code_include"=>"input.yml ruby:abc (AC)", "name"=>""}
|
11
|
+
# >> body: ""
|
12
|
+
# >> Source2MD::Formatter::TypeHidden => false
|
13
|
+
# >> Source2MD::Formatter::TypeEval =>
|
14
|
+
# >> Source2MD::Formatter::TypeCodeInclude => input.yml ruby:abc (AC)
|
10
15
|
# >> > -------------------------------------------------------------------------------- Source2MD::Formatter::TypeCodeInclude
|
11
|
-
# >> > {"code_include"=>"input.yml", "name"=>""}
|
16
|
+
# >> > {"code_include"=>"input.yml ruby:abc (AC)", "name"=>""}
|
12
17
|
# >> > ------------------------------------------------------------ in
|
13
18
|
# >> >
|
14
19
|
# >> >
|
15
20
|
# >> > ------------------------------------------------------------ out
|
16
|
-
# >> > ```
|
21
|
+
# >> > ```ruby:abc (AC)
|
17
22
|
# >> > ---
|
18
23
|
# >> > one:
|
19
24
|
# >> > foo: 1
|
20
25
|
# >> > ```
|
26
|
+
# >> >
|
21
27
|
# >> > ------------------------------------------------------------
|
22
|
-
# >> ```
|
28
|
+
# >> ```ruby:abc (AC)
|
23
29
|
# >> ---
|
24
30
|
# >> one:
|
25
31
|
# >> foo: 1
|
@@ -0,0 +1,43 @@
|
|
1
|
+
#+hidden: true
|
2
|
+
require "./setup"
|
3
|
+
|
4
|
+
puts Source2MD::Element.new(<<~EOS).to_md
|
5
|
+
# ---
|
6
|
+
# foo: bar
|
7
|
+
# ---
|
8
|
+
EOS
|
9
|
+
|
10
|
+
# >> head: {}
|
11
|
+
# >> body: "# ---\n# foo: bar\n# ---\n"
|
12
|
+
# >> Source2MD::Formatter::TypeHidden => false
|
13
|
+
# >> Source2MD::Formatter::TypeEval =>
|
14
|
+
# >> Source2MD::Formatter::TypeCodeInclude =>
|
15
|
+
# >> Source2MD::Formatter::TypeRawInclude =>
|
16
|
+
# >> Source2MD::Formatter::TypeParseInclude =>
|
17
|
+
# >> Source2MD::Formatter::TypeTitle => false
|
18
|
+
# >> Source2MD::Formatter::TypeWarn =>
|
19
|
+
# >> Source2MD::Formatter::TypeAlert =>
|
20
|
+
# >> Source2MD::Formatter::TypeMethod =>
|
21
|
+
# >> Source2MD::Formatter::TypeTable => false
|
22
|
+
# >> Source2MD::Formatter::TypeSourceBlock => false
|
23
|
+
# >> Source2MD::Formatter::TypeMdHeader => # ---
|
24
|
+
# >> # foo: bar
|
25
|
+
# >> # ---
|
26
|
+
# >>
|
27
|
+
# >> > -------------------------------------------------------------------------------- Source2MD::Formatter::TypeMdHeader
|
28
|
+
# >> > {}
|
29
|
+
# >> > ------------------------------------------------------------ in
|
30
|
+
# >> > # ---
|
31
|
+
# >> > # foo: bar
|
32
|
+
# >> > # ---
|
33
|
+
# >> >
|
34
|
+
# >> >
|
35
|
+
# >> > ------------------------------------------------------------ out
|
36
|
+
# >> > ---
|
37
|
+
# >> > foo: bar
|
38
|
+
# >> > ---
|
39
|
+
# >> >
|
40
|
+
# >> > ------------------------------------------------------------
|
41
|
+
# >> ---
|
42
|
+
# >> foo: bar
|
43
|
+
# >> ---
|
@@ -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
|
@@ -0,0 +1,34 @@
|
|
1
|
+
#+hidden: true
|
2
|
+
require "./setup"
|
3
|
+
|
4
|
+
puts Source2MD::Element.new(<<~EOS).to_md
|
5
|
+
# > foo
|
6
|
+
EOS
|
7
|
+
|
8
|
+
# >> head: {}
|
9
|
+
# >> body: "# > foo\n"
|
10
|
+
# >> Source2MD::Formatter::TypeHidden => false
|
11
|
+
# >> Source2MD::Formatter::TypeEval =>
|
12
|
+
# >> Source2MD::Formatter::TypeCodeInclude =>
|
13
|
+
# >> Source2MD::Formatter::TypeRawInclude =>
|
14
|
+
# >> Source2MD::Formatter::TypeParseInclude =>
|
15
|
+
# >> Source2MD::Formatter::TypeTitle => false
|
16
|
+
# >> Source2MD::Formatter::TypeWarn =>
|
17
|
+
# >> Source2MD::Formatter::TypeAlert =>
|
18
|
+
# >> Source2MD::Formatter::TypeMethod =>
|
19
|
+
# >> Source2MD::Formatter::TypeTable => false
|
20
|
+
# >> Source2MD::Formatter::TypeSourceBlock => false
|
21
|
+
# >> Source2MD::Formatter::TypeMdHeader =>
|
22
|
+
# >> Source2MD::Formatter::TypeCodeBlock => false
|
23
|
+
# >> Source2MD::Formatter::TypeQuote => # > foo
|
24
|
+
# >> > -------------------------------------------------------------------------------- Source2MD::Formatter::TypeQuote
|
25
|
+
# >> > {}
|
26
|
+
# >> > ------------------------------------------------------------ in
|
27
|
+
# >> > # > foo
|
28
|
+
# >> >
|
29
|
+
# >> >
|
30
|
+
# >> > ------------------------------------------------------------ out
|
31
|
+
# >> > > foo
|
32
|
+
# >> >
|
33
|
+
# >> > ------------------------------------------------------------
|
34
|
+
# >> > foo
|
@@ -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
|
+
# >> ```
|
data/lib/source2md/cli.rb
CHANGED
@@ -4,6 +4,7 @@ module Source2MD
|
|
4
4
|
class_option :xmp_out_exclude, type: :boolean, aliases: "-x", default: false
|
5
5
|
class_option :data_block_exclude, type: :boolean, default: false
|
6
6
|
class_option :readonly, type: :boolean, aliases: "-r", default: true
|
7
|
+
class_option :oneline, type: :boolean, aliases: "-1", default: false
|
7
8
|
class_option :lang_default, type: :string, aliases: "-l", default: "ruby"
|
8
9
|
class_option :prefix_re, type: :string
|
9
10
|
class_option :comment_re, type: :string
|
@@ -19,6 +20,7 @@ module Source2MD
|
|
19
20
|
Source2MD.xmp_out_exclude = options[:xmp_out_exclude]
|
20
21
|
Source2MD.data_block_exclude = options[:data_block_exclude]
|
21
22
|
Source2MD.readonly = options[:readonly]
|
23
|
+
Source2MD.oneline = options[:oneline]
|
22
24
|
Source2MD.lang_default = options[:lang_default]
|
23
25
|
|
24
26
|
Source2MD::RE.update do |e|
|
data/lib/source2md/element.rb
CHANGED
@@ -2,7 +2,7 @@ module Source2MD
|
|
2
2
|
class Element
|
3
3
|
PLUGINS = [
|
4
4
|
Formatter::TypeHidden, # #+hidden: true
|
5
|
-
Formatter::TypeEval,
|
5
|
+
Formatter::TypeEval, # #+eval:
|
6
6
|
Formatter::TypeCodeInclude, # #+code_include: path/to/foo.html xml:SAMPLE.xml
|
7
7
|
Formatter::TypeRawInclude, # #+raw_include: path/to/file.txt
|
8
8
|
Formatter::TypeParseInclude, # #+parse_include: path/to/file.txt
|
@@ -12,8 +12,20 @@ module Source2MD
|
|
12
12
|
Formatter::TypeMethod, # #+name: foo
|
13
13
|
Formatter::TypeTable, # # |-
|
14
14
|
Formatter::TypeSourceBlock, # #+BEGIN_SRC
|
15
|
+
|
16
|
+
# Type that just removes the comment and does not wrap it
|
17
|
+
Formatter::TypeMdHeader, # # ---
|
18
|
+
Formatter::TypeCodeBlock, # # ```
|
19
|
+
Formatter::TypeQuote, # # > xxx
|
20
|
+
Formatter::TypeList, # # - xxx or 1. xxx
|
21
|
+
|
22
|
+
# Sentence (automatic wrap)
|
15
23
|
Formatter::TypeText, # # foo
|
24
|
+
|
25
|
+
# Code block without wrapping
|
16
26
|
Formatter::TypePartialCode, # 1 + 2 # => 3
|
27
|
+
|
28
|
+
# If not all match
|
17
29
|
Formatter::TypeElse,
|
18
30
|
]
|
19
31
|
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Source2MD
|
2
|
+
module Formatter
|
3
|
+
class TypeCodeBlock < Base
|
4
|
+
|
5
|
+
# "# ```"
|
6
|
+
def self.regexp
|
7
|
+
%r{#{RE.meta_re}\s+```}
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.accept?(element)
|
11
|
+
element.body.match?(regexp)
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_md
|
15
|
+
element.body.remove(TypeText.regexp)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Source2MD
|
2
|
+
module Formatter
|
3
|
+
class TypeList < Base
|
4
|
+
|
5
|
+
# "# 1. foo"
|
6
|
+
# "# - foo"
|
7
|
+
def self.regexp
|
8
|
+
%r{#{RE.meta_re}\s+(?:\d\.|-)\s+\S+}
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.accept?(element)
|
12
|
+
element.body.match?(regexp)
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_md
|
16
|
+
element.body.remove(TypeText.regexp)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Source2MD
|
2
|
+
module Formatter
|
3
|
+
class TypeMdHeader < Base
|
4
|
+
def self.regexp
|
5
|
+
/#{RE.meta_re} ---\n.* ---\n/m
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.accept?(element)
|
9
|
+
element.body.match(regexp)
|
10
|
+
end
|
11
|
+
|
12
|
+
def to_md
|
13
|
+
element.body.remove(TypeText.regexp)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -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
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Source2MD
|
2
|
+
module Formatter
|
3
|
+
class TypeQuote < Base
|
4
|
+
def self.regexp
|
5
|
+
/#{RE.meta_re}\s+\>\s+\S+/
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.accept?(element)
|
9
|
+
element.body.match(regexp)
|
10
|
+
end
|
11
|
+
|
12
|
+
def to_md
|
13
|
+
element.body.remove(TypeText.regexp)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
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,13 +21,17 @@ 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
|
25
|
-
|
28
|
+
|
29
|
+
case
|
30
|
+
when element.head["oneline"] == "false"
|
31
|
+
when element.head["oneline"] == "true" || Source2MD.oneline
|
26
32
|
s = TextHelper.oneline(s)
|
27
33
|
end
|
34
|
+
|
28
35
|
if element.head["hankaku_kana"] == "true"
|
29
36
|
s = TextHelper.hankaku_kana(s)
|
30
37
|
end
|
@@ -7,7 +7,8 @@ module Source2MD
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def oneline(text)
|
10
|
-
text.
|
10
|
+
text = text.gsub(/?\R/, "? ")
|
11
|
+
text = text.remove(/\R+/)
|
11
12
|
end
|
12
13
|
|
13
14
|
def squish(text)
|
@@ -30,5 +31,9 @@ module Source2MD
|
|
30
31
|
min = text.lines.reject(&:blank?).collect { |e| e.slice(/^\s*/).size }.min
|
31
32
|
text.remove(/^ {#{min}}/)
|
32
33
|
end
|
34
|
+
|
35
|
+
def data_block_exclude(text)
|
36
|
+
text.sub(/^__END__\R.*/m, "")
|
37
|
+
end
|
33
38
|
end
|
34
39
|
end
|
data/lib/source2md/version.rb
CHANGED
data/lib/source2md.rb
CHANGED
@@ -0,0 +1,23 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
module Source2MD
|
4
|
+
describe do
|
5
|
+
it "works" do
|
6
|
+
actual = Element.new(<<~EOS).to_md
|
7
|
+
# ```
|
8
|
+
# foo
|
9
|
+
# ```
|
10
|
+
EOS
|
11
|
+
actual.should == <<~EOS
|
12
|
+
```
|
13
|
+
foo
|
14
|
+
```
|
15
|
+
EOS
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
# >> .
|
20
|
+
# >>
|
21
|
+
# >> Finished in 0.00614 seconds (files took 0.36666 seconds to load)
|
22
|
+
# >> 1 example, 0 failures
|
23
|
+
# >>
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
module Source2MD
|
4
|
+
describe do
|
5
|
+
it "works" do
|
6
|
+
actual = Element.new(<<~EOS).to_md
|
7
|
+
# ---
|
8
|
+
# foo: bar
|
9
|
+
# ---
|
10
|
+
EOS
|
11
|
+
actual.should == <<~EOS
|
12
|
+
---
|
13
|
+
foo: bar
|
14
|
+
---
|
15
|
+
EOS
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
# >> .
|
20
|
+
# >>
|
21
|
+
# >> Finished in 0.00648 seconds (files took 0.35849 seconds to load)
|
22
|
+
# >> 1 example, 0 failures
|
23
|
+
# >>
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
module Source2MD
|
4
|
+
describe do
|
5
|
+
it "works" do
|
6
|
+
actual = Element.new(<<~EOS).to_md
|
7
|
+
# > foo
|
8
|
+
EOS
|
9
|
+
actual.should == <<~EOS
|
10
|
+
> foo
|
11
|
+
EOS
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
# >> .
|
16
|
+
# >>
|
17
|
+
# >> Finished in 0.00637 seconds (files took 0.3615 seconds to load)
|
18
|
+
# >> 1 example, 0 failures
|
19
|
+
# >>
|
@@ -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
@@ -6,6 +6,10 @@ module Source2MD
|
|
6
6
|
assert { TextHelper.blank_lines_squish("A\nB\n\nC\n\n\nD") == "A\nB\n\nC\n\nD" }
|
7
7
|
end
|
8
8
|
|
9
|
+
it "oneline" do
|
10
|
+
assert { TextHelper.oneline("?\nA") == "? A" }
|
11
|
+
end
|
12
|
+
|
9
13
|
it "eol_enter" do
|
10
14
|
assert { TextHelper.eol_enter("A") == "A\n" }
|
11
15
|
assert { TextHelper.eol_enter("A\n\n") == "A\n" }
|
@@ -19,5 +23,9 @@ module Source2MD
|
|
19
23
|
assert { TextHelper.space_prefix_remove(" a\n b\n") == "a\n b\n" }
|
20
24
|
assert { TextHelper.space_prefix_remove(" a\n\n b\n") == "a\n\n b\n" }
|
21
25
|
end
|
26
|
+
|
27
|
+
it "data_block_exclude" do
|
28
|
+
assert { TextHelper.data_block_exclude("(before)\n__END__\n(after)") == "(before)\n" }
|
29
|
+
end
|
22
30
|
end
|
23
31
|
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.17
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Akira Ikeda
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-02-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -175,11 +175,14 @@ files:
|
|
175
175
|
- examples/scanner.rb
|
176
176
|
- examples/setup.rb
|
177
177
|
- examples/type_alert.rb
|
178
|
+
- examples/type_code_block.rb
|
178
179
|
- examples/type_code_include.rb
|
179
180
|
- examples/type_eval.rb
|
180
181
|
- examples/type_hidden.rb
|
182
|
+
- examples/type_md_header.rb
|
181
183
|
- examples/type_method.rb
|
182
184
|
- examples/type_partial_code.rb
|
185
|
+
- examples/type_quote.rb
|
183
186
|
- examples/type_source_block.rb
|
184
187
|
- examples/type_table.rb
|
185
188
|
- examples/type_text.rb
|
@@ -191,14 +194,18 @@ files:
|
|
191
194
|
- lib/source2md/element.rb
|
192
195
|
- lib/source2md/formatter/base.rb
|
193
196
|
- lib/source2md/formatter/type_alert.rb
|
197
|
+
- lib/source2md/formatter/type_code_block.rb
|
194
198
|
- lib/source2md/formatter/type_code_include.rb
|
195
199
|
- lib/source2md/formatter/type_else.rb
|
196
200
|
- lib/source2md/formatter/type_eval.rb
|
197
201
|
- lib/source2md/formatter/type_hidden.rb
|
202
|
+
- lib/source2md/formatter/type_list.rb
|
203
|
+
- lib/source2md/formatter/type_md_header.rb
|
198
204
|
- lib/source2md/formatter/type_method.rb
|
199
205
|
- lib/source2md/formatter/type_nop.rb
|
200
206
|
- lib/source2md/formatter/type_parse_include.rb
|
201
207
|
- lib/source2md/formatter/type_partial_code.rb
|
208
|
+
- lib/source2md/formatter/type_quote.rb
|
202
209
|
- lib/source2md/formatter/type_raw_include.rb
|
203
210
|
- lib/source2md/formatter/type_source_block.rb
|
204
211
|
- lib/source2md/formatter/type_table.rb
|
@@ -219,12 +226,15 @@ files:
|
|
219
226
|
- spec/code_block_spec.rb
|
220
227
|
- spec/formatter/sample.yml
|
221
228
|
- spec/formatter/type_alert_spec.rb
|
229
|
+
- spec/formatter/type_code_block_spec.rb
|
222
230
|
- spec/formatter/type_code_include_spec.rb
|
223
231
|
- spec/formatter/type_eval_spec.rb
|
224
232
|
- spec/formatter/type_hidden_spec.rb
|
233
|
+
- spec/formatter/type_md_header_spec.rb
|
225
234
|
- spec/formatter/type_method_spec.rb
|
226
235
|
- spec/formatter/type_parse_include_spec.rb
|
227
236
|
- spec/formatter/type_partial_code_spec.rb
|
237
|
+
- spec/formatter/type_quote_spec.rb
|
228
238
|
- spec/formatter/type_raw_include_spec.rb
|
229
239
|
- spec/formatter/type_source_block_spec.rb
|
230
240
|
- spec/formatter/type_table_spec.rb
|
@@ -254,7 +264,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
254
264
|
- !ruby/object:Gem::Version
|
255
265
|
version: '0'
|
256
266
|
requirements: []
|
257
|
-
rubygems_version: 3.4
|
267
|
+
rubygems_version: 3.5.4
|
258
268
|
signing_key:
|
259
269
|
specification_version: 4
|
260
270
|
summary: Markdown generator from source code
|
@@ -262,12 +272,15 @@ test_files:
|
|
262
272
|
- spec/code_block_spec.rb
|
263
273
|
- spec/formatter/sample.yml
|
264
274
|
- spec/formatter/type_alert_spec.rb
|
275
|
+
- spec/formatter/type_code_block_spec.rb
|
265
276
|
- spec/formatter/type_code_include_spec.rb
|
266
277
|
- spec/formatter/type_eval_spec.rb
|
267
278
|
- spec/formatter/type_hidden_spec.rb
|
279
|
+
- spec/formatter/type_md_header_spec.rb
|
268
280
|
- spec/formatter/type_method_spec.rb
|
269
281
|
- spec/formatter/type_parse_include_spec.rb
|
270
282
|
- spec/formatter/type_partial_code_spec.rb
|
283
|
+
- spec/formatter/type_quote_spec.rb
|
271
284
|
- spec/formatter/type_raw_include_spec.rb
|
272
285
|
- spec/formatter/type_source_block_spec.rb
|
273
286
|
- spec/formatter/type_table_spec.rb
|