source2md 0.0.9 → 0.0.10
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 +4 -4
- data/examples/cli-test.rs +6 -3
- data/examples/cli-test.sh +1 -1
- data/lib/source2md/cli.rb +3 -3
- data/lib/source2md/code_block.rb +17 -22
- data/lib/source2md/element.rb +11 -4
- data/lib/source2md/formatter/type_code_include.rb +1 -1
- data/lib/source2md/formatter/type_method.rb +15 -7
- data/lib/source2md/formatter/{type_md_title.rb → type_nop.rb} +3 -3
- data/lib/source2md/formatter/type_raw_include.rb +2 -1
- data/lib/source2md/formatter/type_source_block.rb +4 -4
- data/lib/source2md/formatter/type_table.rb +5 -5
- data/lib/source2md/formatter/type_text.rb +5 -3
- data/lib/source2md/generator.rb +1 -1
- data/lib/source2md/scanner.rb +4 -4
- data/lib/source2md/text_helper.rb +13 -4
- data/lib/source2md/version.rb +1 -1
- data/lib/source2md.rb +1 -0
- data/spec/code_block_spec.rb +2 -1
- data/spec/formatter/type_code_include_spec.rb +3 -3
- data/spec/formatter/type_method_spec.rb +3 -2
- data/spec/formatter/type_partial_code_spec.rb +1 -1
- data/spec/formatter/type_raw_include_spec.rb +1 -1
- data/spec/formatter/type_source_block_spec.rb +2 -2
- data/spec/formatter/type_table_spec.rb +2 -2
- data/spec/formatter/type_text_spec.rb +5 -4
- data/spec/scanner_spec.rb +15 -5
- data/spec/text_helper_spec.rb +8 -4
- metadata +3 -6
- data/examples/type_md_title.rb +0 -15
- data/spec/formatter/type_md_title_spec.rb +0 -14
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 2ac00b7cc8674c792566d8d08c5d2f1b8f5cf755ceca1479b2ac8248ad6dac3e
         | 
| 4 | 
            +
              data.tar.gz: e7c61a968ca24419cc5a62c86437388f77cd865895ac038a5565b1a4ab4c180d
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 25222fde61442a0fceba5daa0e0ff09e7343c0fcacf7123670d85ee66f3a4df50533ec40b211b851eea0870bf64f781b9dd283dc26650a1d7a004d27a95dd513
         | 
| 7 | 
            +
              data.tar.gz: c89ccfdb613ee1a8fa95eef6a1524be3fe7534a2e5c2fd18fceba4895f87711febc078292f4b974c1ae7a525d75af8e2e528c10b59a55678c7f2730814776077
         | 
    
        data/examples/cli-test.rs
    CHANGED
    
    
    
        data/examples/cli-test.sh
    CHANGED
    
    | @@ -1,2 +1,2 @@ | |
| 1 1 | 
             
            #!/bin/sh
         | 
| 2 | 
            -
            source2md generate -d  | 
| 2 | 
            +
            ../.bin/source2md generate -d cli-test.rs
         | 
    
        data/lib/source2md/cli.rb
    CHANGED
    
    | @@ -2,7 +2,8 @@ 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 | 
            +
                class_option :readonly,        type: :boolean, aliases: "-r", default: true
         | 
| 6 | 
            +
                class_option :default_lang,    type: :string,  aliases: "-l", default: "ruby"
         | 
| 6 7 |  | 
| 7 8 | 
             
                def initialize(...)
         | 
| 8 9 | 
             
                  super
         | 
| @@ -14,8 +15,7 @@ module Source2MD | |
| 14 15 |  | 
| 15 16 | 
             
                  Source2MD.xmp_out_exclude = options[:xmp_out_exclude]
         | 
| 16 17 | 
             
                  Source2MD.readonly = options[:readonly]
         | 
| 17 | 
            -
             | 
| 18 | 
            -
                  tp Source2MD.config
         | 
| 18 | 
            +
                  Source2MD.default_lang = options[:default_lang]
         | 
| 19 19 | 
             
                end
         | 
| 20 20 |  | 
| 21 21 | 
             
                # default_command :generate
         | 
    
        data/lib/source2md/code_block.rb
    CHANGED
    
    | @@ -1,24 +1,22 @@ | |
| 1 1 | 
             
            module Source2MD
         | 
| 2 2 | 
             
              class CodeBlock
         | 
| 3 3 | 
             
                PADDING_KEEP = 2
         | 
| 4 | 
            -
                MARK         =  | 
