Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Switch to new gist URL format #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ JavaScript enabled or available. The resulting markup for the example below loo

<div class="highlight">
<div class="code">
<script src="https://gist.github.com/885179.js?file=example.htaccess.txt"></script>
<script src="https://gist.github.com/edelabar/885179.js?file=example.htaccess.txt"></script>
<noscript>
<pre><code class="apache">
<span class="nb">redirect</span> <span class="m">301</span> /?cat=1 http://www.somesite.com/
<span class="nb">redirect</span> <span class="m">301</span> /?cat=5 http://www.somesite.com/category/standards
</code></pre>
<p><a href="https://gist.github.com/885179">This Gist</a> hosted on <a href="http://github.com/">GitHub</a>.</p>
<p><a href="https://gist.github.com/edelabar/885179">This Gist</a> hosted on <a href="http://github.com/">GitHub</a>.</p>
</noscript>
</div>
</div>
Expand All @@ -28,15 +28,15 @@ Add jekyll-gist-tag.rb to the _plugins directory of your Jekyll site

Where:

gist_raw_url_with_filename is the gist's raw URL (e.g. https://gist.github.com/raw/885179/f030d8edd3e0cf45a9bfa6cea8979d7c006d7c4c/example.htaccess.txt)
gist_raw_url_with_filename is the gist's raw URL (e.g. https://gist.github.com/edelabar/885179/raw/f030d8edd3e0cf45a9bfa6cea8979d7c006d7c4c/example.htaccess.txt)

[pygments_lexer] is the optionally provided name of the pygments lexer for highlighting the code. If omitted, the file extension from the gist will be passed to pygments as the lexer.

The list of included lexers is available in the [Pygments documentation](http://pygments.org/docs/lexers).

## Example

{% render_gist https://gist.github.com/raw/885179/f030d8edd3e0cf45a9bfa6cea8979d7c006d7c4c/example.htaccess.txt apache %}
{% render_gist https://gist.github.com/edelabar/885179/raw/f030d8edd3e0cf45a9bfa6cea8979d7c006d7c4c/example.htaccess.txt apache %}

## Troubleshooting

Expand Down
17 changes: 9 additions & 8 deletions jekyll-gist-tag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ def initialize(tag_name, params, tokens)

url, specified_language = params.split(' ')

if %r|https://gist.github.com/raw/(.*)/.*/(.*\.([a-zA-Z]+))| =~ url
@gist = $1
@file = $2
file_language = $3
if %r|https://gist.github.com/(.*)/(.*)/raw/.*/(.*\.([a-zA-Z]+))| =~ url
@username = $1
@gist = $2
@file = $3
file_language = $4
else
$stderr.puts "Failed to parse gist URL '#{url}' from tag."
$stderr.puts "URL should be in the form 'https://gist.github.com/raw/1234/123456789abcdef/example.txt'"
$stderr.puts "URL should be in the form 'https://gist.github.com/<username>/12345/raw/4116128eb09ebc293bf9c11941dd1091671036b9/example.txt'"
exit(1);
end

Expand Down Expand Up @@ -51,11 +52,11 @@ def render_pygments(context, code, language)

def add_code_tags(code, language)
# Add nested <code> tags to code blocks
code = code.sub(/<pre>/,"<div class=\"gist\"><script src=\"https://gist.github.com/#{@gist}.js?file=#{@file}\"> </script><noscript><pre><code class=\"#{language}\">")
code = code.sub(/<\/pre>/,"</code></pre><p><a href=\"https://gist.github.com/#{@gist}\">This Gist</a> hosted on <a href=\"http://github.com/\">GitHub</a>.</p></noscript></div>")
code = code.sub(/<pre>/,"<div class=\"gist\"><script src=\"https://gist.github.com/#{@username}/#{@gist}.js?file=#{@file}\"> </script><noscript><pre><code class=\"#{language}\">")
code = code.sub(/<\/pre>/,"</code></pre><p><a href=\"https://gist.github.com/#{@username}/#{@gist}\">This Gist</a> hosted on <a href=\"http://github.com/\">GitHub</a>.</p></noscript></div>")
end

end
end

Liquid::Template.register_tag('render_gist', Jekyll::RenderGist)
Liquid::Template.register_tag('render_gist', Jekyll::RenderGist)