Skip to content

Commit

Permalink
Merge pull request #269 from perseoGI/vendor-package
Browse files Browse the repository at this point in the history
Added vendored package blog post
  • Loading branch information
memsharded authored Jul 9, 2024
2 parents cfcd256 + d129bdb commit eb97607
Show file tree
Hide file tree
Showing 9 changed files with 526 additions and 0 deletions.
27 changes: 27 additions & 0 deletions _plugins/inline_highlight.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# jekyll_inline_highlight
#
# A Liquid tag for inline syntax highlighting in Jekyll
#
# https://github.com/bdesham/inline_highlight
#
# Copyright (c) 2014-2015, Tom Preston-Werner and Benjamin Esham
# See README.md for full copyright information.

module Jekyll
class InlineHighlightBlock < Tags::HighlightBlock

def add_code_tag(code)
code_attributes = [
"class=\"highlight language-#{@lang.to_s.gsub("+", "-")}\"",
"data-lang=\"#{@lang.to_s}\""
].join(" ")
"<code #{code_attributes}>#{code.chomp.strip}</code>"
end

def render(context)
super.strip
end
end
end

Liquid::Template.register_tag("ihighlight", Jekyll::InlineHighlightBlock)
29 changes: 29 additions & 0 deletions _plugins/line_highlighting.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Monkey-patch to allow highlighting lines
# PerseoGI: this is provisional until Jekyll 4.4 gets released which incorporates this feature
# Used same parameter (mark_lines) as in https://github.com/jekyll/jekyll/pull/9138
#
# Notice a `.hll` style must be defined in your CSS to highlight the lines
module Jekyll
module Tags
class HighlightBlock
def render_rouge(code)
require "rouge"

formatter = Rouge::Formatters::HTMLLineHighlighter.new(
::Rouge::Formatters::HTML.new,
highlight_lines: parse_highlighted_lines(@highlight_options[:mark_lines])
)
lexer = ::Rouge::Lexer.find_fancy(@lang, code) || Rouge::Lexers::PlainText
formatter.format(lexer.lex(code))
end

private

def parse_highlighted_lines(lines_string)
return [] if lines_string.nil?

lines_string.map(&:to_i)
end
end
end
end
22 changes: 22 additions & 0 deletions _plugins/md_hl_syntax_to_liquid.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# frozen_string_literal: true

# Convert markdown highlight lines feature syntax to liquid syntax
# Author: https://github.com/jekyll/jekyll/issues/8621#issuecomment-839184339
# Usage:
# ```py{1 2-3}
# def foo():
# print("Hello World")
# a = 42
# ```

Jekyll::Hooks.register(:documents, :pre_render) do |document, payload|
docExt = document.extname.tr(".", "")

# only process if we deal with a markdown file
if payload["site"]["markdown_ext"].include?(docExt)
document.content.gsub!(
/^\`\`\`([A-z]+){([\d\s]+)}$(.*?)^\`\`\`$/im,
"{% highlight \\1 mark_lines=\"\\2\" %}\\3{% endhighlight %}"
)
end
end
Loading

0 comments on commit eb97607

Please sign in to comment.