| 4 | 
            +
                MARK         = %r{(?:#|//) =>}
         | 
| 5 5 |  | 
| 6 | 
            -
                 | 
| 7 | 
            -
             | 
| 8 | 
            -
                def initialize(code, options = {})
         | 
| 9 | 
            -
                  @code = code
         | 
| 6 | 
            +
                def initialize(text, options = {})
         | 
| 7 | 
            +
                  @text = text
         | 
| 10 8 | 
             
                  @options = {
         | 
| 11 | 
            -
                    :lang =>  | 
| 9 | 
            +
                    :lang => nil,
         | 
| 12 10 | 
             
                    # :single_sharp_replace_to_blank_line => false,
         | 
| 13 11 | 
             
                  }.merge(options)
         | 
| 14 12 | 
             
                end
         | 
| 15 13 |  | 
| 16 14 | 
             
                def to_md
         | 
| 17 15 | 
             
                  [
         | 
| 18 | 
            -
                    "```#{code_block_head}",
         | 
| 16 | 
            +
                    "```#{code_block_head}\n",
         | 
| 19 17 | 
             
                    normalized_code,
         | 
| 20 | 
            -
                    " | 
| 21 | 
            -
                  ] | 
| 18 | 
            +
                    "```\n",
         | 
| 19 | 
            +
                  ].join
         | 
| 22 20 | 
             
                end
         | 
| 23 21 |  | 
| 24 22 | 
             
                private
         | 
| @@ -28,7 +26,7 @@ module Source2MD | |
| 28 26 | 
             
                  if s = @options[:desc]
         | 
| 29 27 | 
             
                    o << s
         | 
| 30 28 | 
             
                  else
         | 
| 31 | 
            -
                    if s =  | 
| 29 | 
            +
                    if s = lang
         | 
| 32 30 | 
             
                      o << s
         | 
| 33 31 | 
             
                    end
         | 
| 34 32 | 
             
                    if s = @options[:name]
         | 
| @@ -40,17 +38,14 @@ module Source2MD | |
| 40 38 | 
             
                end
         | 
| 41 39 |  | 
| 42 40 | 
             
                def normalized_code
         | 
| 43 | 
            -
                  lines.collect(&method(:normalize)) | 
| 41 | 
            +
                  lines.collect(&method(:normalize)).join
         | 
| 44 42 | 
             
                end
         | 
| 45 43 |  | 
| 46 44 | 
             
                def normalize(line)
         | 
| 47 45 | 
             
                  # if @options[:single_sharp_replace_to_blank_line]
         | 
| 48 46 | 
             
                  #   line = single_sharp_replace_to_blank_line(line)
         | 
| 49 47 | 
             
                  # end
         | 
| 50 | 
            -
                   | 
| 51 | 
            -
                    line = comment_mark_justfiy(line)
         | 
| 52 | 
            -
                  end
         | 
| 53 | 
            -
                  line
         | 
| 48 | 
            +
                  comment_mark_justfiy(line)
         | 
| 54 49 | 
             
                end
         | 
| 55 50 |  | 
| 56 51 | 
             
                # def single_sharp_replace_to_blank_line(line)
         | 
| @@ -66,24 +61,24 @@ module Source2MD | |
| 66 61 | 
             
                end
         | 
| 67 62 |  | 
| 68 63 | 
             
                def raw_lines
         | 
| 69 | 
            -
                  @raw_lines ||=  | 
| 64 | 
            +
                  @raw_lines ||= @text.lines
         | 
| 70 65 | 
             
                end
         | 
| 71 66 |  | 
| 72 67 | 
             
                def lines
         | 
| 73 | 
            -
                  @lines ||=  | 
| 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
         | 
| 68 | 
            +
                  @lines ||= TextHelper.space_prefix_remove(@text).lines
         | 
| 78 69 | 
             
                end
         | 
| 79 70 |  | 
| 80 71 | 
             
                def max
         | 
| 81 72 | 
             
                  @max ||= yield_self do
         | 
| 82 73 | 
             
                    av = lines
         | 
| 83 74 | 
             
                    av = av.find_all { |e| e.match?(MARK) }
         | 
| 84 | 
            -
                    av = av.collect { |e| e.gsub(/\s*#{MARK} | 
| 75 | 
            +
                    av = av.collect { |e| e.gsub(/\s*#{MARK}.*\R/, "").size }
         | 
| 85 76 | 
             
                    av.max
         | 
| 86 77 | 
             
                  end
         | 
| 87 78 | 
             
                end
         | 
| 79 | 
            +
             | 
| 80 | 
            +
                def lang
         | 
| 81 | 
            +
                  @options[:lang] || ENV["DEFAULT_LANG"] || Source2MD.default_lang
         | 
| 82 | 
            +
                end
         | 
| 88 83 | 
             
              end
         | 
| 89 84 | 
             
            end
         | 
    
        data/lib/source2md/element.rb
    CHANGED
    
    | @@ -1,10 +1,9 @@ | |
| 1 1 | 
             
            module Source2MD
         | 
| 2 2 | 
             
              class Element
         | 
| 3 | 
            -
                KEY_VALUE_REGEXP =  | 
| 3 | 
            +
                KEY_VALUE_REGEXP = /^\s*(?:#|\/\/)\+(\S+):\s*(.*)\R?/ # #+key: value
         | 
| 4 4 |  | 
| 5 5 | 
             
                PLUGINS = [
         | 
| 6 6 | 
             
                  Formatter::TypeHidden,       # #+hidden: true
         | 
| 7 | 
            -
                  Formatter::TypeMdTitle,      # ## foo ##
         | 
| 8 7 | 
             
                  Formatter::TypeCodeInclude,  # #+code_include: path/to/foo.html xml:SAMPLE.xml
         | 
| 9 8 | 
             
                  Formatter::TypeRawInclude,   # #+raw_include: path/to/file.txt
         | 
| 10 9 | 
             
                  Formatter::TypeParseInclude, # #+parse_include: path/to/file.txt
         | 
| @@ -34,13 +33,21 @@ module Source2MD | |
| 34 33 | 
             
                end
         | 
| 35 34 |  | 
| 36 35 | 
             
                def body
         | 
| 37 | 
            -
                  @body ||= @content.remove(KEY_VALUE_REGEXP). | 
| 36 | 
            +
                  @body ||= @content.remove(KEY_VALUE_REGEXP).freeze
         | 
| 38 37 | 
             
                end
         | 
| 39 38 |  | 
| 40 39 | 
             
                private
         | 
| 41 40 |  | 
| 42 41 | 
             
                def support_klass
         | 
| 43 | 
            -
                  @support_klass ||=  | 
| 42 | 
            +
                  @support_klass ||= yield_self do
         | 
| 43 | 
            +
                    Source2MD.logger.debug { "head: #{head.inspect}" }
         | 
| 44 | 
            +
                    Source2MD.logger.debug { "body: #{body.inspect}" }
         | 
| 45 | 
            +
                    PLUGINS.find do |e|
         | 
| 46 | 
            +
                      e.accept?(self).tap do |result|
         | 
| 47 | 
            +
                        Source2MD.logger.debug { "#{e} => #{result}" }
         | 
| 48 | 
            +
                      end
         | 
| 49 | 
            +
                    end
         | 
| 50 | 
            +
                  end
         | 
| 44 51 | 
             
                end
         | 
| 45 52 |  | 
| 46 53 | 
             
                def debug_log(object)
         | 
| @@ -6,18 +6,26 @@ module Source2MD | |
| 6 6 | 
             
                  end
         | 
| 7 7 |  | 
| 8 8 | 
             
                  def to_md
         | 
| 9 | 
            -
                    [
         | 
| 10 | 
            -
             | 
| 11 | 
            -
             | 
| 12 | 
            -
                       | 
| 13 | 
            -
                       | 
| 14 | 
            -
             | 
| 9 | 
            +
                    o = []
         | 
| 10 | 
            +
                    o << "### #{element.head["name"]} ###\n"
         | 
| 11 | 
            +
                    if v = element.head["desc"]
         | 
| 12 | 
            +
                      o << "\n"
         | 
| 13 | 
            +
                      o << v + "\n"
         | 
| 14 | 
            +
                      o << "\n"
         | 
| 15 | 
            +
                    end
         | 
| 16 | 
            +
                    o << CodeBlock.new(body).to_md
         | 
| 17 | 
            +
                    if v = element.head["comment"]
         | 
| 18 | 
            +
                      o << "\n"
         | 
| 19 | 
            +
                      o << v + "\n"
         | 
| 20 | 
            +
                      o << "\n"
         | 
| 21 | 
            +
                    end
         | 
| 22 | 
            +
                    o.join
         | 
| 15 23 | 
             
                  end
         | 
| 16 24 |  | 
| 17 25 | 
             
                  private
         | 
| 18 26 |  | 
| 19 27 | 
             
                  def body
         | 
| 20 | 
            -
                    element.body.gsub( | 
| 28 | 
            +
                    element.body.gsub(%r{(#|//)$}, "")
         | 
| 21 29 | 
             
                  end
         | 
| 22 30 | 
             
                end
         | 
| 23 31 | 
             
              end
         | 
| @@ -1,12 +1,12 @@ | |
| 1 1 | 
             
            module Source2MD
         | 
| 2 2 | 
             
              module Formatter
         | 
| 3 | 
            -
                class  | 
| 3 | 
            +
                class TypeNop < Base
         | 
| 4 4 | 
             
                  def self.accept?(element)
         | 
| 5 | 
            -
                    element.head | 
| 5 | 
            +
                    element.head["nop"]
         | 
| 6 6 | 
             
                  end
         | 
| 7 7 |  | 
| 8 8 | 
             
                  def to_md
         | 
| 9 | 
            -
                     | 
| 9 | 
            +
                    ""
         | 
| 10 10 | 
             
                  end
         | 
| 11 11 | 
             
                end
         | 
| 12 12 | 
             
              end
         | 
| @@ -2,7 +2,7 @@ module Source2MD | |
| 2 2 | 
             
              module Formatter
         | 
| 3 3 | 
             
                class TypeSourceBlock < Base
         | 
| 4 4 | 
             
                  def self.accept?(element)
         | 
| 5 | 
            -
                    element.body. | 
| 5 | 
            +
                    element.body.match?(%r{(?:#|//)\+BEGIN_SRC})
         | 
| 6 6 | 
             
                  end
         | 
| 7 7 |  | 
| 8 8 | 
             
                  def to_md
         | 
| @@ -15,12 +15,12 @@ module Source2MD | |
| 15 15 | 
             
                  private
         | 
| 16 16 |  | 
| 17 17 | 
             
                  def body
         | 
| 18 | 
            -
                    element.body.match( | 
| 18 | 
            +
                    element.body.match(%r{(?:#|//)\+BEGIN_SRC.*?\R(.*)(?:#|//)\+END_SRC}m).captures.first
         | 
| 19 19 | 
             
                  end
         | 
| 20 20 |  | 
| 21 21 | 
             
                  def code_block_desc
         | 
| 22 | 
            -
                    if md = element.body.match( | 
| 23 | 
            -
                      md.captures.first | 
| 22 | 
            +
                    if md = element.body.match(%r{(?:#|//)\+BEGIN_SRC (.+)\R})
         | 
| 23 | 
            +
                      md.captures.first
         | 
| 24 24 | 
             
                    end
         | 
| 25 25 | 
             
                  end
         | 
| 26 26 |  | 
| @@ -2,15 +2,15 @@ module Source2MD | |
| 2 2 | 
             
              module Formatter
         | 
| 3 3 | 
             
                class TypeTable < Base
         | 
| 4 4 | 
             
                  def self.accept?(element)
         | 
| 5 | 
            -
                    !element.body.empty? && element.body.lines.all? { |e| e.match?( | 
| 5 | 
            +
                    !element.body.empty? && element.body.lines.all? { |e| e.match?(%r{^\s*(#|//) \|.*\|$}) }
         | 
| 6 6 | 
             
                  end
         | 
| 7 7 |  | 
| 8 8 | 
             
                  def to_md
         | 
| 9 9 | 
             
                    element.body
         | 
| 10 | 
            -
                      .remove( | 
| 11 | 
            -
                      .remove(/\A\|-.*?-\|\R | 
| 12 | 
            -
                      .remove(/^\|-.*?-\|\z/)
         | 
| 13 | 
            -
                      .gsub(/-\+-/, "-|-") | 
| 10 | 
            +
                      .remove(%r{^\s*(#|//) })
         | 
| 11 | 
            +
                      .remove(/\A\|-.*?-\|\R/)  # top
         | 
| 12 | 
            +
                      .remove(/^\|-.*?-\|\R\z/) # bottom
         | 
| 13 | 
            +
                      .gsub(/-\+-/, "-|-")
         | 
| 14 14 | 
             
                  end
         | 
| 15 15 | 
             
                end
         | 
| 16 16 | 
             
              end
         | 
| @@ -3,10 +3,12 @@ module Source2MD | |
| 3 3 | 
             
                class TypeText < Base
         | 
| 4 4 | 
             
                  # "# xxx"
         | 
| 5 5 | 
             
                  # "#"
         | 
| 6 | 
            -
                  REGEXP =  | 
| 6 | 
            +
                  REGEXP = %r{^\s*(?:#|//)( |$)}
         | 
| 7 7 |  | 
| 8 8 | 
             
                  def self.accept?(element)
         | 
| 9 | 
            -
                    element.body. | 
| 9 | 
            +
                    if element.body.present?
         | 
| 10 | 
            +
                      element.body.lines.all? { |e| e.match?(REGEXP) }
         | 
| 11 | 
            +
                    end
         | 
| 10 12 | 
             
                  end
         | 
| 11 13 |  | 
| 12 14 | 
             
                  def to_md
         | 
| @@ -26,7 +28,7 @@ module Source2MD | |
| 26 28 | 
             
                    if element.head["hankaku_kana"] == "true"
         | 
| 27 29 | 
             
                      s = TextHelper.hankaku_kana(s)
         | 
| 28 30 | 
             
                    end
         | 
| 29 | 
            -
                    s
         | 
| 31 | 
            +
                    TextHelper.eol_enter(s)
         | 
| 30 32 | 
             
                  end
         | 
| 31 33 | 
             
                end
         | 
| 32 34 | 
             
              end
         | 
    
        data/lib/source2md/generator.rb
    CHANGED
    
    
    
        data/lib/source2md/scanner.rb
    CHANGED
    
    | @@ -4,7 +4,7 @@ module Source2MD | |
| 4 4 |  | 
| 5 5 | 
             
                SRC_BEGIN_KEY = "BEGIN_SRC"
         | 
| 6 6 | 
             
                SRC_END_KEY   = "END_SRC"
         | 
| 7 | 
            -
                SRC_BLOCK_RE  =  | 
| 7 | 
            +
                SRC_BLOCK_RE  = %r{^\s*(?:#|//)\+#{SRC_BEGIN_KEY}.*?^\s*(?:#|//)\+#{SRC_END_KEY}}m
         | 
| 8 8 |  | 
| 9 9 | 
             
                NORMAL_BLOCK_RE = /.*?#{SEPARATOR}/m
         | 
| 10 10 |  | 
| @@ -19,12 +19,12 @@ module Source2MD | |
| 19 19 |  | 
| 20 20 | 
             
                def to_a
         | 
| 21 21 | 
             
                  v = @content
         | 
| 22 | 
            +
                  v = v.rstrip + "\n\n"
         | 
| 22 23 | 
             
                  if Source2MD.xmp_out_exclude
         | 
| 23 | 
            -
                    v = v.remove( | 
| 24 | 
            +
                    v = v.remove(%r{^(?:#|//) >>.*$})
         | 
| 24 25 | 
             
                  end
         | 
| 25 | 
            -
                  v = v + "\n\n"
         | 
| 26 26 | 
             
                  v = v.scan(PARAGRAPH_RE)
         | 
| 27 | 
            -
                  v = v.collect | 
| 27 | 
            +
                  v = v.collect { |e| e.rstrip + "\n" }
         | 
| 28 28 | 
             
                  v = v.find_all(&:present?)
         | 
| 29 29 | 
             
                end
         | 
| 30 30 | 
             
              end
         | 
| @@ -6,10 +6,6 @@ module Source2MD | |
| 6 6 | 
             
                  text.gsub(/\n{3,}/, "\n\n")
         | 
| 7 7 | 
             
                end
         | 
| 8 8 |  | 
| 9 | 
            -
                def add_newline_at_end_of_text(text)
         | 
| 10 | 
            -
                  text.strip + "\n"
         | 
| 11 | 
            -
                end
         | 
| 12 | 
            -
             | 
| 13 9 | 
             
                def oneline(text)
         | 
| 14 10 | 
             
                  text.remove(/\R+/)
         | 
| 15 11 | 
             
                end
         | 
| @@ -21,5 +17,18 @@ module Source2MD | |
| 21 17 | 
             
                def hankaku_kana(text)
         | 
| 22 18 | 
             
                  NKF.nkf("-wxZ4", text)
         | 
| 23 19 | 
             
                end
         | 
| 20 | 
            +
             | 
| 21 | 
            +
                def indent(text)
         | 
| 22 | 
            +
                  text.gsub(/^/, "  ")
         | 
| 23 | 
            +
                end
         | 
| 24 | 
            +
             | 
| 25 | 
            +
                def eol_enter(text)
         | 
| 26 | 
            +
                  text.rstrip + "\n"
         | 
| 27 | 
            +
                end
         | 
| 28 | 
            +
             | 
| 29 | 
            +
                def space_prefix_remove(text)
         | 
| 30 | 
            +
                  min = text.lines.reject(&:blank?).collect { |e| e.slice(/^\s*/).size }.min
         | 
| 31 | 
            +
                  text.remove(/^ {#{min}}/)
         | 
| 32 | 
            +
                end
         | 
| 24 33 | 
             
              end
         | 
| 25 34 | 
             
            end
         | 
    
        data/lib/source2md/version.rb
    CHANGED
    
    
    
        data/lib/source2md.rb
    CHANGED
    
    
    
        data/spec/code_block_spec.rb
    CHANGED
    
    
| @@ -6,7 +6,7 @@ module Source2MD | |
| 6 6 | 
             
                  actual = Element.new(<<~EOS).to_md
         | 
| 7 7 | 
             
            #+code_include: #{__dir__}/sample.yml
         | 
| 8 8 | 
             
            EOS
         | 
| 9 | 
            -
                  actual.should == <<~EOS | 
| 9 | 
            +
                  actual.should == <<~EOS
         | 
| 10 10 | 
             
            ```yml:sample.yml
         | 
| 11 11 | 
             
            (yaml)
         | 
| 12 12 | 
             
            ```
         | 
| @@ -19,7 +19,7 @@ EOS | |
| 19 19 | 
             
            #+lang: (lang)
         | 
| 20 20 | 
             
            #+name: (name)
         | 
| 21 21 | 
             
            EOS
         | 
| 22 | 
            -
                  actual.should == <<~EOS | 
| 22 | 
            +
                  actual.should == <<~EOS
         | 
| 23 23 | 
             
            ```(lang):(name)
         | 
| 24 24 | 
             
            (yaml)
         | 
| 25 25 | 
             
            ```
         | 
| @@ -30,7 +30,7 @@ EOS | |
| 30 30 | 
             
                  actual = Element.new(<<~EOS).to_md
         | 
| 31 31 | 
             
            #+code_include: #{__dir__}/sample.yml yaml:filename
         | 
| 32 32 | 
             
            EOS
         | 
| 33 | 
            -
                  actual.should == <<~EOS | 
| 33 | 
            +
                  actual.should == <<~EOS
         | 
| 34 34 | 
             
            ```yaml:filename
         | 
| 35 35 | 
             
            (yaml)
         | 
| 36 36 | 
             
            ```
         | 
| @@ -3,7 +3,7 @@ require "spec_helper" | |
| 3 3 | 
             
            module Source2MD
         | 
| 4 4 | 
             
              describe do
         | 
| 5 5 | 
             
                it "works" do
         | 
| 6 | 
            -
                  actual = Element.new(<<~EOS).to_md
         | 
| 6 | 
            +
                  actual = Element.new(TextHelper.indent(<<~EOS)).to_md
         | 
| 7 7 | 
             
            #+name: (name)
         | 
| 8 8 | 
             
            #+desc: (desc)
         | 
| 9 9 | 
             
            #+comment: (comment)
         | 
| @@ -11,7 +11,7 @@ module Source2MD | |
| 11 11 | 
             
            #
         | 
| 12 12 | 
             
            (code2)
         | 
| 13 13 | 
             
            EOS
         | 
| 14 | 
            -
                  actual.should == <<~EOS | 
| 14 | 
            +
                  actual.should == <<~EOS
         | 
| 15 15 | 
             
            ### (name) ###
         | 
| 16 16 |  | 
| 17 17 | 
             
            (desc)
         | 
| @@ -23,6 +23,7 @@ EOS | |
| 23 23 | 
             
            ```
         | 
| 24 24 |  | 
| 25 25 | 
             
            (comment)
         | 
| 26 | 
            +
             | 
| 26 27 | 
             
                  EOS
         | 
| 27 28 | 
             
                end
         | 
| 28 29 | 
             
              end
         | 
| @@ -8,7 +8,7 @@ module Source2MD | |
| 8 8 | 
             
                  (foo)
         | 
| 9 9 | 
             
                  #+END_SRC
         | 
| 10 10 | 
             
                  EOS
         | 
| 11 | 
            -
                  actual.should == <<~EOS | 
| 11 | 
            +
                  actual.should == <<~EOS
         | 
| 12 12 | 
             
            ```ruby
         | 
| 13 13 | 
             
            (foo)
         | 
| 14 14 | 
             
            ```
         | 
| @@ -21,7 +21,7 @@ module Source2MD | |
| 21 21 | 
             
                  (foo)
         | 
| 22 22 | 
             
                  #+END_SRC
         | 
| 23 23 | 
             
                  EOS
         | 
| 24 | 
            -
                  actual.should == <<~EOS | 
| 24 | 
            +
                  actual.should == <<~EOS
         | 
| 25 25 | 
             
            ```diff xxx:yyy
         | 
| 26 26 | 
             
            (foo)
         | 
| 27 27 | 
             
            ```
         | 
| @@ -11,7 +11,7 @@ module Source2MD | |
| 11 11 | 
             
            # | d | d | d |
         | 
| 12 12 | 
             
            # |---+---+---|
         | 
| 13 13 | 
             
            EOS
         | 
| 14 | 
            -
                  actual.should == <<~EOS | 
| 14 | 
            +
                  actual.should == <<~EOS
         | 
| 15 15 | 
             
            | h | h | h |
         | 
| 16 16 | 
             
            |---|---|---|
         | 
| 17 17 | 
             
            | d | d | d |
         | 
| @@ -25,7 +25,7 @@ EOS | |
| 25 25 | 
             
            # |---+---+---|
         | 
| 26 26 | 
             
            # | d | d | d |
         | 
| 27 27 | 
             
            EOS
         | 
| 28 | 
            -
                  actual.should == <<~EOS | 
| 28 | 
            +
                  actual.should == <<~EOS
         | 
| 29 29 | 
             
            | h | h | h |
         | 
| 30 30 | 
             
            |---|---|---|
         | 
| 31 31 | 
             
            | d | d | d |
         | 
| @@ -3,11 +3,12 @@ require "spec_helper" | |
| 3 3 | 
             
            module Source2MD
         | 
| 4 4 | 
             
              describe do
         | 
| 5 5 | 
             
                it "works" do
         | 
| 6 | 
            +
                  # Source2MD.logger.level = :debug
         | 
| 6 7 | 
             
                  actual = Element.new(<<~EOS).to_md
         | 
| 7 8 | 
             
            # - foo
         | 
| 8 9 | 
             
            #   http://example.com/
         | 
| 9 10 | 
             
            EOS
         | 
| 10 | 
            -
                  actual.should == <<~EOS | 
| 11 | 
            +
                  actual.should == <<~EOS
         | 
| 11 12 | 
             
            - foo
         | 
| 12 13 | 
             
              http://example.com/
         | 
| 13 14 | 
             
            EOS
         | 
| @@ -22,7 +23,7 @@ EOS | |
| 22 23 | 
             
            # c
         | 
| 23 24 | 
             
            # d
         | 
| 24 25 | 
             
            EOS
         | 
| 25 | 
            -
                  actual.should == <<~EOS | 
| 26 | 
            +
                  actual.should == <<~EOS
         | 
| 26 27 | 
             
            abcd
         | 
| 27 28 | 
             
            EOS
         | 
| 28 29 | 
             
                end
         | 
| @@ -36,7 +37,7 @@ EOS | |
| 36 37 | 
             
            # c
         | 
| 37 38 | 
             
            # d
         | 
| 38 39 | 
             
            EOS
         | 
| 39 | 
            -
                  actual.should == <<~EOS | 
| 40 | 
            +
                  actual.should == <<~EOS
         | 
| 40 41 | 
             
            a b c d
         | 
| 41 42 | 
             
            EOS
         | 
| 42 43 | 
             
                end
         | 
| @@ -46,7 +47,7 @@ EOS | |
| 46 47 | 
             
            #+hankaku_kana: true
         | 
| 47 48 | 
             
            # アア
         | 
| 48 49 | 
             
            EOS
         | 
| 49 | 
            -
                  actual.should == " | 
| 50 | 
            +
                  actual.should == "アア\n"
         | 
| 50 51 | 
             
                end
         | 
| 51 52 | 
             
              end
         | 
| 52 53 | 
             
            end
         | 
    
        data/spec/scanner_spec.rb
    CHANGED
    
    | @@ -21,13 +21,23 @@ module Source2MD | |
| 21 21 | 
             
                  foo
         | 
| 22 22 | 
             
                  EOS
         | 
| 23 23 |  | 
| 24 | 
            -
                  ary | 
| 25 | 
            -
                  assert { ary == ["foo", "#+BEGIN_SRC\n\nfoo\n\n#+END_SRC", "foo", "#+BEGIN_SRC\nfoo\n#+END_SRC", "foo"] }
         | 
| 24 | 
            +
                  assert { ary == ["foo\n", "#+BEGIN_SRC\n\nfoo\n\n#+END_SRC\n", "foo\n", "#+BEGIN_SRC\nfoo\n#+END_SRC\n", "foo\n"] }
         | 
| 26 25 | 
             
                end
         | 
| 27 26 | 
             
              end
         | 
| 28 27 | 
             
            end
         | 
| 29 | 
            -
            # >>  | 
| 28 | 
            +
            # >> F
         | 
| 30 29 | 
             
            # >> 
         | 
| 31 | 
            -
            # >>  | 
| 32 | 
            -
            # >>  | 
| 30 | 
            +
            # >> Failures:
         | 
| 31 | 
            +
            # >> 
         | 
| 32 | 
            +
            # >>   1) Source2MD::Scanner works
         | 
| 33 | 
            +
            # >>      Failure/Error: Unable to find - to read failed line
         | 
| 34 | 
            +
            # >>      Test::Unit::AssertionFailedError:
         | 
| 35 | 
            +
            # >>      # -:25:in `block (2 levels) in <module:Source2MD>'
         | 
| 36 | 
            +
            # >> 
         | 
| 37 | 
            +
            # >> Finished in 0.01112 seconds (files took 0.26074 seconds to load)
         | 
| 38 | 
            +
            # >> 1 example, 1 failure
         | 
| 39 | 
            +
            # >> 
         | 
| 40 | 
            +
            # >> Failed examples:
         | 
| 41 | 
            +
            # >> 
         | 
| 42 | 
            +
            # >> rspec -:5 # Source2MD::Scanner works
         | 
| 33 43 | 
             
            # >> 
         | 
    
        data/spec/text_helper_spec.rb
    CHANGED
    
    | @@ -6,14 +6,18 @@ 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 " | 
| 10 | 
            -
                  assert { TextHelper. | 
| 11 | 
            -
                  assert { TextHelper. | 
| 12 | 
            -
                  assert { TextHelper.add_newline_at_end_of_text("A\n\n") == "A\n" }
         | 
| 9 | 
            +
                it "eol_enter" do
         | 
| 10 | 
            +
                  assert { TextHelper.eol_enter("A") == "A\n"     }
         | 
| 11 | 
            +
                  assert { TextHelper.eol_enter("A\n\n") == "A\n" }
         | 
| 13 12 | 
             
                end
         | 
| 14 13 |  | 
| 15 14 | 
             
                it "hankaku_kana" do
         | 
| 16 15 | 
             
                  assert { TextHelper.hankaku_kana("アア") == "アア" }
         | 
| 17 16 | 
             
                end
         | 
| 17 | 
            +
             | 
| 18 | 
            +
                it "space_prefix_remove" do
         | 
| 19 | 
            +
                  assert { TextHelper.space_prefix_remove(" a\n  b\n") == "a\n b\n" }
         | 
| 20 | 
            +
                  assert { TextHelper.space_prefix_remove(" a\n\n  b\n") == "a\n\n b\n" }
         | 
| 21 | 
            +
                end
         | 
| 18 22 | 
             
              end
         | 
| 19 23 | 
             
            end
         | 
    
        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. | 
| 4 | 
            +
              version: 0.0.10
         | 
| 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-08- | 
| 11 | 
            +
            date: 2023-08-12 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: activesupport
         | 
| @@ -177,7 +177,6 @@ files: | |
| 177 177 | 
             
            - examples/type_alert.rb
         | 
| 178 178 | 
             
            - examples/type_code_include.rb
         | 
| 179 179 | 
             
            - examples/type_hidden.rb
         | 
| 180 | 
            -
            - examples/type_md_title.rb
         | 
| 181 180 | 
             
            - examples/type_method.rb
         | 
| 182 181 | 
             
            - examples/type_partial_code.rb
         | 
| 183 182 | 
             
            - examples/type_source_block.rb
         | 
| @@ -194,8 +193,8 @@ files: | |
| 194 193 | 
             
            - lib/source2md/formatter/type_code_include.rb
         | 
| 195 194 | 
             
            - lib/source2md/formatter/type_else.rb
         | 
| 196 195 | 
             
            - lib/source2md/formatter/type_hidden.rb
         | 
| 197 | 
            -
            - lib/source2md/formatter/type_md_title.rb
         | 
| 198 196 | 
             
            - lib/source2md/formatter/type_method.rb
         | 
| 197 | 
            +
            - lib/source2md/formatter/type_nop.rb
         | 
| 199 198 | 
             
            - lib/source2md/formatter/type_parse_include.rb
         | 
| 200 199 | 
             
            - lib/source2md/formatter/type_partial_code.rb
         | 
| 201 200 | 
             
            - lib/source2md/formatter/type_raw_include.rb
         | 
| @@ -219,7 +218,6 @@ files: | |
| 219 218 | 
             
            - spec/formatter/type_alert_spec.rb
         | 
| 220 219 | 
             
            - spec/formatter/type_code_include_spec.rb
         | 
| 221 220 | 
             
            - spec/formatter/type_hidden_spec.rb
         | 
| 222 | 
            -
            - spec/formatter/type_md_title_spec.rb
         | 
| 223 221 | 
             
            - spec/formatter/type_method_spec.rb
         | 
| 224 222 | 
             
            - spec/formatter/type_parse_include_spec.rb
         | 
| 225 223 | 
             
            - spec/formatter/type_partial_code_spec.rb
         | 
| @@ -261,7 +259,6 @@ test_files: | |
| 261 259 | 
             
            - spec/formatter/type_alert_spec.rb
         | 
| 262 260 | 
             
            - spec/formatter/type_code_include_spec.rb
         | 
| 263 261 | 
             
            - spec/formatter/type_hidden_spec.rb
         | 
| 264 | 
            -
            - spec/formatter/type_md_title_spec.rb
         | 
| 265 262 | 
             
            - spec/formatter/type_method_spec.rb
         | 
| 266 263 | 
             
            - spec/formatter/type_parse_include_spec.rb
         | 
| 267 264 | 
             
            - spec/formatter/type_partial_code_spec.rb
         | 
    
        data/examples/type_md_title.rb
    DELETED
    
    | @@ -1,15 +0,0 @@ | |
| 1 | 
            -
            #+hidden: true
         | 
| 2 | 
            -
            require "./setup"
         | 
| 3 | 
            -
             | 
| 4 | 
            -
            puts Source2MD::Element.new(<<~EOS).to_md
         | 
| 5 | 
            -
            ## foo ##
         | 
| 6 | 
            -
            EOS
         | 
| 7 | 
            -
            # >> > -------------------------------------------------------------------------------- Source2MD::Part::TypeMdTitle
         | 
| 8 | 
            -
            # >> > {}
         | 
| 9 | 
            -
            # >> > ------------------------------------------------------------ in
         | 
| 10 | 
            -
            # >> > ## foo ##
         | 
| 11 | 
            -
            # >> >
         | 
| 12 | 
            -
            # >> > ------------------------------------------------------------ out
         | 
| 13 | 
            -
            # >> > ## foo ##
         | 
| 14 | 
            -
            # >> > ------------------------------------------------------------
         | 
| 15 | 
            -
            # >> ## foo ##
         |