Skip to content

Commit 0550a3a

Browse files
committed
feat(syntax): add support for liquid_tags.include_code plugin
fix #518
1 parent edba54f commit 0550a3a

7 files changed

Lines changed: 127 additions & 2 deletions

File tree

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
---
2+
Title: Code Snippets -- Include code from file
3+
Tags: code-snippets, plugins, liquid-tags
4+
Date: 2020-02-02 20:53
5+
comments: false
6+
Slug: code-snippets-include-code-from-file
7+
authors: Talha Mansoor
8+
Category: Supported Plugins
9+
---
10+
11+
Elegant supports [`liquid_tags.include_code` plugin](https://github.com/getpelican/pelican-plugins/tree/master/liquid_tags#include-code).
12+
13+
<!-- TODO: remove this warning after https://github.com/getpelican/pelican-plugins/pull/1243 is merged -->
14+
15+
!!! Warning "Pending Pull Request"
16+
17+
The demo you see here is dependent on [this
18+
patch](https://github.com/getpelican/pelican-plugins/pull/1243).
19+
20+
Until Pelican team merges the patch into plugins repository, you will have
21+
apply this patch manually to your copy of plugins.
22+
23+
## Example 1
24+
25+
{% include_code square-root.py lang:python Calculate square root of 8 %}
26+
27+
## Example 2 -- Without Filename
28+
29+
{% include_code alias-sed.fish :hidefilename: Fish Shell alias for sed %}
30+
31+
## Example 3 -- Without Download Link
32+
33+
{% include_code alias-sed.fish :hidelink: Fish Shell alias for sed %}
34+
35+
## Example 4 -- Without Filename and Download Link
36+
37+
{% include_code alias-sed.fish :hidefilename: :hidelink: Fish Shell alias for sed %}
38+
39+
## Example 3 -- Without Metadata
40+
41+
{% include_code square-root.js lang:js :hideall: Compute square-root %}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
function sed -d 'alias sed to gsed'
2+
command gsed $argv;
3+
end
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// From https://gist.github.com/joelpt/3824024
2+
//
3+
// The Babylonian Method
4+
// http://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method
5+
// @param n - the number to compute the square root of
6+
// @param g - the best guess so far (can omit from initial call)
7+
function squirt(n, g) {
8+
if (!g) {
9+
// Take an initial guess at the square root
10+
g = n / 2.0;
11+
}
12+
var d = n / g; // Divide our guess into the number
13+
var ng = (d + g) / 2.0; // Use average of g and d as our new guess
14+
if (g == ng) {
15+
// The new guess is the same as the old guess; further guesses
16+
// can get no more accurate so we return this guess
17+
return g;
18+
}
19+
// Recursively solve for closer and closer approximations of the square root
20+
return squirt(n, ng);
21+
}
22+
23+
console.log(squirt(42)); // 6.48074069840786
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# -*- coding: utf-8 -*-
2+
# Python Program to calculate the square root
3+
# Note: change this value for a different result
4+
num = 8
5+
# To take the input from the user
6+
# num = float(input('Enter a number: '))
7+
num_sqrt = num ** 0.5
8+
print("The square root of %0.3f is %0.3f" % (num, num_sqrt))

documentation/pelicanconf.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
PLUGINS = [
3030
"extract_toc",
3131
"liquid_tags.img",
32+
"liquid_tags.include_code",
3233
"neighbors",
3334
"related_posts",
3435
"render_math",
@@ -76,7 +77,7 @@
7677
)
7778

7879
# Elegant theme
79-
STATIC_PATHS = ["theme/images", "images", "extra/_redirects"]
80+
STATIC_PATHS = ["theme/images", "images", "extra/_redirects", "code"]
8081
EXTRA_PATH_METADATA = {"extra/_redirects": {"path": "_redirects"}}
8182

8283
if os.environ.get("CONTEXT") == "production":

documentation/tasks.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,11 @@ def plugins_sync(c):
118118
# For now we don't need submodules plugins. When we do, use
119119
# --recurse-submodules and --shallow-submodules switches
120120
# Do specify path in --recurse-submodules so that only relevant plugin is downloaded
121+
# TODO: switch back to getpelican repository after PR is merged
122+
# https://github.com/getpelican/pelican-plugins/pull/1243
123+
# "git clone --jobs 8 --depth 1 --shallow-submodules https://github.com/getpelican/pelican-plugins.git plugins"
121124
c.run(
122-
"git clone --jobs 8 --depth 1 --shallow-submodules https://github.com/getpelican/pelican-plugins.git plugins"
125+
"git clone --jobs 8 --depth 1 --shallow-submodules --single-branch --branch feat-liquid-tags-include-code https://github.com/talha131/pelican-plugins.git plugins"
123126
)
124127

125128

static/css/code.css

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,52 @@ pre {
1818
word-wrap: normal;
1919
color: #ebdbb2; /* This is needed due to bug in Pygments. It does not wraps some part of the code of some lagauges, like reST. This is for fallback. */
2020
}
21+
/* liquid_tags.include_code */
22+
figure.code {
23+
margin: 0;
24+
padding: 0;
25+
& figcaption {
26+
display: flex;
27+
flex-direction: row;
28+
flex-wrap: wrap;
29+
justify-content: space-between;
30+
align-items: center;
31+
border-radius: var(--borderRadius) var(--borderRadius) 0 0;
32+
background-color: #544c50;
33+
color: #ebdbb2;
34+
padding: 2px 9.5px;
35+
font-family: var(--sansFontFamily);
36+
& span.liquid-tags-code-title {
37+
flex-grow: 1;
38+
}
39+
& span.liquid-tags-code-filename {
40+
font-family: var(--monoFontFamily);
41+
color: #fe8019;
42+
}
43+
/* Download Link */
44+
& a {
45+
color: #b8bb26;
46+
text-transform: capitalize;
47+
position: relative;
48+
margin-left: 30px;
49+
&:before {
50+
display: inline-block;
51+
height: 18px;
52+
width: 18px;
53+
content: url("data:image/svg+xml,%3Csvg%20image-rendering%3D%22optimizeQuality%22%20shape-rendering%3D%22geometricPrecision%22%20text-rendering%3D%22geometricPrecision%22%20viewBox%3D%220%200%20294%20452.5%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Cg%20fill%3D%22%23b8bb26%22%3E%3Cpath%20d%3D%22m126%200h42v185h62l-83%20111-83-111h62z%22%2F%3E%3Cpath%20d%3D%22m294%20257v105c-98%200-196%200-294%200v-105h34v71h226v-71z%22%2F%3E%3C%2Fg%3E%3C%2Fsvg%3E%0A");
54+
margin: 0;
55+
padding: 0 4px 0 0;
56+
top: 4px;
57+
right: 100%;
58+
position: absolute;
59+
}
60+
}
61+
}
62+
& div.highlight:not(:first-child) {
63+
border-radius: 0 0 var(--borderRadius) var(--borderRadius);
64+
}
65+
}
66+
2167
table {
2268
table-layout: fixed;
2369
width: 100%;

0 commit comments

Comments
 (0)