source2md 0.0.7 → 0.0.9

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: a21ad256d10d0e8ac822542cfd3b1487ac15ce8e24e9ca7d49b79b8ebef0a29c
4
- data.tar.gz: d437547f1970f22495788b9a39df4c4c953a90a567765181c8ba3fad37dbc095
3
+ metadata.gz: a69cc0fff709a6adfac13be6784fb107d230200b6797391dfd2c970fab4f48ca
4
+ data.tar.gz: 14168fb1b130a4112eb08c4408d6c4bc84b70e5db1b53889201d2c5094343d32
5
5
  SHA512:
6
- metadata.gz: '0920cf0732141436270a375f378a2981b28fcbcefb58e74c4eca9d29fb83e3473ccbc161c956cef54c24ab998d62c618c38fcca6c66cb63422ea6458363448dd'
7
- data.tar.gz: e25345a90c1e3d46899a762a87582b3c9c6e2ec398d38a2a1c815af4fe03094ec823ef840b97a24e7089c3636280f940c5192751213e2e7eecfdfcec8ac74e97
6
+ metadata.gz: c539724001175e52377e62c132ed15d622fdc854dfc02b20f6aa6018bc108044832c9bd2617f9c198ff3261c70fc2876da0004a9b862c462d0af3b5b32f39148
7
+ data.tar.gz: 12fc867c80e7012e8199264fd7c7c2c90d1a0c6e3ead297317deceaeca66b83176fc23389b2803bf060383341b7a5c2321cb90c2da121d73d6db6806fa36ac26
data/README.md CHANGED
@@ -273,7 +273,7 @@ Using this option allows you to split a line regardless of the markdown library.
273
273
 
274
274
  ```ruby
275
275
  puts Source2MD::Section.new(<<~EOS).to_md
276
- #+oneline: true
276
+ #+squish: true
277
277
  # Lorem ipsum dolor sit amet, consectetur adipisicing elit,
278
278
  # sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
279
279
  EOS
@@ -7,7 +7,7 @@ require "./setup"
7
7
 
8
8
  #+BEGIN_SRC
9
9
  puts Source2MD::Section.new(<<~EOS).to_md
10
- #+oneline: true
10
+ #+squish: true
11
11
  # Lorem ipsum dolor sit amet, consectetur adipisicing elit,
12
12
  # sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
13
13
  EOS
@@ -0,0 +1,3 @@
1
+ a
2
+ b
3
+ c
@@ -0,0 +1,2 @@
1
+ #!/bin/sh
2
+ source2md generate -d a.rs
@@ -4,20 +4,16 @@ require "./setup"
4
4
  puts Source2MD::Element.new(<<~EOS).to_md
5
5
  #+alert: (foo)
6
6
  EOS
7
- # >> --------------------------------------------------------------------------------
8
- # >> Source2MD::Part::TypeAlert
9
- # >>
10
- # >> head:
11
- # >> {:alert=>"(foo)"}
12
- # >>
13
- # >> in:
14
- # >>
15
- # >>
16
- # >> out:
17
- # >> :::message alert
18
- # >> (foo)
19
- # >> :::
20
- # >> --------------------------------------------------------------------------------
7
+ # >> > -------------------------------------------------------------------------------- Source2MD::Formatter::TypeAlert
8
+ # >> > {"alert"=>"(foo)"}
9
+ # >> > ------------------------------------------------------------ in
10
+ # >> >
11
+ # >> >
12
+ # >> > ------------------------------------------------------------ out
13
+ # >> > :::message alert
14
+ # >> > (foo)
15
+ # >> > :::
16
+ # >> > ------------------------------------------------------------
21
17
  # >> :::message alert
22
18
  # >> (foo)
23
19
  # >> :::
@@ -2,22 +2,26 @@
2
2
  require "./setup"
3
3
 
4
4
  puts Source2MD::Element.new(<<~EOS).to_md
5
- (foo)
5
+ a
6
+ b
7
+ c
6
8
  EOS
7
- # >> --------------------------------------------------------------------------------
8
- # >> Source2MD::Part::TypePartialCode
9
- # >>
10
- # >> head:
11
- # >> {}
12
- # >>
13
- # >> in:
14
- # >> (foo)
15
- # >>
16
- # >> out:
9
+ # >> > -------------------------------------------------------------------------------- Source2MD::Formatter::TypePartialCode
10
+ # >> > {}
11
+ # >> > ------------------------------------------------------------ in
12
+ # >> > a
13
+ # >> > b
14
+ # >> > c
15
+ # >> >
16
+ # >> > ------------------------------------------------------------ out
17
+ # >> > ```ruby
18
+ # >> > a
19
+ # >> > b
20
+ # >> > c
21
+ # >> > ```
22
+ # >> > ------------------------------------------------------------
17
23
  # >> ```ruby
