source2md 0.0.17 → 0.0.19

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: 2d239ae5a48c121dc61a4fcd811cf6572f32b1ee793bae58a2a6c69f4e815d0f
4
- data.tar.gz: 748a3da2af4129d894031af00b71b0e4553e4a21018b84a2d12e0f646ab1ce12
3
+ metadata.gz: 27633f0c0b343c08b59225c30971fbcd2f70c8685c64f46aba8c7ee64827aeaf
4
+ data.tar.gz: f9e85e2afe2374c0b13a08369f279cd45cb0592746fca19d0ba3691a08c57977
5
5
  SHA512:
6
- metadata.gz: 4fa15b238f101e8da2f2f2f8a997e98697c032af2b6674b7896ae7ce0b325f695e213c1b321b8989bc58a9a448bc9d030dccd0251b2473f738ac5e0a0e920957
7
- data.tar.gz: a7d8ca07d2bd122437b711b9ce90387783e1d96a560b422c1c83cd745f062656c4ab0cde8239532c611fb898fcb7d98396bd3d447975b558e93713bf85cd2d4d
6
+ metadata.gz: 1d75891ce8bb4c77cec87c2f0d1390077ffe34970c24fe20acb563f72ebbd36ec7a5c05d5ebe5c84cc2646b543554b88f67ba4850304a5451e0c0101b6438cb8
7
+ data.tar.gz: de15373bb4c11f0cca950b9d0b1ab0f3f83162a3548681aeddae124281c9adacc6698b8669e842f90ba6bb56effd51fab7ee51b8b83378e803c6f3c9d02c7690
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ # require "~/src/zenn/lib/default_task"
2
+
1
3
  require "bundler/gem_tasks"
2
4
 
3
5
  Pathname.glob("lib/source2md/tasks/**/*.rake").each { |file| load(file) }
@@ -0,0 +1,40 @@
1
+ #+hidden: true
2
+ require "./setup"
3
+
4
+ puts Source2MD::Element.new(<<~EOS).to_md
5
+ # ![](https://example.com/image.png)
6
+ # *(alt)*
7
+ EOS
8
+
9
+ # >> head: {}
10
+ # >> body: "# ![](https://example.com/image.png)\n# *(alt)*\n"
11
+ # >> Source2MD::Formatter::TypeHidden => false
12
+ # >> Source2MD::Formatter::TypeEval =>
13
+ # >> Source2MD::Formatter::TypeCodeInclude =>
14
+ # >> Source2MD::Formatter::TypeRawInclude =>
15
+ # >> Source2MD::Formatter::TypeParseInclude =>
16
+ # >> Source2MD::Formatter::TypeTitle => false
17
+ # >> Source2MD::Formatter::TypeWarn =>
18
+ # >> Source2MD::Formatter::TypeAlert =>
19
+ # >> Source2MD::Formatter::TypeMethod =>
20
+ # >> Source2MD::Formatter::TypeTable => false
21
+ # >> Source2MD::Formatter::TypeSourceBlock => false
22
+ # >> Source2MD::Formatter::TypeMdHeader =>
23
+ # >> Source2MD::Formatter::TypeCodeBlock => false
24
+ # >> Source2MD::Formatter::TypeQuote =>
25
+ # >> Source2MD::Formatter::TypeList => false
26
+ # >> Source2MD::Formatter::TypeInlineImage => # ![]
27
+ # >> > -------------------------------------------------------------------------------- Source2MD::Formatter::TypeInlineImage
28
+ # >> > {}
29
+ # >> > ------------------------------------------------------------ in
30
+ # >> > # ![](https://example.com/image.png)
31
+ # >> > # *(alt)*
32
+ # >> >
33
+ # >> >
34
+ # >> > ------------------------------------------------------------ out
35
+ # >> > ![](https://example.com/image.png)
36
+ # >> > *(alt)*
37
+ # >> >
38
+ # >> > ------------------------------------------------------------
39
+ # >> ![](https://example.com/image.png)
40
+ # >> *(alt)*
@@ -0,0 +1,39 @@
1
+ #+hidden: true
2
+ require "./setup"
3
+
4
+ puts Source2MD::Element.new(<<~EOS).to_md
5
+ # - a
6
+ # - b
7
+ EOS
8
+
9
+ # >> head: {}
10
+ # >> body: "# - a\n# - b\n"
11
+ # >> Source2MD::Formatter::TypeHidden => false
12
+ # >> Source2MD::Formatter::TypeEval =>
13
+ # >> Source2MD::Formatter::TypeCodeInclude =>
14
+ # >> Source2MD::Formatter::TypeRawInclude =>
15
+ # >> Source2MD::Formatter::TypeParseInclude =>
16
+ # >> Source2MD::Formatter::TypeTitle => false
17
+ # >> Source2MD::Formatter::TypeWarn =>
18
+ # >> Source2MD::Formatter::TypeAlert =>
19
+ # >> Source2MD::Formatter::TypeMethod =>
20
+ # >> Source2MD::Formatter::TypeTable => false
21
+ # >> Source2MD::Formatter::TypeSourceBlock => false
22
+ # >> Source2MD::Formatter::TypeMdHeader =>
23
+ # >> Source2MD::Formatter::TypeCodeBlock => false
24
+ # >> Source2MD::Formatter::TypeQuote =>
25
+ # >> Source2MD::Formatter::TypeList => true
26
+ # >> > -------------------------------------------------------------------------------- Source2MD::Formatter::TypeList
27
+ # >> > {}
28
+ # >> > ------------------------------------------------------------ in
29
+ # >> > # - a
30
+ # >> > # - b
31
+ # >> >
32
+ # >> >
33
+ # >> > ------------------------------------------------------------ out
34
+ # >> > - a
35
+ # >> > - b
36
+ # >> >
37
+ # >> > ------------------------------------------------------------
38
+ # >> - a
39
+ # >> - b
@@ -0,0 +1,41 @@
1
+ #+hidden: true
2
+ require "./setup"
3
+ Source2MD.oneline = true
4
+
5
+ puts Source2MD::Element.new(<<~EOS).to_md
6
+ # http://
7
+ # http://
8
+ EOS
9
+
10
+ # >> head: {}
11
+ # >> body: "# http://\n# http://\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 => false
25
+ # >> Source2MD::Formatter::TypeQuote =>
26
+ # >> Source2MD::Formatter::TypeList => false
27
+ # >> Source2MD::Formatter::TypeUrlList => true
28
+ # >> > -------------------------------------------------------------------------------- Source2MD::Formatter::TypeUrlList
29
+ # >> > {}
30
+ # >> > ------------------------------------------------------------ in
31
+ # >> > # http://
32
+ # >> > # http://
33
+ # >> >
34
+ # >> >
35
+ # >> > ------------------------------------------------------------ out
36
+ # >> > http://
37
+ # >> > http://
38
+ # >> >
39
+ # >> > ------------------------------------------------------------
40
+ # >> http://
41
+ # >> http://
data/lib/source2md/cli.rb CHANGED
@@ -1,10 +1,10 @@
1
1
  module Source2MD
