Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Square bracket support closes #42 #43

Merged
merged 7 commits into from
May 21, 2018
2 changes: 1 addition & 1 deletion lib/jekyll-relative-links/generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Generator < Jekyll::Generator
# Use Jekyll's native relative_url filter
include Jekyll::Filters::URLFilters

LINK_TEXT_REGEX = %r!([^\]]+)!
LINK_TEXT_REGEX = %r!(.*?)!
FRAGMENT_REGEX = %r!(#.+?)?!
INLINE_LINK_REGEX = %r!\[#{LINK_TEXT_REGEX}\]\(([^\)]+?)#{FRAGMENT_REGEX}\)!
REFERENCE_LINK_REGEX = %r!^\s*?\[#{LINK_TEXT_REGEX}\]: (.+?)#{FRAGMENT_REGEX}\s*?$!
Expand Down
4 changes: 4 additions & 0 deletions spec/fixtures/site/page.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@

[Another item](_items/some-subdir/another-item.md)

[[A link with square brackets]](another-page.md)

[\[A link with escaped square brackets\]](/another-page.md)

Content end

[reference]: another-page.md
Expand Down
10 changes: 10 additions & 0 deletions spec/jekyll-relative-links/generator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,16 @@
expect(page.content).to include("[Ghost page](ghost-page.md)")
end

it "handles links with nested square brackets" do
expected = "[[A link with square brackets]](/another-page.html)"
expect(page.content).to include(expected)
end

it "handles links with escaped nested square brackets" do
expected = "[\\[A link with escaped square brackets\\]](/another-page.html)"
expect(page.content).to include(expected)
end

context "reference links" do
it "handles reference links" do
expect(page.content).to include("[reference]: /another-page.html")
Expand Down