Sha256: 1463457bffc11de16749143ea19ca4f1afdf90be5106527c04a06f065a7e4f6a
Contents?: true
Size: 855 Bytes
Versions: 7
Compression:
Stored size: 855 Bytes
Contents
# Delete extra blank lines inside ~~~~~ code bloks # # rubocop:disable MethodLength module Mdoc class Processor class SmartCodeBlock < Processor def process!(doc) odd, last, hold = false, false, 0 new_body = '' doc.body.split(/\n/).each do |line| if line =~ /^\s*~{3,}\s*\w*\s*/ hold = 0 if odd odd = odd ? false : true last = true else next if last && odd && (line =~ /^\s*$/) if line =~ /^\s*$/ hold += 1 # hold the line next end last = false end hold.times { new_body << "\n" } hold = 0 new_body << line << "\n" end doc.body = new_body.chomp # puts doc.body end end end end # rubocop:enable MethodLength
Version data entries
7 entries across 7 versions & 1 rubygems