Skip to content

Commit d331534

Browse files
committed
better/faster syntax highlighting
1 parent b2eafdb commit d331534

File tree

9 files changed

+411
-2358
lines changed

9 files changed

+411
-2358
lines changed

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,4 +137,4 @@ DEPENDENCIES
137137
yui-compressor
138138

139139
BUNDLED WITH
140-
2.1.4
140+
2.5.0

_config.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,13 @@ twitter_username: htmlcsstoimage.com
2828
github_username: htmlcsstoimage
2929
logo: "/assets/images/HCTI.png"
3030

31-
highlighter: none
31+
highlighter: rouge
32+
markdown: kramdown
33+
kramdown:
34+
syntax_highlighter: rouge
35+
syntax_highlighter_opts:
36+
block:
37+
line_numbers: false
3238

3339
# Build settings
3440
theme: just-the-docs

_layouts/default.html

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,8 @@ <h2 class="text-delta">Table of contents</h2>
159159
{% endif %}
160160
</div>
161161

162-
{% css_asset_tag prism %}
163-
- /assets/css/prism.css
164-
- /assets/css/search.css
165-
{% endcss_asset_tag %}
162+
<link href="/assets/css/syntax.css" rel="stylesheet" type="text/css" />
163+
<link href="/assets/css/search.css" rel="stylesheet" type="text/css" />
166164

167165
{% javascript_asset_tag global %}
168166
- /assets/js/just-the-docs.js
@@ -180,14 +178,25 @@ <h2 class="text-delta">Table of contents</h2>
180178
});
181179
</script>
182180

181+
<script src="/assets/js/clipboard.min.js"></script>
183182
<script>
184-
window.Prism = window.Prism || {};
185-
Prism.manual = true;
183+
// Add copy buttons to code blocks
184+
document.addEventListener('DOMContentLoaded', function() {
185+
document.querySelectorAll('.highlight').forEach(function(block) {
186+
var btn = document.createElement('button');
187+
btn.className = 'copy-btn';
188+
btn.textContent = 'Copy';
189+
btn.addEventListener('click', function() {
190+
var code = block.querySelector('code');
191+
navigator.clipboard.writeText(code.textContent).then(function() {
192+
btn.textContent = 'Copied!';
193+
setTimeout(function() { btn.textContent = 'Copy'; }, 2000);
194+
});
195+
});
196+
block.style.position = 'relative';
197+
block.appendChild(btn);
198+
});
199+
});
186200
</script>
187-
188-
{% javascript_asset_tag highlighting %}
189-
- /assets/js/prism.js
190-
- /assets/js/clipboard.min.js
191-
{% endjavascript_asset_tag %}
192201
</body>
193202
</html>

_plugins/jekyll_asset_pipeline.rb

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,8 @@ def self.filetype
99
def html
1010
file_path = "#{output_path}/#{@filename}"
1111

12-
if @filename.match? "jtd"
13-
return "<link href='#{file_path}' rel='stylesheet' " \
14-
"type='text/css' async />\n" \
15-
end
16-
17-
"<link href='#{file_path}' rel='preload' " \
18-
"type='text/css' async />\n" \
19-
"<link rel='preload' href='#{file_path}' as='style' onload=\"this.onload=null;this.rel='stylesheet'\"> " \
20-
"<noscript><link rel='stylesheet' href='#{file_path}'></noscript>"
12+
# Load all CSS files directly as stylesheets
13+
"<link href='#{file_path}' rel='stylesheet' type='text/css' />\n"
2114
end
2215
end
2316
end
@@ -43,8 +36,6 @@ def html
4336
module JekyllAssetPipeline
4437
class CssCompressor < JekyllAssetPipeline::Compressor
4538
require 'yui/compressor'
46-
require 'pry'
47-
require 'pry-byebug'
4839

4940
def self.filetype
5041
'.css'

_plugins/jeykll_html_css_to_image.rb

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
require "json"
2-
require 'pry'
3-
require 'pry-byebug'
42
require "htmlcsstoimage"
53

64
module Jekyll
@@ -13,12 +11,16 @@ def initialize(tag_name, input, tokens)
1311
end
1412

