Skip to content

Commit da4ff26

Browse files
tjgrathwelldshafik
authored andcommitted
TOC: Skip markdown image links like ![cool image](cool_image.jpg)
1 parent e3e6654 commit da4ff26

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

lib/contents.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ def subpages_for filename
4141
content = content_for(filename)
4242

4343
# (markdown) links of the form: [link text](link_page)
44-
content.scan /\[.*?\]\((.*?)\)/ do |link, _|
44+
# but NOT images of the form ![alt text](image_link.jpg)
45+
content.scan /[^!]\[.*?\]\((.*?)\)/ do |link, _|
4546
next if (link =~ /^http/)
4647
next if (link =~ %r(^//)) # protocol-less absolute links e.g. //google.com
47-
next if (link =~ /\.\w{3}$/) # jpg/gif/svg/etc
4848
links.push(link) if !links.include? link
4949
end
5050

spec/sites/meals/clean_up.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Throw all your things away! ![garbage](garbage.jpg)
2+
3+
YOU'RE DONE!!
4+
5+
![successful person](success.jpg)

spec/sites/meals/clean_up.step

-3
This file was deleted.

0 commit comments

Comments
 (0)