jdvp-codetabs-commonmark 0.1.3 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/jdvp-codetabs-commonmark.rb +28 -17
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9c4adff98dae5a51639e65482f45d0cc3e001c8241cba16b953ab3b1bc543d26
|
4
|
+
data.tar.gz: d5a1d2ee0f4f85194a1d8b2f9c82163631247e832c16f4a38acc6b5f181bd487
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 31252e262c0d4e48464c44ea1c4698c752abfe71ed4ab79adfd65334f1922499de3568dfe6d9ab899fb3041c0e97367280809830e4230ba18f88bbdc8fdc17af
|
7
|
+
data.tar.gz: 19dd9da254c7fa53894906ff5c25e73333299d8cd82eb4c9ada3cb4515e7242ddeef7fd76245731a9551a6d538c8d32f9459180fbe2a742fceaf0559b936ba02
|
@@ -4,22 +4,8 @@ require "jekyll"
|
|
4
4
|
require "securerandom"
|
5
5
|
|
6
6
|
class CodeTabsCustomerRenderer < JekyllCommonMarkCustomRenderer
|
7
|
-
@added_assets_links = false
|
8
7
|
@added_copy_snackbar = false
|
9
8
|
|
10
|
-
def render(node)
|
11
|
-
if node.type == :document
|
12
|
-
if (!@added_assets_links)
|
13
|
-
#Add references to the fonts, css, and js required
|
14
|
-
out("<link rel=\"stylesheet\" href=\"https://fonts.googleapis.com/css?family=Roboto+Mono\"/>")
|
15
|
-
out("<link rel=\"stylesheet\" href=\"JdvpCodeTabs-baseurl/assets/codeblock.css\"/>")
|
16
|
-
out("<script src=\"JdvpCodeTabs-baseurl/assets/codeblock.js\"></script>")
|
17
|
-
@added_assets_links = true
|
18
|
-
end
|
19
|
-
end
|
20
|
-
super(node)
|
21
|
-
end
|
22
|
-
|
23
9
|
def code_block(node)
|
24
10
|
#Determine what objects this code block is surrounded by.
|
25
11
|
previous_node_type = node&.previous&.type&.to_s
|
@@ -144,9 +130,31 @@ class Jekyll::Converters::Markdown
|
|
144
130
|
end
|
145
131
|
end
|
146
132
|
|
147
|
-
|
148
|
-
|
149
|
-
|
133
|
+
def get_resource_string(site)
|
134
|
+
return "<link rel=\"stylesheet\" href=\"https://fonts.googleapis.com/css?family=Roboto+Mono\"/>" +
|
135
|
+
"<link rel=\"stylesheet\" href=\"#{site.baseurl}/assets/codeblock.css\"/>" +
|
136
|
+
"<script src=\"#{site.baseurl}/assets/codeblock.js\"></script>"
|
137
|
+
end
|
138
|
+
|
139
|
+
def add_resource_links_in_html_head(site)
|
140
|
+
site_directory = "#{site.in_dest_dir("/")}"
|
141
|
+
|
142
|
+
# For every html file in the generated site
|
143
|
+
Dir.glob("**/*.html", base: site_directory).each do |file_name|
|
144
|
+
file_plus_path = "#{site_directory}#{file_name}"
|
145
|
+
|
146
|
+
# Check if the file contains a code switcher and skip it if it does not
|
147
|
+
if (!File.foreach(file_plus_path).grep(/code_switcher_container_parent/).any?)
|
148
|
+
next
|
149
|
+
end
|
150
|
+
|
151
|
+
# If the file has a code switcher and a head element, add the resource links to the end of the head element
|
152
|
+
if (File.foreach(file_plus_path).grep(/<\/head>/).any?)
|
153
|
+
File.write(file_plus_path, File.open(file_plus_path, &:read).sub("</head>","#{get_resource_string(site)}</head>"))
|
154
|
+
# Otherwise if it has a html element add a head element with the resource links
|
155
|
+
elsif (File.foreach(file_plus_path).grep(/<\/html>/).any?)
|
156
|
+
File.write(file_plus_path, File.open(file_plus_path, &:read).sub(/(<html.*>)/,"#{$1}<head>#{get_resource_string(site)}</head>"))
|
157
|
+
end
|
150
158
|
end
|
151
159
|
end
|
152
160
|
|
@@ -166,4 +174,7 @@ Jekyll::Hooks.register :site, :post_write do |site|
|
|
166
174
|
FileUtils.cp(copy_icon, "#{site.in_dest_dir("assets/icon_copy.svg")}")
|
167
175
|
theme_icon = File.expand_path("../../assets/icon_theme.svg", __FILE__)
|
168
176
|
FileUtils.cp(theme_icon, "#{site.in_dest_dir("assets/icon_theme.svg")}")
|
177
|
+
|
178
|
+
#Add CSS & JS references to files that use code tabs
|
179
|
+
add_resource_links_in_html_head(site)
|
169
180
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jdvp-codetabs-commonmark
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- JD Porterfield
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-01-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: securerandom
|