From 1ba23c32c69ad70721615e5b5cb82aef34606534 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Wed, 20 Jan 2016 11:46:18 -0800 Subject: [PATCH] add Utils.strip_heredoc --- lib/jekyll/utils.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/jekyll/utils.rb b/lib/jekyll/utils.rb index 6e0023de..6dd2b117 100644 --- a/lib/jekyll/utils.rb +++ b/lib/jekyll/utils.rb @@ -10,6 +10,12 @@ module Jekyll SLUGIFY_DEFAULT_REGEXP = Regexp.new('[^[:alnum:]]+').freeze SLUGIFY_PRETTY_REGEXP = Regexp.new("[^[:alnum:]._~!$&'()+,;=@]+").freeze + # Takes an indented string and removes the preceding spaces on each line + + def strip_heredoc(str) + str.gsub(/^[ \t]{#{(str.scan(/^[ \t]*(?=\S)/).min || "").size}}/, "") + end + # Takes a slug and turns it into a simple title. def titleize_slug(slug)