source2md 0.0.13 → 0.0.15

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: 563959d92fa1520a3e09544319ff3eb9a50ac0136cc68edb290b98dc6d005e4e
4
- data.tar.gz: 895fe538bd66ae956f5892b8278a4f7936140e78e07231d2cab7e6d926834b78
3
+ metadata.gz: e6729b84590ef4ebe43528414aa73d6acd79d9171c813c4a8de9acd7148c9115
4
+ data.tar.gz: 0b5d54093161840a33b2ce104752883e50e582dda9e7dc925767c83ef6f8ab05
5
5
  SHA512:
6
- metadata.gz: 83fc8fd71c70f95f3ccdb05b3119ea21dd6a09df913b58b254783189fefd2a370bdffd4d9becf77285ab2c7594a95b8529271f6b1587e94977ee023e4ebffbfb
7
- data.tar.gz: 02d4b91d972ce7aeffb30dcd9af76001bbf2d2385e2082cc0db4e0e71d1e6e043930e404651dcff5e63606955b97c28b04d8d2f7b8b34963dd1426ca407528fe
6
+ metadata.gz: 81e2f855af240b3ea35c887f6bb6275eb699702934f62a8f13b86e5c0abfe4dcf0b77e7ffd17d2f17784565da8f92795ee1a35416226813c91269b247b2fe8f5
7
+ data.tar.gz: 51272d19c77da2481488acecc3a30eb97b8073ce8e2b1c9264252e0d738974223327f8a30eadc7146feefe20b4e6a76dd63a523b1345f3f149125cb950026678
data/README.md CHANGED
@@ -32,6 +32,8 @@ puts Source2MD::Section.new(<<~EOS).to_md
32
32
  "Hello, world!"
33
33
  }
34
34
 
35
+ #+partial_code_name: (name)
36
+ #+partial_code_lang: (ruby)
35
37
  hello.call
36
38
  EOS
37
39
  ```
@@ -42,7 +44,7 @@ EOS
42
44
  > }
43
45
  > ```
44
46
 
45
- > ```ruby
47
+ > ```(ruby):(name)
46
48
  > hello.call
47
49
  > ```
48
50
 
@@ -315,3 +317,13 @@ EOS
315
317
  ```
316
318
 
317
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,6 +11,8 @@ puts Source2MD::Section.new(<<~EOS).to_md
11
11
  "Hello, world!"
12
12
  }
13
13
 
14
+ #+partial_code_name: (name)
15
+ #+partial_code_lang: (ruby)
14
16
  hello.call
15
17
  EOS
16
18
  #+END_SRC
@@ -21,9 +23,10 @@ EOS
21
23
  # > }
22
24
  # > ```
23
25
 
24
- # > ```ruby
26
+ # > ```(ruby):(name)
25
27
  # > hello.call
26
28
  # > ```
29
+
27
30
  # >> ```ruby
28
31
  # >> hello = -> {
29
32
  # >> "Hello, world!"
@@ -31,6 +34,6 @@ EOS
31
34
  # >> ```
32
35
  # >>
33
36
  # >>
34
- # >> ```ruby
37
+ # >> ```(ruby):(name)
35
38
  # >> hello.call
36
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,13 +4,14 @@ require "./setup"
4
4
  Source2MD.data_block_exclude = true
5
5
 
6
6
  puts Source2MD::Element.new(<<~EOS).to_md
7
+ #+partial_code_name: foo
7
8
  a
8
9
  b
9
10
  c
10
11
  __END__
11
12
  foo
12
13
  EOS
13
- # >> head: {}
14
+ # >> head: {"partial_code_name"=>"foo"}
14
15
  # >> body: "a\n b\nc\n__END__\nfoo\n"
15
16
  # >> Source2MD::Formatter::TypeHidden => false
16
17
  # >> Source2MD::Formatter::TypeCodeInclude =>
@@ -25,7 +26,7 @@ EOS
25
26
  # >> Source2MD::Formatter::TypeText => false
26
27
  # >> Source2MD::Formatter::TypePartialCode => true
27
28
  # >> > -------------------------------------------------------------------------------- Source2MD::Formatter::TypePartialCode
28
- # >> > {}
29
+ # >> > {"partial_code_name"=>"foo"}
29
30
  # >> > ------------------------------------------------------------ in
30
31
  # >> > a
31
32
  # >> > b
@@ -35,14 +36,14 @@ EOS
35
36
  # >> >
36
37
  # >> >
37
38
  # >> > ------------------------------------------------------------ out
38
- # >> > ```ruby
39
+ # >> > ```ruby:foo
39
40
  # >> > a
40
41
  # >> > b
41
42
  # >> > c
42
43
  # >> > ```
43
44
  # >> >
44
45
  # >> > ------------------------------------------------------------
45
- # >> ```ruby
46
+ # >> ```ruby:foo
46
47
  # >> a
47
48
  # >> b
48
49
  # >> c
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,7 +6,7 @@ module Source2MD
6
6
  end
7
7
 
8
8
  def to_md
9
- CodeBlock.new(body).to_md
9
+ CodeBlock.new(body, code_block_options).to_md
10
10
  end
11
11
 
12
12
  private
@@ -18,6 +18,14 @@ module Source2MD
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,3 +1,3 @@
1
1
  module Source2MD
2
- VERSION = "0.0.13"
2
+ VERSION = "0.0.15"
3
3
  end
data/lib/source2md.rb CHANGED
@@ -1,5 +1,5 @@
1
+ require "active_support"
1
2
  require "active_support/logger"
2
- require "active_support/isolated_execution_state"
3
3
 
4
4
  require "active_support/core_ext/hash"
5
5
  require "active_support/core_ext/string"
@@ -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,13 +4,15 @@ module Source2MD
4
4
  describe do
5
5
  it "works" do
6
6
  actual = Element.new(<<~EOS).to_md
7
+ #+partial_code_name: xxx
8
+ #+partial_code_lang: yyy
7
9
  (foo)
8
10
  __END__
9
11
  1
10
12
  2
11
13
  EOS
12
14
  actual.should == <<~EOS
13
- ```ruby
15
+ ```yyy:xxx
14
16
  (foo)
15
17
  ```
16
18
  EOS
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.13
4
+ version: 0.0.15
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-02 00:00:00.000000000 Z
11
+ date: 2023-11-10 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.19
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