source2md 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a21ad256d10d0e8ac822542cfd3b1487ac15ce8e24e9ca7d49b79b8ebef0a29c
4
- data.tar.gz: d437547f1970f22495788b9a39df4c4c953a90a567765181c8ba3fad37dbc095
3
+ metadata.gz: f07581e2e1a43897fbabf84171220745ae7ca72f96a19fd0f56e9aac6e73bd5d
4
+ data.tar.gz: 62e064eaf58861b1abf0b04739e54715a2efbcc74ced61fb0c949e232bf6e3a0
5
5
  SHA512:
6
- metadata.gz: '0920cf0732141436270a375f378a2981b28fcbcefb58e74c4eca9d29fb83e3473ccbc161c956cef54c24ab998d62c618c38fcca6c66cb63422ea6458363448dd'
7
- data.tar.gz: e25345a90c1e3d46899a762a87582b3c9c6e2ec398d38a2a1c815af4fe03094ec823ef840b97a24e7089c3636280f940c5192751213e2e7eecfdfcec8ac74e97
6
+ metadata.gz: b426db58ee1eda88c7c9174867cdb6dd9e67d951605a74dc0c2fbcaf8d3464819a84042822fc7d99d78513762be1c3de491af6a2f61dd2d755f8a268fcd58bde
7
+ data.tar.gz: 2d97f41bc6ab44b7a2019c2008a4845f879c7b91e82a68ed5fc98e158eebb9a660fe7a34ebfc9a7ef2551c389fc0a84360bc67bd57de56e465900f717a6544c1
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
@@ -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
  #
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
@@ -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,10 +58,10 @@ 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
 
@@ -72,7 +72,7 @@ module Source2MD
72
72
  def max
73
73
  @max ||= yield_self do
74
74
  av = lines
75
- av = av.find_all { |e| e.include?(MARK) }
75
+ av = av.find_all { |e| e.match?(MARK) }
76
76
  av = av.collect { |e| e.gsub(/\s*#{MARK}.*/, "").size }
77
77
  av.max
78
78
  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
@@ -7,7 +7,13 @@ module Source2MD
7
7
  end
8
8
 
9
9
  def call
10
+ if output_file.exist?
11
+ FileUtils.chmod("a+w", output_file)
12
+ end
10
13
  output_file.write(to_md)
14
+ if Source2MD.readonly
15
+ FileUtils.chmod("a-w", output_file)
16
+ end
11
17
  puts "write: #{output_file}"
12
18
  end
13
19
 
@@ -1,3 +1,3 @@
1
1
  module Source2MD
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
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"
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.8
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
@@ -248,7 +248,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
248
248
  - !ruby/object:Gem::Version
249
249
  version: '0'
250
250
  requirements: []
251
- rubygems_version: 3.4.17
251
+ rubygems_version: 3.4.18
252
252
  signing_key:
253
253
  specification_version: 4
254
254
  summary: Markdown generator from source code