From 72f9e888c150f9e20c4293d97bca6656c2478afa Mon Sep 17 00:00:00 2001 From: Maxime Vaillancourt Date: Mon, 23 Aug 2021 19:39:07 -0400 Subject: [PATCH] Highlight content wrapped with == --- _notes/your-first-note.md | 2 ++ _plugins/markdown-highlighter.rb | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 _plugins/markdown-highlighter.rb diff --git a/_notes/your-first-note.md b/_notes/your-first-note.md index b93c1c5..c9018fe 100644 --- a/_notes/your-first-note.md +++ b/_notes/your-first-note.md @@ -73,6 +73,8 @@ And of course, images look great: +You can also ==highlight some content== by wrapping it with `==`. + ### Code syntax highlighting You can add code blocks with full syntax color highlighting by wrapping code snippet in triple backticks and specifying the type of the code (`js`, `rb`, `sh`, etc.): diff --git a/_plugins/markdown-highlighter.rb b/_plugins/markdown-highlighter.rb new file mode 100644 index 0000000..6630d00 --- /dev/null +++ b/_plugins/markdown-highlighter.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +# Turns ==something== in Markdown to something in output HTML + +Jekyll::Hooks.register [:notes], :post_convert do |doc| + replace(doc) +end + +Jekyll::Hooks.register [:pages], :post_convert do |doc| + # jekyll considers anything at the root as a page, + # we only want to consider actual pages + next unless doc.path.start_with?('_pages/') + replace(doc) +end + +def replace(doc) + doc.content.gsub!(/==+(\w(.*?)?[^ .=]?)==+/, "\\1") +end