source2md 0.0.15 → 0.0.16

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e6729b84590ef4ebe43528414aa73d6acd79d9171c813c4a8de9acd7148c9115
4
- data.tar.gz: 0b5d54093161840a33b2ce104752883e50e582dda9e7dc925767c83ef6f8ab05
3
+ metadata.gz: f98cf52536b132ac7b8a7ed2b99653c0b1c668c0d3b7bd3681e898854fa00b8a
4
+ data.tar.gz: e78fa6dbddfefd98ee5757ca3f41911568df9825c332e1e1453e0df3ff0d7b7f
5
5
  SHA512:
6
- metadata.gz: 81e2f855af240b3ea35c887f6bb6275eb699702934f62a8f13b86e5c0abfe4dcf0b77e7ffd17d2f17784565da8f92795ee1a35416226813c91269b247b2fe8f5
7
- data.tar.gz: 51272d19c77da2481488acecc3a30eb97b8073ce8e2b1c9264252e0d738974223327f8a30eadc7146feefe20b4e6a76dd63a523b1345f3f149125cb950026678
6
+ metadata.gz: a9844d91a277c17f86037ab84efbf5b1f0bcd627fbb00ef16188f19b0e90716b0d7402644b7b60f5975919d7b194851d762463b93a7a50461e09b1eb5459d95f
7
+ data.tar.gz: 8d18aeff6e37f72c9c18c8187d64a62e9078cd534e280ef4c165a99c973f6bf079a610b57d86d8fe9d2b7abc8143ce7a9acbedbce2f710dcb537467358acddf4
data/.gitignore CHANGED
@@ -2,3 +2,4 @@
2
2
  /*.gem
3
3
  /pkg
4
4
  /spec/.all_test_result.txt
5
+ /*.el
@@ -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 hidden!
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 hidden!
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.sub(/^__END__\R.*/m, "")
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 code_block_desc_keywords.include?("hidden!")
14
+ if option_list.include?("hidden!")
10
15
  return ""
11
16
  end
12
- CodeBlock.new(body, desc: code_block_desc).to_md
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 code_block_desc
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 code_block_desc_keywords
28
- code_block_desc.to_s.split(/\s+/).to_set
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
- REGEXP = %r{#{RE.meta_re}( |$)}
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?(REGEXP) }
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(REGEXP)
24
+ s = element.body.remove(self.class.regexp)
22
25
  if element.head["squish"] == "true"
23
26
  s = TextHelper.squish(s)
24
27
  end
@@ -28,6 +28,7 @@ module Source2MD
28
28
  def reset
29
29
  @meta_re = nil
30
30
  @stdout_re = nil
31
+ @text_prefix_re = nil
31
32
  end
32
33
  end
33
34
  end
@@ -30,5 +30,9 @@ module Source2MD
30
30
  min = text.lines.reject(&:blank?).collect { |e| e.slice(/^\s*/).size }.min
31
31
  text.remove(/^ {#{min}}/)
32
32
  end
33
+
34
+ def data_block_exclude(text)
35
+ text.sub(/^__END__\R.*/m, "")
36
+ end
33
37
  end
34
38
  end
@@ -1,3 +1,3 @@
1
1
  module Source2MD
2
- VERSION = "0.0.15"
2
+ VERSION = "0.0.16"
3
3
  end
@@ -6,6 +6,7 @@ module Source2MD
6
6
  actual = Element.new(<<~EOS).to_md
7
7
  #+partial_code_name: xxx
8
8
  #+partial_code_lang: yyy
9
+ #+data_block_exclude: true
9
10
  (foo)
10
11
  __END__
11
12
  1
@@ -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
@@ -10,7 +10,7 @@ Zeitwerk::Loader.eager_load_all
10
10
 
11
11
  Source2MD.logger.level = :error
12
12
  Source2MD.xmp_out_exclude = true
13
- Source2MD.data_block_exclude = true
13
+ # Source2MD.data_block_exclude = true
14
14
 
15
15
  RSpec.configure do |config|
16
16
  config.expect_with :rspec do |c|
@@ -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.15
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-10 00:00:00.000000000 Z
11
+ date: 2023-12-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport