bibmarkdown 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/bibmarkdown.gemspec +3 -3
- data/lib/bibmarkdown/document.rb +37 -31
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b1ae9c68a4ae3e578f2e0c51ac4848ad49ba8615
|
4
|
+
data.tar.gz: 3a02f49a6aaf61dc9e04c5b6c63449a691574198
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 46cd8fc901d0000095b9f9ce5abdf25a8cb44610e485f096d8803540172fd8438e3713b11f6c5342c74856178e2cf5aea36ea9fbf846deba002ca1d82fbb885a
|
7
|
+
data.tar.gz: 272d0cef6ebb59597cb8ec2da626c7b807fd8499362c414d33fa8c5768f042990fadabe8a77341863c56779e610420366edd1df4fbc6dd060d9a92f0c8ea3831
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.2.0
|
data/bibmarkdown.gemspec
CHANGED
@@ -2,16 +2,16 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Juwelier::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: bibmarkdown 1.
|
5
|
+
# stub: bibmarkdown 1.2.0 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "bibmarkdown"
|
9
|
-
s.version = "1.
|
9
|
+
s.version = "1.2.0"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib"]
|
13
13
|
s.authors = ["Ruben Verborgh"]
|
14
|
-
s.date = "2017-
|
14
|
+
s.date = "2017-05-09"
|
15
15
|
s.email = "ruben@verborgh.org"
|
16
16
|
s.extra_rdoc_files = [
|
17
17
|
"LICENSE.md",
|
data/lib/bibmarkdown/document.rb
CHANGED
@@ -11,44 +11,50 @@ module BibMarkdown
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def to_markdown
|
14
|
-
|
14
|
+
@references = {}
|
15
15
|
|
16
16
|
# Replace all citations by links
|
17
|
-
markdown = @source.gsub %r{\[([^\]]*)\]\(
|
18
|
-
|
17
|
+
markdown = @source.gsub %r{\[([^\]]*)\]\(cit[eo]:(\w+)\s+([^\)]+)\)} do |match|
|
18
|
+
text = $1; rel = $2; keys = $3
|
19
19
|
|
20
|
-
#
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
reference_id = reference_ids[key] = reference_ids.length + 1
|
25
|
-
end
|
26
|
-
|
27
|
-
# Look up citation and its URL
|
28
|
-
entry = @entries[key]
|
29
|
-
raise "Failed to generate references: entry '#{key}' does not exist." unless entry
|
30
|
-
url = entry[:url] || ''
|
20
|
+
# Create the references
|
21
|
+
refs = keys.strip.split(/\s*,\s*/).map {|key| create_reference key }
|
22
|
+
raise "Missing reference key in #{match}" if refs.empty?
|
23
|
+
reflinks = refs.map{|r| r[:link]}.join ''
|
31
24
|
|
32
|
-
#
|
33
|
-
|
34
|
-
|
35
|
-
# If the text
|
36
|
-
|
37
|
-
|
38
|
-
#
|
39
|
-
elsif url.empty?
|
40
|
-
"#{html} #{reflink}"
|
41
|
-
# Otherwise, output the link and the reference
|
25
|
+
# If the link text is empty, output links to the references
|
26
|
+
if text.empty?
|
27
|
+
reflinks
|
28
|
+
# If there is no URL, output the text followed by links to the references
|
29
|
+
elsif refs.first[:url].empty?
|
30
|
+
"#{text} #{reflinks}"
|
31
|
+
# Otherwise, output the linked text and the references
|
42
32
|
else
|
43
|
-
|
33
|
+
property = 'http://purl.org/spar/cito/' + rel
|
34
|
+
"#{create_link text, refs.first[:url], property: property} #{reflinks}"
|
44
35
|
end
|
45
36
|
end
|
46
37
|
|
47
|
-
# Append the reference list to the
|
48
|
-
"#{markdown}\n\n#{references_html
|
38
|
+
# Append the reference list to the document
|
39
|
+
"#{markdown}\n\n#{references_html}".rstrip
|
49
40
|
end
|
50
41
|
|
51
42
|
protected
|
43
|
+
def create_reference key
|
44
|
+
return @references[key] if @references.has_key? key
|
45
|
+
|
46
|
+
# Look up citation and its URL
|
47
|
+
entry = @entries[key]
|
48
|
+
raise "Failed to generate references: entry '#{key}' does not exist." unless entry
|
49
|
+
url = entry[:url] || ''
|
50
|
+
|
51
|
+
# Assign an ID and create a link to the reference
|
52
|
+
id = @references.length + 1
|
53
|
+
link = create_link "[#{id}]", "#ref-#{id}", class: 'reference'
|
54
|
+
|
55
|
+
@references[key] = { id: id, url: url, link: link }
|
56
|
+
end
|
57
|
+
|
52
58
|
def h text
|
53
59
|
CGI::escapeHTML(text || '')
|
54
60
|
end
|
@@ -59,14 +65,14 @@ module BibMarkdown
|
|
59
65
|
%Q{<a #{attrs.join ' '}>#{html}</a>}
|
60
66
|
end
|
61
67
|
|
62
|
-
def references_html
|
63
|
-
if
|
68
|
+
def references_html
|
69
|
+
if @references.empty?
|
64
70
|
''
|
65
71
|
else
|
66
72
|
html = %Q{<h2 id="references">References</h2>\n}
|
67
73
|
html += %Q{<dl class="references">\n}
|
68
|
-
|
69
|
-
html += %Q{ <dt id="ref-#{id}">[#{id}]</dt>\n}
|
74
|
+
@references.each do |key, ref|
|
75
|
+
html += %Q{ <dt id="ref-#{ref[:id]}">[#{ref[:id]}]</dt>\n}
|
70
76
|
html += %Q{ <dd>#{reference_html key}</dd>\n}
|
71
77
|
end
|
72
78
|
html += %Q{</dl>\n}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bibmarkdown
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ruben Verborgh
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-05-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: citeproc-ruby
|