aboutsummaryrefslogtreecommitdiff
path: root/_plugins/add-link-to-plaintext-code-block.rb
diff options
context:
space:
mode:
authorEuAndreh <eu@euandre.org>2020-08-17 09:19:34 -0300
committerEuAndreh <eu@euandre.org>2020-08-17 10:01:48 -0300
commit6cebae3ffa2ea2b364b0c39238ec7cea243cc2a7 (patch)
tree298238abfe44fa803f72c5367bbf8796bc25022d /_plugins/add-link-to-plaintext-code-block.rb
parentAdd scripts/missing-translations.sh (diff)
downloadeuandre.org-6cebae3ffa2ea2b364b0c39238ec7cea243cc2a7.tar.gz
euandre.org-6cebae3ffa2ea2b364b0c39238ec7cea243cc2a7.tar.xz
Generate plaintext links to raw code blocks
Generate txt files from code blocks embedded on pages, and add links to them.
Diffstat (limited to '_plugins/add-link-to-plaintext-code-block.rb')
-rw-r--r--_plugins/add-link-to-plaintext-code-block.rb14
1 files changed, 14 insertions, 0 deletions
diff --git a/_plugins/add-link-to-plaintext-code-block.rb b/_plugins/add-link-to-plaintext-code-block.rb
new file mode 100644
index 0000000..461102e
--- /dev/null
+++ b/_plugins/add-link-to-plaintext-code-block.rb
@@ -0,0 +1,14 @@
+# </code></pre></div></div>
+Jekyll::Hooks.register :documents, :post_render do |doc|
+ if doc.output_ext == ".html"
+ code_block_counter = 1
+ doc.output = doc.output.gsub(/(<\/code><\/pre><\/div><\/div>)/) do |match|
+ res = match +
+ '<div class="plaintext-link"><a href="' +
+ "#{doc.url}.#{code_block_counter}.txt" +
+ '">plaintext</a></div>'
+ code_block_counter += 1
+ res
+ end
+ end
+end