source2md 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +0 -6
- data/doc/0130_hidden.rb +7 -5
- data/examples/type_code_include.rb +17 -12
- data/examples/type_source_block.rb +11 -21
- data/lib/source2md/formatter/type_source_block.rb +7 -0
- data/lib/source2md/scanner.rb +11 -11
- data/lib/source2md/version.rb +1 -1
- data/spec/formatter/type_source_block_spec.rb +9 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 45ea284efbf369a44f443d19ad9efef483c50d71b7d0a6a3061e22fd0a844ab4
|
4
|
+
data.tar.gz: f5e5ae8ac1275e92d6a09161f6561e3ca3ed39e13b821d69a3b5ceae53d23467
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9b801b23ca8be860c0f76bbc6e3184b79ee9872b424108b83598dc23362667e00c21eb857c2995698addee97f85bd2995dc421b4f2d6dadd871e7f3db80eb6d0
|
7
|
+
data.tar.gz: 4972b72106e655da9078ce8962eb4bd32fbecccd520c1d7d0bd24b7e1029b6d9fa1aa2775ce9b9a4a980fd7af9d373d35be8c1666d67868eb1a04d5589f036cf
|
data/README.md
CHANGED
@@ -72,15 +72,9 @@ 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
80
|
```ruby
|
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
|
@@ -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
|
-
# >> ```
|
@@ -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
|
data/lib/source2md/scanner.rb
CHANGED
@@ -1,19 +1,19 @@
|
|
1
1
|
module Source2MD
|
2
2
|
class Scanner
|
3
|
-
SEPARATOR
|
3
|
+
SEPARATOR = "\\R{2,}"
|
4
4
|
|
5
|
-
#
|
5
|
+
# MD_CODE_BLOCK_RE = /^# ```.*?^# ```/m
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
SRC_BEGIN_KEY = "BEGIN_SRC"
|
8
|
+
SRC_END_KEY = "END_SRC"
|
9
|
+
SRC_BLOCK_RE = /^#\+#{SRC_BEGIN_KEY}.*?^#\+#{SRC_END_KEY}/m
|
10
10
|
|
11
|
-
|
11
|
+
NORMAL_BLOCK_RE = /.*?#{SEPARATOR}/m
|
12
12
|
|
13
|
-
|
14
|
-
#
|
15
|
-
|
16
|
-
|
13
|
+
PARAGRAPH_RE = Regexp.union [
|
14
|
+
# MD_CODE_BLOCK_RE,
|
15
|
+
SRC_BLOCK_RE,
|
16
|
+
NORMAL_BLOCK_RE,
|
17
17
|
]
|
18
18
|
|
19
19
|
def initialize(content)
|
@@ -26,7 +26,7 @@ module Source2MD
|
|
26
26
|
v = v.remove(/^# >>.*$/)
|
27
27
|
end
|
28
28
|
v = v + "\n\n"
|
29
|
-
v = v.scan(
|
29
|
+
v = v.scan(PARAGRAPH_RE)
|
30
30
|
v = v.collect(&:strip)
|
31
31
|
v = v.find_all(&:present?)
|
32
32
|
end
|
data/lib/source2md/version.rb
CHANGED