18
- # >> (foo)
19
- # >> ```
20
- # >> --------------------------------------------------------------------------------
21
- # >> ```ruby
22
- # >> (foo)
24
+ # >> a
25
+ # >> b
26
+ # >> c
23
27
  # >> ```
@@ -2,7 +2,7 @@
2
2
  require "./setup"
3
3
 
4
4
  puts Source2MD::Element.new(<<~EOS).to_md
5
- #+oneline: true
5
+ #+squish: true
6
6
  # a
7
7
  # b
8
8
  #
@@ -25,18 +25,18 @@ puts Source2MD::Element.new(<<~EOS).to_md
25
25
  EOS
26
26
 
27
27
  # >> > -------------------------------------------------------------------------------- Source2MD::Formatter::TypeText
28
- # >> > {"oneline"=>"true"}
28
+ # >> > {"squish"=>"true"}
29
29
  # >> > ------------------------------------------------------------ in
30
30
  # >> > # a
31
31
  # >> > # b
32
32
  # >> > #
33
33
  # >> > # c
34
34
  # >> > # d
35
- # >> >
35
+ # >> >
36
36
  # >> > ------------------------------------------------------------ out
37
- # >> > abcd
37
+ # >> > a b c d
38
38
  # >> > ------------------------------------------------------------
39
- # >> abcd
39
+ # >> a b c d
40
40
  # >> > -------------------------------------------------------------------------------- Source2MD::Formatter::TypeText
41
41
  # >> > {"squish"=>"true"}
42
42
  # >> > ------------------------------------------------------------ in
@@ -45,7 +45,7 @@ EOS
45
45
  # >> > #
46
46
  # >> > # c
47
47
  # >> > # d
48
- # >> >
48
+ # >> >
49
49
  # >> > ------------------------------------------------------------ out
50
50
  # >> > a b c d
51
51
  # >> > ------------------------------------------------------------
@@ -54,7 +54,7 @@ EOS
54
54
  # >> > {"hankaku_kana"=>"true"}
55
55
  # >> > ------------------------------------------------------------ in
56
56
  # >> > # アア
57
- # >> >
57
+ # >> >
58
58
  # >> > ------------------------------------------------------------ out
59
59
  # >> > アア
60
60
  # >> > ------------------------------------------------------------
@@ -4,22 +4,14 @@ require "./setup"
4
4
  puts Source2MD::Element.new(<<~EOS).to_md
5
5
  #+title2: (foo)
6
6
  EOS
7
- # >> title2: (foo)
8
- # >> --------------------------------------------------------------------------------
9
- # >> Source2MD::Part::TypeTitle
10
- # >>
11
- # >> head:
12
- # >> {:title2=>"(foo)"}
13
- # >>
14
- # >> in:
15
- # >>
16
- # >>
17
- # >> out:
18
- # >>
19
- # >> (foo)
20
- # >>
21
- # >> --------------------------------------------------------------------------------
22
- # >> title2: (foo)
23
- # >>
24
- # >> (foo)
25
- # >>
7
+ # >> ## (foo) ##
8
+ # >> > -------------------------------------------------------------------------------- Source2MD::Formatter::TypeTitle
9
+ # >> > {"title2"=>"(foo)"}
10
+ # >> > ------------------------------------------------------------ in
11
+ # >> >
12
+ # >> >
13
+ # >> > ------------------------------------------------------------ out
14
+ # >> > ## (foo) ##
15
+ # >> > ------------------------------------------------------------
16
+ # >> ## (foo) ##
17
+ # >> ## (foo) ##
@@ -2,22 +2,18 @@
2
2
  require "./setup"
3
3
 
4
4
  puts Source2MD::Element.new(<<~EOS).to_md
5
- #+info: (foo)
5
+ #+warn: (foo)
6
6
  EOS