2
2
  class Cli < Thor
3
3
  class_option :debug, type: :boolean, aliases: "-d", default: false
4
- class_option :xmp_out_exclude, type: :boolean, aliases: "-x", default: false
5
- class_option :data_block_exclude, type: :boolean, default: false
4
+ class_option :xmp_out_exclude, type: :boolean, aliases: "-x", default: true
5
+ class_option :data_block_exclude, type: :boolean, default: true
6
6
  class_option :readonly, type: :boolean, aliases: "-r", default: true
7
- class_option :oneline, type: :boolean, aliases: "-1", default: false
7
+ class_option :oneline, type: :boolean, aliases: "-1", default: true
8
8
  class_option :lang_default, type: :string, aliases: "-l", default: "ruby"
9
9
  class_option :prefix_re, type: :string
10
10
  class_option :comment_re, type: :string
@@ -18,6 +18,8 @@ module Source2MD
18
18
  Formatter::TypeCodeBlock, # # ```
19
19
  Formatter::TypeQuote, # # > xxx
20
20
  Formatter::TypeList, # # - xxx or 1. xxx
21
+ Formatter::TypeUrlList, # # http.*
22
+ Formatter::TypeInlineImage, # # ![]
21
23
 
22
24
  # Sentence (automatic wrap)
23
25
  Formatter::TypeText, # # foo
@@ -0,0 +1,17 @@
1
+ module Source2MD
2
+ module Formatter
3
+ class TypeInlineImage < Base
4
+ def self.regexp
5
+ /#{RE.meta_re}\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
@@ -47,7 +47,18 @@ module Source2MD
47
47
  end
48
48
 
49
49
  def clean_descs
50
- option_list - OPTION_KEYS
50
+ lang_default_add(option_list - OPTION_KEYS)
51
+ end
52
+
53
+ # :yyy -> xxx:yyy
54
+ def lang_default_add(list)
55
+ list.collect do |e|
56
+ if e.start_with?(":")
57
+ Source2MD.lang_default + e
58
+ else
59
+ e
60
+ end
61
+ end
51
62
  end
52
63
  end
53
64
  end
