From 01bbb8d49851d7da3d7f49dcac672d8ee5cb63fd Mon Sep 17 00:00:00 2001 From: Robin De Schepper Date: Fri, 27 Sep 2024 16:02:50 -0400 Subject: [PATCH] only process text outside of code blocks --- README.md | 4 +--- lib/README.md | 7 ------- lib/jekyll-gfm-admonitions.rb | 10 ++++++++++ 3 files changed, 11 insertions(+), 10 deletions(-) delete mode 100644 lib/README.md diff --git a/README.md b/README.md index 5e5038c..10c6fc7 100644 --- a/README.md +++ b/README.md @@ -165,13 +165,11 @@ Your markdown files should start like this. > [!IMPORTANT] > -> Your root `README.md` front matter should contain a `permalink` attribute: +> Your root `README.md` front matter should contain the following `permalink` attribute: > ```yaml > permalink: /index.html > ``` -Link to nested [README](./lib/README.md) - ## License This project is licensed under the MIT License. See the [LICENSE.txt](LICENSE.txt) file diff --git a/lib/README.md b/lib/README.md deleted file mode 100644 index 4489d47..0000000 --- a/lib/README.md +++ /dev/null @@ -1,7 +0,0 @@ ---- ---- - -# Test nested - -> [!IMPORTANT] -> Was this rendered? \ No newline at end of file diff --git a/lib/jekyll-gfm-admonitions.rb b/lib/jekyll-gfm-admonitions.rb index 2325d6b..d0f91ff 100644 --- a/lib/jekyll-gfm-admonitions.rb +++ b/lib/jekyll-gfm-admonitions.rb @@ -66,6 +66,12 @@ def self.admonition_pages end def convert_admonitions(doc) + code_blocks = [] + doc.content.gsub!(/```.*?```/m) do |match| + code_blocks << match + "```{{CODE_BLOCK_#{code_blocks.length - 1}}}```" + end + doc.content.gsub!(/>\s*\[!(IMPORTANT|NOTE|WARNING|TIP|CAUTION)\]\s*\n((?:>.*\n?)*)/) do type = ::Regexp.last_match(1).downcase title = type.capitalize @@ -78,6 +84,10 @@ def convert_admonitions(doc)

#{@markdown.convert(text)}

\n\n" end + + doc.content.gsub!(/```\{\{CODE_BLOCK_(\d+)}}```/) do + "```#{code_blocks[$1.to_i]}```" + end end end