source2md 0.0.14 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3477e280893742563cabf28b242a48d0efdc0943294c902a0fd7085950213b6a
4
- data.tar.gz: 6a0c6f3b324fe3cd6b6d6e9fd1c038fba91dcbaf3aff742cf8f80ef2129c49a7
3
+ metadata.gz: f98cf52536b132ac7b8a7ed2b99653c0b1c668c0d3b7bd3681e898854fa00b8a
4
+ data.tar.gz: e78fa6dbddfefd98ee5757ca3f41911568df9825c332e1e1453e0df3ff0d7b7f
5
5
  SHA512:
6
- metadata.gz: be3fb7b9ef5f24186a2b613fd10d42d5d0bbad7781d99b9ac72251dda336b13d50737febd993f6d5ecfc0dfe83fb87930c317b3dc21475afe593e1fecea5173b
7
- data.tar.gz: 0e68f783920b8abb32a1e405cecc4f0f881cf9bc71f4b3b2f13fff444b8272b8361d37389f10c4085b55be51c67a439d6ddbc5061bda776a4255797a9ecf1cd3
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
data/README.md CHANGED
@@ -32,7 +32,8 @@ puts Source2MD::Section.new(<<~EOS).to_md
32
32
  "Hello, world!"
33
33
  }
34
34
 
35
- #+code_block_name: (name)
35
+ #+partial_code_name: (name)
36
+ #+partial_code_lang: (ruby)
36
37
  hello.call
37
38
  EOS
38
39
  ```
@@ -43,7 +44,7 @@ EOS
43
44
  > }
44
45
  > ```
45
46
 
46
- > ```ruby:(name)
47
+ > ```(ruby):(name)
47
48
  > hello.call
48
49
  > ```
49
50
 
@@ -316,3 +317,13 @@ EOS
316
317
  ```
317
318
 
318
319
  > foo
320
+
321
+ ### Eval ###
322
+
323
+ Function for changing internal variables
324
+
325
+ ```ruby
326
+ puts Source2MD::Section.new(<<~EOS).to_md
327
+ #+eval: Source2MD.lang_default = "shell"
328
+ EOS
329
+ ```
@@ -11,7 +11,8 @@ puts Source2MD::Section.new(<<~EOS).to_md
11
11
  "Hello, world!"
12
12
  }
13
13
 
14
- #+code_block_name: (name)
14
+ #+partial_code_name: (name)
15
+ #+partial_code_lang: (ruby)
15
16
  hello.call
16
17
  EOS
17
18
  #+END_SRC
@@ -22,7 +23,7 @@ EOS
22
23
  # > }
23
24
  # > ```
24
25
 
25
- # > ```ruby:(name)
26
+ # > ```(ruby):(name)
26
27
  # > hello.call
27
28
  # > ```
28
29
 
@@ -33,6 +34,6 @@ EOS
33
34
  # >> ```
34
35
  # >>
35
36
  # >>
36
- # >> ```ruby:(name)
37
+ # >> ```(ruby):(name)
37
38
  # >> hello.call
38
39
  # >> ```
data/doc/0250_eval.rb ADDED
@@ -0,0 +1,12 @@
1
+ #+hidden: true
2
+ require "./setup"
3
+
4
+ #+title3: Eval
5
+
6
+ # Function for changing internal variables
7
+
8
+ #+BEGIN_SRC
9
+ puts Source2MD::Section.new(<<~EOS).to_md
10
+ #+eval: Source2MD.lang_default = "shell"
11
+ EOS
12
+ #+END_SRC
@@ -0,0 +1,18 @@
1
+ #+hidden: true
2
+ require "./setup"
3
+
4
+ puts Source2MD::Element.new(<<~EOS).to_md
5
+ #+eval: Source2MD.lang_default = "lisp"
6
+ EOS
7
+ # >> head: {"eval"=>"Source2MD.lang_default = \"lisp\""}
8
+ # >> body: ""
9
+ # >> Source2MD::Formatter::TypeEval => Source2MD.lang_default = "lisp"
10
+ # >> > -------------------------------------------------------------------------------- Source2MD::Formatter::TypeEval
11
+ # >> > {"eval"=>"Source2MD.lang_default = \"lisp\""}
12
+ # >> > ------------------------------------------------------------ in
13
+ # >> >
14
+ # >> >
15
+ # >> > ------------------------------------------------------------ out
16
+ # >> >
17
+ # >> > ------------------------------------------------------------
18
+ # >>
@@ -4,16 +4,18 @@ require "./setup"
4
4
  Source2MD.data_block_exclude = true
