Commit 9ac906e3 authored by Sylvester Keil's avatar Sylvester Keil

add markdown link filter

see #30
parent 2aaf4168
...@@ -71,3 +71,62 @@ Feature: BibTeX ...@@ -71,3 +71,62 @@ Feature: BibTeX
And the "_site/scholar.html" file should exist And the "_site/scholar.html" file should exist
And I should not see "Programming Ruby" in "_site/scholar.html" And I should not see "Programming Ruby" in "_site/scholar.html"
And I should see "The Ruby Programming Language" 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"
...@@ -43,12 +43,18 @@ Then(/^the (.*) directory should exist$/) do |dir| ...@@ -43,12 +43,18 @@ Then(/^the (.*) directory should exist$/) do |dir|
assert File.directory?(dir) assert File.directory?(dir)
end end
Then(/^I should see "(.*)" in "(.*)"$/) do |text, file| Then(/^I should see "(.*)" in "(.*)"$/) do |pattern, file|
assert_match Regexp.new(text), File.open(file).readlines.join text = File.open(file).readlines.join
assert_match Regexp.new(pattern), text,
"Pattern /#{pattern}/ not found in: #{text}"
end end
Then(/^I should not see "(.*)" in "(.*)"$/) do |text, file| Then(/^I should not see "(.*)" in "(.*)"$/) do |pattern, file|
assert !File.open(file).readlines.join.match(Regexp.new(text)) text = File.open(file).readlines.join
assert !text.match(Regexp.new(pattern)),
"Did not exptect /#{pattern}/ in: #{text}"
end end
......
...@@ -27,6 +27,15 @@ Given(/^I have the following BibTeX options:$/) do |table| ...@@ -27,6 +27,15 @@ Given(/^I have the following BibTeX options:$/) do |table|
end end
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| Then(/^"(.*)" should come before "(.*)" in "(.*)"$/) do |p1, p2, file|
data = File.open(file).readlines.join('') data = File.open(file).readlines.join('')
......
...@@ -19,3 +19,5 @@ require 'jekyll/scholar/tags/cite_details' ...@@ -19,3 +19,5 @@ require 'jekyll/scholar/tags/cite_details'
require 'jekyll/scholar/tags/quote' require 'jekyll/scholar/tags/quote'
require 'jekyll/scholar/tags/reference' require 'jekyll/scholar/tags/reference'
require 'jekyll/scholar/generators/details' require 'jekyll/scholar/generators/details'
require 'jekyll/scholar/plugins/markdown_links'
# 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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment