-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #269 from perseoGI/vendor-package
Added vendored package blog post
- Loading branch information
Showing
9 changed files
with
526 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.