5
5
 
6
6
  puts Source2MD::Element.new(<<~EOS).to_md
7
- #+code_block_name: foo
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: {"code_block_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
- # >> > {"code_block_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
+ # >> ```
data/lib/source2md/cli.rb CHANGED
@@ -4,7 +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 :default_lang, type: :string, aliases: "-l", default: "ruby"
7
+ class_option :lang_default, type: :string, aliases: "-l", default: "ruby"
8
8
  class_option :prefix_re, type: :string
9
9
  class_option :comment_re, type: :string
10
10
 
@@ -19,7 +19,7 @@ module Source2MD
19
19
  Source2MD.xmp_out_exclude = options[:xmp_out_exclude]
20
20
  Source2MD.data_block_exclude = options[:data_block_exclude]
21
21
  Source2MD.readonly = options[:readonly]
22
- Source2MD.default_lang = options[:default_lang]
22
+ Source2MD.lang_default = options[:lang_default]
23
23
 
24
24
  Source2MD::RE.update do |e|
25
25
  if v = options[:prefix_re]
@@ -6,7 +6,9 @@ module Source2MD
6
6
  def initialize(text, options = {})
7
7
  @text = text
8
8
  @options = {
9
+ :desc => nil,
9
10
  :lang => nil,
11
+ :name => nil,
10
12
  # :single_sharp_replace_to_blank_line => false,
11
13
  }.merge(options)
12
14
  end
@@ -21,6 +23,8 @@ module Source2MD
21
23
 
22
24
  private
23
25
 
26
+ # <-------------------> desc
27
+ # <- lang ->:<- name ->
24
28
  def code_block_head
25
29
  o = []
26
30
  if s = @options[:desc]
@@ -78,7 +82,7 @@ module Source2MD
78
82
  end
79
83
 
80
84
  def lang
81
- @options[:lang] || ENV["DEFAULT_LANG"] || Source2MD.default_lang
85
+ @options[:lang] || ENV["DEFAULT_LANG"] || Source2MD.lang_default
82
86
  end
83
87
  end
84
88
  end
@@ -2,6 +2,7 @@ module Source2MD
2
2
  class Element
3
3
  PLUGINS = [
4
4
  Formatter::TypeHidden, # #+hidden: true
5
+ Formatter::TypeEval, # #+eval:
5
6
  Formatter::TypeCodeInclude, # #+code_include: path/to/foo.html xml:SAMPLE.xml
6
7
  Formatter::TypeRawInclude, # #+raw_include: path/to/file.txt
7
8
  Formatter::TypeParseInclude, # #+parse_include: path/to/file.txt
@@ -0,0 +1,14 @@
1
+ module Source2MD
2
+ module Formatter
3
+ class TypeEval < Base
4
+ def self.accept?(element)
5
+ element.head["eval"]
6
+ end
7
+
8
+ def to_md
9
+ eval(element.head["eval"])
10
+ ""
11
+ end
12
+ end
13
+ end
14
+ end
@@ -6,18 +6,26 @@ module Source2MD
6
6
  end
7
7
 
8
8
  def to_md
9
- CodeBlock.new(body, name: element.head["code_block_name"]).to_md
9
+ CodeBlock.new(body, code_block_options).to_md
10
10
  end
11
11
 
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
20
20
  end
21
+
22
+ def code_block_options
23
+ {
24
+ lang: element.head["partial_code_lang"],
25
+ name: element.head["partial_code_name"],
26
+ desc: element.head["partial_code_desc"],
27
+ }
28
+ end
21
29
  end
22
30
  end
23
31
  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.14"
2
+ VERSION = "0.0.16"
3
3
  end
data/lib/source2md.rb CHANGED
@@ -15,7 +15,7 @@ module Source2MD
15
15
  config_accessor(:debug) { false }
16
16
  config_accessor(:xmp_out_exclude) { false }
17
17
  config_accessor(:readonly) { true }
18
- config_accessor(:default_lang) { "ruby" }
18
+ config_accessor(:lang_default) { "ruby" }
19
19
  config_accessor(:data_block_exclude) { false }
20
20
  end
21
21
 
@@ -0,0 +1,16 @@
1
+ require "spec_helper"
2
+
3
+ module Source2MD
4
+ describe do
5
+ it "works" do
6
+ actual = Element.new(<<~EOS).to_md
7
+ #+eval: 1 + 2
8
+ EOS
9
+ end
10
+ end
11
+ end
12
+ # >> .
13
+ # >>
14
+ # >> Finished in 0.00398 seconds (files took 0.34568 seconds to load)
15
+ # >> 1 example, 0 failures
16
+ # >>
@@ -4,14 +4,16 @@ module Source2MD
4
4
  describe do
5
5
  it "works" do
6
6
  actual = Element.new(<<~EOS).to_md
7
- #+code_block_name: xxx
7
+ #+partial_code_name: xxx
8
+ #+partial_code_lang: yyy
9
+ #+data_block_exclude: true
8
10
  (foo)
9
11
  __END__
10
12
  1
11
13
  2
12
14
  EOS
13
15
  actual.should == <<~EOS
14
- ```ruby:xxx
16
+ ```yyy:xxx
15
17
  (foo)
16
18
  ```
17
19
  EOS
@@ -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.14
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-10-24 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
@@ -163,6 +163,7 @@ files:
163
163
  - doc/0220_text_squish.rb
164
164
  - doc/0230_text_hankaku_kana.rb
165
165
  - doc/0240_parse_include.rb
166
+ - doc/0250_eval.rb
166
167
  - doc/setup.rb
167
168
  - examples/cli-test.rs
168
169
  - examples/cli-test.sh
@@ -175,6 +176,7 @@ files:
175
176
  - examples/setup.rb
176
177
  - examples/type_alert.rb
177
178
  - examples/type_code_include.rb
179
+ - examples/type_eval.rb
178
180
  - examples/type_hidden.rb
179
181
  - examples/type_method.rb
180
182
  - examples/type_partial_code.rb
@@ -191,6 +193,7 @@ files:
191
193
  - lib/source2md/formatter/type_alert.rb
192
194
  - lib/source2md/formatter/type_code_include.rb
193
195
  - lib/source2md/formatter/type_else.rb
196
+ - lib/source2md/formatter/type_eval.rb
194
197
  - lib/source2md/formatter/type_hidden.rb
195
198
  - lib/source2md/formatter/type_method.rb
196
199
  - lib/source2md/formatter/type_nop.rb
@@ -217,6 +220,7 @@ files:
217
220
  - spec/formatter/sample.yml
218
221
  - spec/formatter/type_alert_spec.rb
219
222
  - spec/formatter/type_code_include_spec.rb
223
+ - spec/formatter/type_eval_spec.rb
220
224
  - spec/formatter/type_hidden_spec.rb
221
225
  - spec/formatter/type_method_spec.rb
222
226
  - spec/formatter/type_parse_include_spec.rb
@@ -250,7 +254,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
250
254
  - !ruby/object:Gem::Version
251
255
  version: '0'
252
256
  requirements: []
253
- rubygems_version: 3.4.20
257
+ rubygems_version: 3.4.22
254
258
  signing_key:
255
259
  specification_version: 4
256
260
  summary: Markdown generator from source code
@@ -259,6 +263,7 @@ test_files:
259
263
  - spec/formatter/sample.yml
260
264
  - spec/formatter/type_alert_spec.rb
261
265
  - spec/formatter/type_code_include_spec.rb
266
+ - spec/formatter/type_eval_spec.rb
262
267
  - spec/formatter/type_hidden_spec.rb
263
268
  - spec/formatter/type_method_spec.rb
264
269
  - spec/formatter/type_parse_include_spec.rb