1513
def render(context)
14+
key = hcti_key(context)
15+
# Return placeholder for local development without API key
16+
return "https://via.placeholder.com/600x400?text=HCTI+Image+Placeholder" unless key
17+
1618
input = parse_input(@input, context)
1719
@template_id = input["template_id"]
1820
@template_params = input
1921
@template_params.delete("template_id")
2022

21-
client = HTMLCSSToImage.new(api_key: hcti_key(context))
23+
client = HTMLCSSToImage.new(api_key: key)
2224
image = client.create_image_from_template(template_id, @template_params)
2325

2426
image.url
@@ -36,7 +38,8 @@ def hcti_key(context)
3638
end
3739

3840
return key if key
39-
raise StandardError.new("Please set your HTML/CSS to Image API key")
41+
# Return nil for local development - the tag will return a placeholder
42+
nil
4043
end
4144

4245
def parse_input(input, context)

_sass/custom/custom.scss

Lines changed: 105 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,19 @@ img {
3535
.code-toolbar {
3636
position: relative;
3737
pre {
38-
background-color: #f5f6fa !important;
38+
background-color: #1e1e2e !important;
3939
}
4040
code {
4141
border: unset;
42+
color: #cdd6f4 !important;
4243
}
4344

4445
.toolbar-item {
4546
position: absolute;
4647
padding: 8px;
4748
top: 0px;
4849
right: 0px;
49-
color: $grey-dk-100;
50+
color: $grey-lt-100;
5051

5152
.success {
5253
svg {
@@ -56,6 +57,108 @@ img {
5657
}
5758
}
5859

60+
// Improved code block styling for better contrast
61+
pre[class*="language-"],
62+
code[class*="language-"] {
63+
background-color: #1e1e2e !important;
64+
color: #cdd6f4 !important;
65+
border: none !important;
66+
}
67+
68+
pre[class*="language-"] {
69+
border-radius: 6px;
70+
padding: 1rem !important;
71+
}
72+
73+
// Syntax highlighting colors (dark theme)
74+
.token.comment,
75+
.token.prolog,
76+
.token.doctype,
77+
.token.cdata {
78+
color: #6c7086 !important;
79+
}
80+
81+
.token.string,
82+
.token.attr-value {
83+
color: #a6e3a1 !important;
84+
}
85+
86+
.token.punctuation,
87+
.token.operator {
88+
color: #89dceb !important;
89+
}
90+
91+
.token.property,
92+
.token.tag,
93+
.token.boolean,
94+
.token.number,
95+
.token.constant,
96+
.token.symbol {
97+
color: #fab387 !important;
98+
}
99+
100+
.token.selector,
101+
.token.attr-name,
102+
.token.char,
103+
.token.builtin {
104+
color: #f9e2af !important;
105+
}
106+
107+
.token.keyword,
108+
.token.atrule {
109+
color: #cba6f7 !important;
110+
}
111+
112+
.token.function {
113+
color: #89b4fa !important;
114+
}
115+
116+
.token.url,
117+
.token.variable {
118+
color: #f38ba8 !important;
119+
}
120+
121+
// Bash/Shell specific syntax highlighting
122+
.language-bash,
123+
.language-shell,
124+
.language-sh {
125+
// Command names (curl, echo, etc.)
126+
.token.function {
127+
color: #89b4fa !important;
128+
font-weight: 600;
129+
}
130+
131+
// Flags and parameters (-X, -d, -u, --data-urlencode)
132+
.token.parameter,
133+
.token.variable {
134+
color: #f9e2af !important;
135+
}
136+
137+
// Strings (single and double quoted)
138+
.token.string {
139+
color: #a6e3a1 !important;
140+
}
141+
142+
// URLs
143+
.token.url {
144+
color: #89dceb !important;
145+
}
146+
147+
// Operators and punctuation
148+
.token.operator {
149+
color: #f38ba8 !important;
150+
}
151+
}
152+
153+
// Additional bash-specific token styling for better visibility
154+
pre[class*="language-bash"],
155+
pre[class*="language-shell"],
156+
pre[class*="language-sh"] {
157+
.token.assign-left {
158+
color: #cba6f7 !important;
159+
}
160+
}
161+
59162
.code-example {
60163
align-text: center;
61164
.hcti-container {

assets/css/prism.css

Lines changed: 0 additions & 122 deletions
This file was deleted.

0 commit comments

Comments
 (0)