Skip to content

Commit

Permalink
Merge pull request #82 from markets/haml_6_support
Browse files Browse the repository at this point in the history
Add support for Haml 6
  • Loading branch information
tdreyno committed Jan 17, 2024
2 parents 6b7a777 + a047fa6 commit 0a8e205
Showing 1 changed file with 28 additions and 14 deletions.
42 changes: 28 additions & 14 deletions lib/middleman-syntax/haml_monkey_patch.rb
Original file line number Diff line number Diff line change
@@ -1,22 +1,36 @@
# If Haml is around, define a :code filter that can be used to more conveniently output highlighted code.

if defined? Haml
module Haml
module Filters
module Code
include Base
module HamlMonkeyPatch
def render(code)
code = code.rstrip
code = code.encode(Encoding::UTF_8)

def render(code)
code = code.rstrip
code = code.encode(Encoding::UTF_8)
# Allow language to be specified via a special comment like:
# # lang: ruby
if code.lines.first =~ /\A\s*#\s*lang:\s*(\w+)$/
language = $1
code = code.lines.to_a[1..-1].join # Strip first line
end

# Allow language to be specified via a special comment like:
# # lang: ruby
if code.lines.first =~ /\A\s*#\s*lang:\s*(\w+)$/
language = $1
code = code.lines.to_a[1..-1].join # Strip first line
end
Middleman::Syntax::Highlighter.highlight(code, language)
end
end

Middleman::Syntax::Highlighter.highlight(code, language)
if Gem::Version.new(Haml::VERSION) >= Gem::Version.new("6.0.0")
module Haml
class Filters
class Code < Base
extend HamlMonkeyPatch
end
end
end
else
module Haml
module Filters
module Code
include Base
extend HamlMonkeyPatch
end
end
end
Expand Down

0 comments on commit 0a8e205

Please sign in to comment.