source2md 0.0.16 → 0.0.17

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: f98cf52536b132ac7b8a7ed2b99653c0b1c668c0d3b7bd3681e898854fa00b8a
4
- data.tar.gz: e78fa6dbddfefd98ee5757ca3f41911568df9825c332e1e1453e0df3ff0d7b7f
3
+ metadata.gz: 2d239ae5a48c121dc61a4fcd811cf6572f32b1ee793bae58a2a6c69f4e815d0f
4
+ data.tar.gz: 748a3da2af4129d894031af00b71b0e4553e4a21018b84a2d12e0f646ab1ce12
5
5
  SHA512:
6
- metadata.gz: a9844d91a277c17f86037ab84efbf5b1f0bcd627fbb00ef16188f19b0e90716b0d7402644b7b60f5975919d7b194851d762463b93a7a50461e09b1eb5459d95f
7
- data.tar.gz: 8d18aeff6e37f72c9c18c8187d64a62e9078cd534e280ef4c165a99c973f6bf079a610b57d86d8fe9d2b7abc8143ce7a9acbedbce2f710dcb537467358acddf4
6
+ metadata.gz: 4fa15b238f101e8da2f2f2f8a997e98697c032af2b6674b7896ae7ce0b325f695e213c1b321b8989bc58a9a448bc9d030dccd0251b2473f738ac5e0a0e920957
7
+ data.tar.gz: a7d8ca07d2bd122437b711b9ce90387783e1d96a560b422c1c83cd745f062656c4ab0cde8239532c611fb898fcb7d98396bd3d447975b558e93713bf85cd2d4d
@@ -0,0 +1,41 @@
1
+ #+hidden: true
2
+ require "./setup"
3
+
4
+ puts Source2MD::Element.new(<<~EOS).to_md
5
+ # ```
6
+ # foo
7
+ # ```
8
+ EOS
9
+
10
+ # >> head: {}
11
+ # >> body: "# ```\n# foo\n# ```\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 => true
25
+ # >> > -------------------------------------------------------------------------------- Source2MD::Formatter::TypeCodeBlock
26
+ # >> > {}
27
+ # >> > ------------------------------------------------------------ in
28
+ # >> > # ```
29
+ # >> > # foo
30
+ # >> > # ```
31
+ # >> >
32
+ # >> >
33
+ # >> > ------------------------------------------------------------ out
34
+ # >> > ```
35
+ # >> > foo
36
+ # >> > ```
37
+ # >> >
38
+ # >> > ------------------------------------------------------------
39
+ # >> ```
40
+ # >> foo
41
+ # >> ```
@@ -3,23 +3,29 @@ require "./setup"
3
3
 
4
4
  puts Source2MD::Element.new(<<~EOS).to_md
5
5
 
6
- #+code_include: input.yml
6
+ #+code_include: input.yml ruby:abc (AC)
7
7
  #+name:
8
8
 
9
9
  EOS
10
+ # >> head: {"code_include"=>"input.yml ruby:abc (AC)", "name"=>""}
11
+ # >> body: ""
12
+ # >> Source2MD::Formatter::TypeHidden => false
13
+ # >> Source2MD::Formatter::TypeEval =>
14
+ # >> Source2MD::Formatter::TypeCodeInclude => input.yml ruby:abc (AC)
10
15
  # >> > -------------------------------------------------------------------------------- Source2MD::Formatter::TypeCodeInclude
11
- # >> > {"code_include"=>"input.yml", "name"=>""}
16
+ # >> > {"code_include"=>"input.yml ruby:abc (AC)", "name"=>""}
12
17
  # >> > ------------------------------------------------------------ in
13
18
  # >> >
14
19
  # >> >
15
20
  # >> > ------------------------------------------------------------ out
16
- # >> > ```yml:
21
+ # >> > ```ruby:abc (AC)
17
22
  # >> > ---
18
23
  # >> > one:
19
24
  # >> > foo: 1
20
25
  # >> > ```
26
+ # >> >
21
27
  # >> > ------------------------------------------------------------
22
- # >> ```yml:
28
+ # >> ```ruby:abc (AC)
23
29
  # >> ---
24
30
  # >> one:
25
31
  # >> foo: 1
