xijo/reverse_markdown

Improper space parsing within codeblock

Closed this issue · 2 comments

The use of String#squeeze in the file below is messing with codeblock's indentation.

text.tr("\n\t", ' ').squeeze(' ')

I.E.

# Original code block
def original_value
  if assigned?
    original_attribute.original_value
  else
    type_cast(value_before_type_cast)
  end
end

# After ReverseMarkdown
def original_value
 if assigned?
 original_attribute.original_value
 else
 type_cast(value_before_type_cast)
 end
end
xijo commented

@maestromac Thanks for reporting. Can you provide a complete example of the problem.

The following looks ok for me:

code =<<~EOS
  <pre>
    <code>
      def original_value
        if assigned?
          original_attribute.original_value
        else
          type_cast(value_before_type_cast)
        end
      end
    </code>
  </pre>
EOS

puts ReverseMarkdown.convert(code)

        def original_value
          if assigned?
            original_attribute.original_value
          else
            type_cast(value_before_type_cast)
          end
        end

It's been a while so I'm having trouble recalling and providing the original item that caused this problem. One thing I do remember is that the code block may not have been wrapped in a pre/code tag.

Thanks for following up. Since we went ahead and monkey patched that method, I'm closing this issue.