7
- # >> --------------------------------------------------------------------------------
8
- # >> Source2MD::Part::ElementInfo
9
- # >>
10
- # >> head:
11
- # >> {:info=>"(foo)"}
12
- # >>
13
- # >> in:
14
- # >>
15
- # >>
16
- # >> out:
17
- # >> :::message
18
- # >> (foo)
19
- # >> :::
20
- # >> --------------------------------------------------------------------------------
7
+ # >> > -------------------------------------------------------------------------------- Source2MD::Formatter::TypeWarn
8
+ # >> > {"warn"=>"(foo)"}
9
+ # >> > ------------------------------------------------------------ in
10
+ # >> >
11
+ # >> >
12
+ # >> > ------------------------------------------------------------ out
13
+ # >> > :::message
14
+ # >> > (foo)
15
+ # >> > :::
16
+ # >> > ------------------------------------------------------------
21
17
  # >> :::message
22
18
  # >> (foo)
23
19
  # >> :::
data/lib/source2md/cli.rb CHANGED
@@ -2,6 +2,7 @@ module Source2MD
2
2
  class Cli < Thor
3
3
  class_option :debug, type: :boolean, aliases: "-d", default: false
4
4
  class_option :xmp_out_exclude, type: :boolean, aliases: "-x", default: false
5
+ class_option :readonly, type: :boolean, default: true
5
6
 
6
7
  def initialize(...)
7
8
  super
@@ -12,6 +13,7 @@ module Source2MD
12
13
  end
13
14
 
14
15
  Source2MD.xmp_out_exclude = options[:xmp_out_exclude]
16
+ Source2MD.readonly = options[:readonly]
15
17
 
16
18
  tp Source2MD.config
17
19
  end
@@ -20,7 +22,7 @@ module Source2MD
20
22
 
21
23
  map "g" => :generate
22
24
  desc "generate [files]", "Markdown generation"
23
- option :output_file, type: :string, aliases: "-o", default: "output.md"
25
+ option :output_file, type: :string, aliases: "-o", default: nil
24
26
  def generate(*files)
25
27
  Generator.new(options.to_options.merge(files: files)).call
26
28
  end
@@ -1,7 +1,7 @@
1
1
  module Source2MD
2
2
  class CodeBlock
3
3
  PADDING_KEEP = 2