@@ -0,0 +1,43 @@
1
+ #+hidden: true
2
+ require "./setup"
3
+
4
+ puts Source2MD::Element.new(<<~EOS).to_md
5
+ # ---
6
+ # foo: bar
7
+ # ---
8
+ EOS
9
+
10
+ # >> head: {}
11
+ # >> body: "# ---\n# foo: bar\n# ---\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
+ # >> # foo: bar
25
+ # >> # ---
26
+ # >>
27
+ # >> > -------------------------------------------------------------------------------- Source2MD::Formatter::TypeMdHeader
28
+ # >> > {}
29
+ # >> > ------------------------------------------------------------ in
30
+ # >> > # ---
31
+ # >> > # foo: bar
32
+ # >> > # ---
33
+ # >> >
34
+ # >> >
35
+ # >> > ------------------------------------------------------------ out
36
+ # >> > ---
37
+ # >> > foo: bar
38
+ # >> > ---
39
+ # >> >
40
+ # >> > ------------------------------------------------------------
41
+ # >> ---
42
+ # >> foo: bar
43
+ # >> ---
@@ -0,0 +1,34 @@
1
+ #+hidden: true
2
+ require "./setup"
3
+
4
+ puts Source2MD::Element.new(<<~EOS).to_md
5
+ # > foo
6
+ EOS
7
+
8
+ # >> head: {}
9
+ # >> body: "# > foo\n"
10
+ # >> Source2MD::Formatter::TypeHidden => false
11
+ # >> Source2MD::Formatter::TypeEval =>
12
+ # >> Source2MD::Formatter::TypeCodeInclude =>
13
+ # >> Source2MD::Formatter::TypeRawInclude =>
14
+ # >> Source2MD::Formatter::TypeParseInclude =>
15
+ # >> Source2MD::Formatter::TypeTitle => false
16
+ # >> Source2MD::Formatter::TypeWarn =>
17
+ # >> Source2MD::Formatter::TypeAlert =>
18
+ # >> Source2MD::Formatter::TypeMethod =>
19
+ # >> Source2MD::Formatter::TypeTable => false
20
+ # >> Source2MD::Formatter::TypeSourceBlock => false
21
+ # >> Source2MD::Formatter::TypeMdHeader =>
22
+ # >> Source2MD::Formatter::TypeCodeBlock => false
23
+ # >> Source2MD::Formatter::TypeQuote => # > foo
24
+ # >> > -------------------------------------------------------------------------------- Source2MD::Formatter::TypeQuote
25
+ # >> > {}
26
+ # >> > ------------------------------------------------------------ in
27
+ # >> > # > foo
28
+ # >> >
29
+ # >> >
30
+ # >> > ------------------------------------------------------------ out
31
+ # >> > > foo
32
+ # >> >
33
+ # >> > ------------------------------------------------------------
34
+ # >> > foo
data/lib/source2md/cli.rb CHANGED
@@ -4,6 +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 :oneline, type: :boolean, aliases: "-1", default: false
7
8
  class_option :lang_default, type: :string, aliases: "-l", default: "ruby"
8
9
  class_option :prefix_re, type: :string
9
10
  class_option :comment_re, type: :string
@@ -19,6 +20,7 @@ module Source2MD
19
20
  Source2MD.xmp_out_exclude = options[:xmp_out_exclude]
20
21
  Source2MD.data_block_exclude = options[:data_block_exclude]
21
22
  Source2MD.readonly = options[:readonly]
23
+ Source2MD.oneline = options[:oneline]
22
24
  Source2MD.lang_default = options[:lang_default]
23
25
 
24
26
  Source2MD::RE.update do |e|
@@ -2,7 +2,7 @@ module Source2MD
2
2
  class Element
3
3
  PLUGINS = [
4
4
  Formatter::TypeHidden, # #+hidden: true
5
- Formatter::TypeEval, # #+eval:
5
+ Formatter::TypeEval, # #+eval:
6
6
  Formatter::TypeCodeInclude, # #+code_include: path/to/foo.html xml:SAMPLE.xml
7
7
  Formatter::TypeRawInclude, # #+raw_include: path/to/file.txt
8
8
  Formatter::TypeParseInclude, # #+parse_include: path/to/file.txt
@@ -12,8 +12,20 @@ module Source2MD
12
12
  Formatter::TypeMethod, # #+name: foo
13
13
  Formatter::TypeTable, # # |-
14
14
  Formatter::TypeSourceBlock, # #+BEGIN_SRC
15
+
16
+ # Type that just removes the comment and does not wrap it
17
+ Formatter::TypeMdHeader, # # ---
18
+ Formatter::TypeCodeBlock, # # ```
19
+ Formatter::TypeQuote, # # > xxx
20
+ Formatter::TypeList, # # - xxx or 1. xxx
21
+
22
+ # Sentence (automatic wrap)
15
23
  Formatter::TypeText, # # foo
24
+
25
+ # Code block without wrapping
16
26
  Formatter::TypePartialCode, # 1 + 2 # => 3
27
+
28
+ # If not all match
17
29
  Formatter::TypeElse,
18
30
  ]