@@ -0,0 +1,21 @@
1
+ module Source2MD
2
+ module Formatter
3
+ class TypeUrlList < Base
4
+
5
+ # "# http.*"
6
+ def self.regexp
7
+ %r{#{RE.meta_re}\s+(?:http)}
8
+ end
9
+
10
+ def self.accept?(element)
11
+ if element.body.present?
12
+ element.body.lines.all? { |e| e.match?(regexp) }
13
+ end
14
+ end
15
+
16
+ def to_md
17
+ element.body.remove(TypeText.regexp)
18
+ end
19
+ end
20
+ end
21
+ end
@@ -1,3 +1,3 @@
1
1
  module Source2MD
2
- VERSION = "0.0.17"
2
+ VERSION = "0.0.19"
3
3
  end
data/lib/source2md.rb CHANGED
@@ -17,7 +17,7 @@ module Source2MD
17
17
  config_accessor(:readonly) { true }
18
18
  config_accessor(:lang_default) { "ruby" }
19
19
  config_accessor(:data_block_exclude) { false }
20
- config_accessor(:oneline) { false }
20
+ config_accessor(:oneline) { true }
21
21
  end
22
22
 
23
23
  require "zeitwerk"
@@ -0,0 +1,21 @@
1
+ require "spec_helper"
2
+
3
+ module Source2MD
4
+ describe do
5
+ it "works" do
6
+ actual = Element.new(<<~EOS).to_md
7
+ # ![](https://example.com/image.png)
8
+ # *(alt)*
9
+ EOS
10
+ actual.should == <<~EOS
11
+ ![](https://example.com/image.png)
12
+ *(alt)*
13
+ EOS
14
+ end
15
+ end
16
+ end
17
+ # >> .
18
+ # >>
19
+ # >> Finished in 0.00592 seconds (files took 0.33715 seconds to load)
20
+ # >> 1 example, 0 failures
21
+ # >>
@@ -0,0 +1,21 @@
1
+ require "spec_helper"
2
+
3
+ module Source2MD
4
+ describe do
5
+ it "works" do
6
+ actual = Element.new(<<~EOS).to_md
7
+ # - a
8
+ # - b
9
+ EOS
10
+ actual.should == <<~EOS
11
+ - a
12
+ - b
13
+ EOS
14
+ end
15
+ end
16
+ end
17
+ # >> .
18
+ # >>
19
+ # >> Finished in 0.00671 seconds (files took 0.42211 seconds to load)
20
+ # >> 1 example, 0 failures
21
+ # >>
@@ -28,6 +28,19 @@ module Source2MD
28
28
  EOS
29
29
  end
30
30
 
31
+ it "works" do
32
+ actual = Element.new(<<~EOS).to_md
33
+ #+BEGIN_SRC :yyy
34
+ (foo)
35
+ #+END_SRC
36
+ EOS
37
+ actual.should == <<~EOS
38
+ ```ruby:yyy
39
+ (foo)
40
+ ```
41
+ EOS
42
+ end
43
+
31
44
  it "works" do
32
45
  actual = Element.new(<<~EOS).to_md
33
46
  #+BEGIN_SRC diff xxx:yyy hidden!
@@ -54,12 +67,12 @@ module Source2MD
54
67
  end
55
68
  end
56
69
  # >> ...F
57
- # >>
70
+ # >>
58
71
  # >> Failures:
59
- # >>
72
+ # >>
60
73
  # >> 1) works
61
74
  # >> Failure/Error: Unable to find - to read failed line
62
- # >>
75
+ # >>
63
76
  # >> expected: ""
64
77
  # >> got: "```xxx:yyy data_block_exclude\n```\n" (using ==)
65
78
  # >> Diff:
@@ -67,11 +80,11 @@ end
67
80
  # >> +```xxx:yyy data_block_exclude
68
81
  # >> +```
69
82
  # >> # -:47:in `block (2 levels) in <module:Source2MD>'
70
- # >>
83
+ # >>
71
84
  # >> Finished in 0.01747 seconds (files took 0.33507 seconds to load)
72
85
  # >> 4 examples, 1 failure
73
- # >>
86
+ # >>
74
87
  # >> Failed examples:
75
- # >>
88
+ # >>
76
89
  # >> rspec -:40 # works
77
- # >>
90
+ # >>
@@ -49,5 +49,21 @@ EOS
49
49
  EOS
50
50
  actual.should == "アア\n"
51
51
  end
52
+
53
+ it "http" do
54
+ actual = Element.new(<<~EOS).to_md
55
+ # http://
56
+ # http://
57
+ EOS
58
+ actual.should == <<~EOS
59
+ http://
60
+ http://
61
+ EOS
62
+ end
52
63
  end
53
64
  end
65
+ # >> .....
66
+ # >>
67
+ # >> Finished in 0.00713 seconds (files took 0.33822 seconds to load)
68
+ # >> 5 examples, 0 failures
69
+ # >>
@@ -0,0 +1,21 @@
1
+ require "spec_helper"
2
+
3
+ module Source2MD
4
+ describe do
5
+ it "works" do
6
+ actual = Element.new(<<~EOS).to_md
7
+ # http://
8
+ # http://
9
+ EOS
10
+ actual.should == <<~EOS
11
+ http://
12
+ http://
13
+ EOS
14
+ end
15
+ end
16
+ end
17
+ # >> .
18
+ # >>
19
+ # >> Finished in 0.0059 seconds (files took 0.34597 seconds to load)
20
+ # >> 1 example, 0 failures
21
+ # >>
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.17
4
+ version: 0.0.19
5
5
  platform: ruby
6
6
  authors:
7
7
  - Akira Ikeda
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-02-02 00:00:00.000000000 Z
11
+ date: 2024-04-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -179,6 +179,8 @@ files:
179
179
  - examples/type_code_include.rb
180
180
  - examples/type_eval.rb
181
181
  - examples/type_hidden.rb
182
+ - examples/type_inline_image.rb
183
+ - examples/type_list.rb
182
184
  - examples/type_md_header.rb
183
185
  - examples/type_method.rb
184
186
  - examples/type_partial_code.rb
@@ -187,6 +189,7 @@ files:
187
189
  - examples/type_table.rb
188
190
  - examples/type_text.rb
189
191
  - examples/type_title.rb
192
+ - examples/type_url_list.rb
190
193
  - examples/type_warn.rb
191
194
  - lib/source2md.rb
192
195
  - lib/source2md/cli.rb
@@ -199,6 +202,7 @@ files:
199
202
  - lib/source2md/formatter/type_else.rb
200
203
  - lib/source2md/formatter/type_eval.rb
201
204
  - lib/source2md/formatter/type_hidden.rb
205
+ - lib/source2md/formatter/type_inline_image.rb
202
206
  - lib/source2md/formatter/type_list.rb
203
207
  - lib/source2md/formatter/type_md_header.rb
204
208
  - lib/source2md/formatter/type_method.rb
@@ -211,6 +215,7 @@ files:
211
215
  - lib/source2md/formatter/type_table.rb
212
216
  - lib/source2md/formatter/type_text.rb
213
217
  - lib/source2md/formatter/type_title.rb
218
+ - lib/source2md/formatter/type_url_list.rb
214
219
  - lib/source2md/formatter/type_warn.rb
215
220
  - lib/source2md/generator.rb
216
221
  - lib/source2md/logger.rb
@@ -230,6 +235,8 @@ files:
230
235
  - spec/formatter/type_code_include_spec.rb
231
236
  - spec/formatter/type_eval_spec.rb
232
237
  - spec/formatter/type_hidden_spec.rb
238
+ - spec/formatter/type_inline_image_spec.rb
239
+ - spec/formatter/type_list_spec.rb
233
240
  - spec/formatter/type_md_header_spec.rb
234
241
  - spec/formatter/type_method_spec.rb
235
242
  - spec/formatter/type_parse_include_spec.rb
@@ -240,6 +247,7 @@ files:
240
247
  - spec/formatter/type_table_spec.rb
241
248
  - spec/formatter/type_text_spec.rb
242
249
  - spec/formatter/type_title_spec.rb
250
+ - spec/formatter/type_url_list_spec.rb
243
251
  - spec/formatter/type_warn_spec.rb
244
252
  - spec/generator_spec.rb
245
253
  - spec/scanner_spec.rb
@@ -264,7 +272,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
264
272
  - !ruby/object:Gem::Version
265
273
  version: '0'
266
274
  requirements: []
267
- rubygems_version: 3.5.4
275
+ rubygems_version: 3.5.9
268
276
  signing_key:
269
277
  specification_version: 4
270
278
  summary: Markdown generator from source code
@@ -276,6 +284,8 @@ test_files:
276
284
  - spec/formatter/type_code_include_spec.rb
277
285
  - spec/formatter/type_eval_spec.rb
278
286
  - spec/formatter/type_hidden_spec.rb
287
+ - spec/formatter/type_inline_image_spec.rb
288
+ - spec/formatter/type_list_spec.rb
279
289
  - spec/formatter/type_md_header_spec.rb
280
290
  - spec/formatter/type_method_spec.rb
281
291
  - spec/formatter/type_parse_include_spec.rb
@@ -286,6 +296,7 @@ test_files:
286
296
  - spec/formatter/type_table_spec.rb
287
297
  - spec/formatter/type_text_spec.rb
288
298
  - spec/formatter/type_title_spec.rb
299
+ - spec/formatter/type_url_list_spec.rb
289
300
  - spec/formatter/type_warn_spec.rb
290
301
  - spec/generator_spec.rb
291
302
  - spec/scanner_spec.rb