Skip to content

Commit

Permalink
add markdown link filter
Browse files Browse the repository at this point in the history
see #30
  • Loading branch information
inukshuk committed May 14, 2015
1 parent 2aaf416 commit 9ac906e
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 4 deletions.
59 changes: 59 additions & 0 deletions features/filter.feature
Expand Up @@ -71,3 +71,62 @@ Feature: BibTeX
And the "_site/scholar.html" file should exist
And I should not see "Programming Ruby" in "_site/scholar.html"
And I should see "The Ruby Programming Language" in "_site/scholar.html"

@tags @urls
Scenario: URLs as text
Given I have a scholar configuration with:
| key | value |
| source | ./_bibliography |
And I have a "_bibliography" directory
And I have a file "_bibliography/references.bib":
"""
@book{pickaxe,
title = {Programming Ruby 1.9: The Pragmatic Programmer's Guide},
author = {Thomas, Dave and Fowler, Chad and Hunt, Andy},
year = {2009},
edition = 3,
publisher = {Pragmatic Bookshelf},
url = {https://pragprog.com}
}
"""
And I have a page "scholar.html":
"""
---
---
{% bibliography %}
"""
When I run jekyll
Then the _site directory should exist
And the "_site/scholar.html" file should exist
And I should see "from https://pragprog.com" in "_site/scholar.html"

@tags @urls
Scenario: URLs as Markdown links
Given I have a scholar configuration with:
| key | value |
| source | ./_bibliography |
And I have the following BibTeX filters:
| latex |
| markdown |
And I have a "_bibliography" directory
And I have a file "_bibliography/references.bib":
"""
@book{pickaxe,
title = {Programming Ruby 1.9: The Pragmatic Programmer's Guide},
author = {Thomas, Dave and Fowler, Chad and Hunt, Andy},
year = {2009},
edition = 3,
publisher = {Pragmatic Bookshelf},
url = {https://pragprog.com}
}
"""
And I have a page "scholar.html":
"""
---
---
{% bibliography %}
"""
When I run jekyll
Then the _site directory should exist
And the "_site/scholar.html" file should exist
And I should see "from \[https://pragprog.com\]\(https://pragprog.com\)" in "_site/scholar.html"
14 changes: 10 additions & 4 deletions features/step_definitions/jekyll_steps.rb
Expand Up @@ -43,12 +43,18 @@
assert File.directory?(dir)
end

Then(/^I should see "(.*)" in "(.*)"$/) do |text, file|
assert_match Regexp.new(text), File.open(file).readlines.join
Then(/^I should see "(.*)" in "(.*)"$/) do |pattern, file|
text = File.open(file).readlines.join

assert_match Regexp.new(pattern), text,
"Pattern /#{pattern}/ not found in: #{text}"
end

Then(/^I should not see "(.*)" in "(.*)"$/) do |text, file|
assert !File.open(file).readlines.join.match(Regexp.new(text))
Then(/^I should not see "(.*)" in "(.*)"$/) do |pattern, file|
text = File.open(file).readlines.join

assert !text.match(Regexp.new(pattern)),
"Did not exptect /#{pattern}/ in: #{text}"
end


Expand Down
9 changes: 9 additions & 0 deletions features/step_definitions/scholar_steps.rb
Expand Up @@ -27,6 +27,15 @@
end
end

Given(/^I have the following BibTeX filters:$/) do |table|
File.open('_config.yml', 'a') do |f|
f.write(" bibtex_filters:\n")
table.raw.flatten.each do |row|
f.write(" - #{row}\n")
end
end
end

Then(/^"(.*)" should come before "(.*)" in "(.*)"$/) do |p1, p2, file|
data = File.open(file).readlines.join('')

Expand Down
2 changes: 2 additions & 0 deletions lib/jekyll/scholar.rb
Expand Up @@ -19,3 +19,5 @@
require 'jekyll/scholar/tags/quote'
require 'jekyll/scholar/tags/reference'
require 'jekyll/scholar/generators/details'

require 'jekyll/scholar/plugins/markdown_links'
14 changes: 14 additions & 0 deletions lib/jekyll/scholar/plugins/markdown_links.rb
@@ -0,0 +1,14 @@
# Contriubted by @mfenner
# See https://github.com/inukshuk/jekyll-scholar/issues/30

require 'uri'

module Jekyll
class Scholar
class Markdown < BibTeX::Filter
def apply(value)
value.to_s.gsub(URI.regexp(['http','https','ftp'])) { |c| "[#{$&}](#{$&})" }
end
end
end
end

0 comments on commit 9ac906e

Please sign in to comment.