19
31
 
@@ -0,0 +1,19 @@
1
+ module Source2MD
2
+ module Formatter
3
+ class TypeCodeBlock < Base
4
+
5
+ # "# ```"
6
+ def self.regexp
7
+ %r{#{RE.meta_re}\s+```}
8
+ end
9
+
10
+ def self.accept?(element)
11
+ element.body.match?(regexp)
12
+ end
13
+
14
+ def to_md
15
+ element.body.remove(TypeText.regexp)
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,20 @@
1
+ module Source2MD
2
+ module Formatter
3
+ class TypeList < Base
4
+
5
+ # "# 1. foo"
6
+ # "# - foo"
7
+ def self.regexp
8
+ %r{#{RE.meta_re}\s+(?:\d\.|-)\s+\S+}
9
+ end
10
+
11
+ def self.accept?(element)
12
+ element.body.match?(regexp)
13
+ end
14
+
15
+ def to_md
16
+ element.body.remove(TypeText.regexp)
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,17 @@
1
+ module Source2MD
2
+ module Formatter
3
+ class TypeMdHeader < Base
4
+ def self.regexp
5
+ /#{RE.meta_re} ---\n.* ---\n/m
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
@@ -0,0 +1,17 @@
1
+ module Source2MD
2
+ module Formatter
3
+ class TypeQuote < Base
4
+ def self.regexp
5
+ /#{RE.meta_re}\s+\>\s+\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
@@ -25,9 +25,13 @@ module Source2MD
25
25
  if element.head["squish"] == "true"
26
26
  s = TextHelper.squish(s)
27
27
  end
28
- if element.head["oneline"] == "true"
28
+
29
+ case
30
+ when element.head["oneline"] == "false"
31
+ when element.head["oneline"] == "true" || Source2MD.oneline
29
32
  s = TextHelper.oneline(s)
30
33
  end
34
+
31
35
  if element.head["hankaku_kana"] == "true"
32
36
  s = TextHelper.hankaku_kana(s)
33
37
  end
@@ -7,7 +7,8 @@ module Source2MD
7
7
  end
8
8
 
9
9
  def oneline(text)
10
- text.remove(/\R+/)
10
+ text = text.gsub(/?\R/, "? ")
11
+ text = text.remove(/\R+/)
11
12
  end
12
13
 
13
14
  def squish(text)
@@ -1,3 +1,3 @@
1
1
  module Source2MD
2
- VERSION = "0.0.16"
2
+ VERSION = "0.0.17"
3
3
  end
data/lib/source2md.rb CHANGED
@@ -17,6 +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
21
  end
21
22
 
22
23
  require "zeitwerk"
@@ -0,0 +1,23 @@
1
+ require "spec_helper"
2
+
3
+ module Source2MD
4
+ describe do
5
+ it "works" do
6
+ actual = Element.new(<<~EOS).to_md
7
+ # ```
8
+ # foo
9
+ # ```
10
+ EOS
11
+ actual.should == <<~EOS
12
+ ```
13
+ foo
14
+ ```
15
+ EOS
16
+ end
17
+ end
18
+ end
19
+ # >> .
20
+ # >>
21
+ # >> Finished in 0.00614 seconds (files took 0.36666 seconds to load)
22
+ # >> 1 example, 0 failures
23
+ # >>
@@ -0,0 +1,23 @@
1
+ require "spec_helper"
2
+
3
+ module Source2MD
4
+ describe do
5
+ it "works" do
6
+ actual = Element.new(<<~EOS).to_md
7
+ # ---
8
+ # foo: bar
9
+ # ---
10
+ EOS
11
+ actual.should == <<~EOS
12
+ ---
13
+ foo: bar
14
+ ---
15
+ EOS
16
+ end
17
+ end
18
+ end
19
+ # >> .
20
+ # >>
21
+ # >> Finished in 0.00648 seconds (files took 0.35849 seconds to load)
22
+ # >> 1 example, 0 failures
23
+ # >>
@@ -0,0 +1,19 @@
1
+ require "spec_helper"
2
+
3
+ module Source2MD
4
+ describe do
5
+ it "works" do
6
+ actual = Element.new(<<~EOS).to_md
7
+ # > foo
8
+ EOS
9
+ actual.should == <<~EOS
10
+ > foo
11
+ EOS
12
+ end
13
+ end
14
+ end
15
+ # >> .
16
+ # >>
17
+ # >> Finished in 0.00637 seconds (files took 0.3615 seconds to load)
18
+ # >> 1 example, 0 failures
19
+ # >>
@@ -6,6 +6,10 @@ module Source2MD
6
6
  assert { TextHelper.blank_lines_squish("A\nB\n\nC\n\n\nD") == "A\nB\n\nC\n\nD" }
7
7
  end
8
8
 
9
+ it "oneline" do
10
+ assert { TextHelper.oneline("?\nA") == "? A" }
11
+ end
12
+
9
13
  it "eol_enter" do
10
14
  assert { TextHelper.eol_enter("A") == "A\n" }
11
15
  assert { TextHelper.eol_enter("A\n\n") == "A\n" }
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.16
4
+ version: 0.0.17
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-12-31 00:00:00.000000000 Z
11
+ date: 2024-02-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -175,11 +175,14 @@ files:
175
175
  - examples/scanner.rb
176
176
  - examples/setup.rb
177
177
  - examples/type_alert.rb
178
+ - examples/type_code_block.rb
178
179
  - examples/type_code_include.rb
179
180
  - examples/type_eval.rb
180
181
  - examples/type_hidden.rb
182
+ - examples/type_md_header.rb
181
183
  - examples/type_method.rb
182
184
  - examples/type_partial_code.rb
185
+ - examples/type_quote.rb
183
186
  - examples/type_source_block.rb
184
187
  - examples/type_table.rb
185
188
  - examples/type_text.rb
@@ -191,14 +194,18 @@ files:
191
194
  - lib/source2md/element.rb
192
195
  - lib/source2md/formatter/base.rb
193
196
  - lib/source2md/formatter/type_alert.rb
197
+ - lib/source2md/formatter/type_code_block.rb
194
198
  - lib/source2md/formatter/type_code_include.rb
195
199
  - lib/source2md/formatter/type_else.rb
196
200
  - lib/source2md/formatter/type_eval.rb
197
201
  - lib/source2md/formatter/type_hidden.rb
202
+ - lib/source2md/formatter/type_list.rb
203
+ - lib/source2md/formatter/type_md_header.rb
198
204
  - lib/source2md/formatter/type_method.rb
199
205
  - lib/source2md/formatter/type_nop.rb
200
206
  - lib/source2md/formatter/type_parse_include.rb
201
207
  - lib/source2md/formatter/type_partial_code.rb
208
+ - lib/source2md/formatter/type_quote.rb
202
209
  - lib/source2md/formatter/type_raw_include.rb
203
210
  - lib/source2md/formatter/type_source_block.rb
204
211
  - lib/source2md/formatter/type_table.rb
@@ -219,12 +226,15 @@ files:
219
226
  - spec/code_block_spec.rb
220
227
  - spec/formatter/sample.yml
221
228
  - spec/formatter/type_alert_spec.rb
229
+ - spec/formatter/type_code_block_spec.rb
222
230
  - spec/formatter/type_code_include_spec.rb
223
231
  - spec/formatter/type_eval_spec.rb
224
232
  - spec/formatter/type_hidden_spec.rb
233
+ - spec/formatter/type_md_header_spec.rb
225
234
  - spec/formatter/type_method_spec.rb
226
235
  - spec/formatter/type_parse_include_spec.rb
227
236
  - spec/formatter/type_partial_code_spec.rb
237
+ - spec/formatter/type_quote_spec.rb
228
238
  - spec/formatter/type_raw_include_spec.rb
229
239
  - spec/formatter/type_source_block_spec.rb
230
240
  - spec/formatter/type_table_spec.rb
@@ -254,7 +264,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
254
264
  - !ruby/object:Gem::Version
255
265
  version: '0'
256
266
  requirements: []
257
- rubygems_version: 3.4.22
267
+ rubygems_version: 3.5.4
258
268
  signing_key:
259
269
  specification_version: 4
260
270
  summary: Markdown generator from source code
@@ -262,12 +272,15 @@ test_files:
262
272
  - spec/code_block_spec.rb
263
273
  - spec/formatter/sample.yml
264
274
  - spec/formatter/type_alert_spec.rb
275
+ - spec/formatter/type_code_block_spec.rb
265
276
  - spec/formatter/type_code_include_spec.rb
266
277
  - spec/formatter/type_eval_spec.rb
267
278
  - spec/formatter/type_hidden_spec.rb
279
+ - spec/formatter/type_md_header_spec.rb
268
280
  - spec/formatter/type_method_spec.rb
269
281
  - spec/formatter/type_parse_include_spec.rb
270
282
  - spec/formatter/type_partial_code_spec.rb
283
+ - spec/formatter/type_quote_spec.rb
271
284
  - spec/formatter/type_raw_include_spec.rb
272
285
  - spec/formatter/type_source_block_spec.rb
273
286
  - spec/formatter/type_table_spec.rb