4
- MARK = "# =>"
4
+ MARK = /(?:#|\/\/) =>/
5
5
 
6
6
  attr_accessor :code
7
7
 
@@ -58,21 +58,29 @@ module Source2MD
58
58
  # end
59
59
 
60
60
  def comment_mark_justfiy(line)
61
- line.gsub(/(.*?)\s*#{MARK}(.*)/) {
62
- a, b = Regexp.last_match.captures
61
+ line.gsub(/(.*?)\s*(#{MARK})(.*)/) {
62
+ a, b, c = Regexp.last_match.captures
63
63
  space = " " * (PADDING_KEEP + (max - a.size))
64
- [a, space, MARK, b].join
64
+ [a, space, b, c].join
65
65
  }
66
66
  end
67
67
 
68
+ def raw_lines
69
+ @raw_lines ||= code.lines.collect(&:rstrip)
70
+ end
71
+
68
72
  def lines
69
- @lines ||= code.strip.lines.collect(&:rstrip)
73
+ @lines ||= yield_self do
74
+ min = raw_lines.collect { |e| e.slice(/^\s*/).size }.min
75
+ re = /^\s{#{min}}/
76
+ raw_lines.collect { |e| e.remove(re) }
77
+ end
70
78
  end
71
79
 
72
80
  def max
73
81
  @max ||= yield_self do
74
82
  av = lines
75
- av = av.find_all { |e| e.include?(MARK) }
83
+ av = av.find_all { |e| e.match?(MARK) }
76
84
  av = av.collect { |e| e.gsub(/\s*#{MARK}.*/, "").size }
77
85
  av.max
78
86
  end
@@ -1,6 +1,6 @@
1
1
  module Source2MD
2
2
  class Element
3
- KEY_VALUE_REGEXP = /^#\+(\S+):\s*(.*)\R?/ # #+key: value
3
+ KEY_VALUE_REGEXP = /^(?:#|\/\/)\+(\S+):\s*(.*)\R?/ # #+key: value
4
4
 
5
5
  PLUGINS = [
6
6
  Formatter::TypeHidden, # #+hidden: true
@@ -34,7 +34,7 @@ module Source2MD
34
34
  end
35
35
 
36
36
  def body
37
- @body ||= @content.remove(KEY_VALUE_REGEXP).strip.freeze
37
+ @body ||= @content.remove(KEY_VALUE_REGEXP).rstrip.freeze
38
38
  end
39
39
 
40
40
  private
@@ -7,8 +7,20 @@ module Source2MD
7
7
  end
8
8
 
9
9
  def call
10
- output_file.write(to_md)
11
- puts "write: #{output_file}"
10
+ if !output_file
11
+ puts to_md
12
+ end
13
+
14
+ if output_file
15
+ if output_file.exist?
16
+ FileUtils.chmod("a+w", output_file)
17
+ end
18
+ output_file.write(to_md)
19
+ if Source2MD.readonly
20
+ FileUtils.chmod("a-w", output_file)
21
+ end
22
+ puts "write: #{output_file}"
23
+ end
12
24
  end
13
25
 
14
26
  def to_md
@@ -28,7 +40,11 @@ module Source2MD
28
40
  end
29
41
 
30
42
  def output_file
31
- @output_file ||= Pathname(params[:output_file]).expand_path
43
+ @output_file ||= yield_self do
44
+ if v = params[:output_file]
45
+ Pathname(v).expand_path
46
+ end
47
+ end
32
48
  end
33
49
  end
34
50
  end
@@ -24,7 +24,7 @@ module Source2MD
24
24
  end
25
25
  v = v + "\n\n"
26
26
  v = v.scan(PARAGRAPH_RE)
27
- v = v.collect(&:strip)
27
+ v = v.collect(&:rstrip)
28
28
  v = v.find_all(&:present?)
29
29
  end
30
30
  end
@@ -1,3 +1,3 @@
1
1
  module Source2MD
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.9"
3
3
  end
data/lib/source2md.rb CHANGED
@@ -14,6 +14,7 @@ module Source2MD
14
14
  include ActiveSupport::Configurable
15
15
  config_accessor(:debug) { false }
16
16
  config_accessor(:xmp_out_exclude) { false }
17
+ config_accessor(:readonly) { true }
17
18
  end
18
19
 
19
20
  require "zeitwerk"
data/output.md ADDED
@@ -0,0 +1,13 @@
1
+ ```ruby
2
+ a
3
+ ```
4
+
5
+ ```ruby
6
+ r.xy(); // => Vec2(0.0, 0.0)
7
+ r.xy(); // => Vec2(0.0, 0.0)
8
+ r.xy(); // => Vec2(0.0, 0.0)
9
+ ```
10
+
11
+ ```ruby
12
+ b
13
+ ```
data/spec/scanner_spec.rb CHANGED
@@ -17,10 +17,17 @@ module Source2MD
17
17
  #+BEGIN_SRC
18
18
  foo
19
19
  #+END_SRC
20
+
20
21
  foo
21
22
  EOS
22
23
 
24
+ ary # => ["foo", "#+BEGIN_SRC\n\nfoo\n\n#+END_SRC", "foo", "#+BEGIN_SRC\nfoo\n#+END_SRC", "foo"]
23
25
  assert { ary == ["foo", "#+BEGIN_SRC\n\nfoo\n\n#+END_SRC", "foo", "#+BEGIN_SRC\nfoo\n#+END_SRC", "foo"] }
24
26
  end
25
27
  end
26
28
  end
29
+ # >> .
30
+ # >>
31
+ # >> Finished in 0.00793 seconds (files took 0.26816 seconds to load)
32
+ # >> 1 example, 0 failures
33
+ # >>
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.7
4
+ version: 0.0.9
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-07-28 00:00:00.000000000 Z
11
+ date: 2023-08-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -165,6 +165,8 @@ files:
165
165
  - doc/0240_text_hankaku_kana.rb
166
166
  - doc/0250_parse_include.rb
167
167
  - doc/setup.rb
168
+ - examples/cli-test.rs
169
+ - examples/cli-test.sh
168
170
  - examples/cli.rb
169
171
  - examples/element_text.rb
170
172
  - examples/input.rb
@@ -210,6 +212,7 @@ files:
210
212
  - lib/source2md/tasks/test.rake
211
213
  - lib/source2md/text_helper.rb
212
214
  - lib/source2md/version.rb
215
+ - output.md
213
216
  - source2md.gemspec
214
217
  - spec/code_block_spec.rb
215
218
  - spec/formatter/sample.yml
@@ -248,7 +251,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
248
251
  - !ruby/object:Gem::Version
249
252
  version: '0'
250
253
  requirements: []
251
- rubygems_version: 3.4.17
254
+ rubygems_version: 3.4.18
252
255
  signing_key:
253
256
  specification_version: 4
254
257
  summary: Markdown generator from source code