Skip to content

Commit

Permalink
Merge pull request #31 from nebulab/elia/yaml-front-matter
Browse files Browse the repository at this point in the history
Use YAML to parse the front matter
  • Loading branch information
elia authored Oct 25, 2023
2 parents 758dc28 + e35ec1a commit abb40fc
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions lib/erb/formatter.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# frozen_string_literal: false

require 'pp'
require "erb"
require "ripper"
require 'securerandom'
require 'erb'
require 'yaml'
require 'strscan'
require 'stringio'
require 'securerandom'
require 'erb/formatter/version'

require 'syntax_tree'
Expand Down Expand Up @@ -104,10 +104,13 @@ def initialize(source, line_width: 80, filename: nil, debug: $DEBUG)
end

def remove_front_matter(source)
source.sub(/\A---\n[\s\S]*?\n---\n/) do |match|
@front_matter = match
match.gsub(/[^\n]/, ' ')
end
return source unless source.start_with?("---\n")

first_body_line = YAML.parse(source).children.first.end_line + 1
lines = source.lines

@front_matter = lines[0...first_body_line].join
lines[first_body_line..].join
end

attr_accessor \
Expand Down

0 comments on commit abb40fc

Please sign in to comment.