bibmarkdown 1.2.1 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c99bc98d84bf0eed3fb8dd4d7d44a4868c91962f
4
- data.tar.gz: b552385ae4b3e037c9c94001c83f144d483a5731
3
+ metadata.gz: b3643b4d21d60997b979670eec92eefe6832ead5
4
+ data.tar.gz: 6aef6c803413b1799ebf2d9080f509341b0ded80
5
5
  SHA512:
6
- metadata.gz: 6b99bff193aca4ffa06785821aac9a3a70d2a0d83481bfb17db5464e51396d6bcfcad221c14e47f3fc019c03313edcb2a08845cd23cdffdcd345c322a5e6bc14
7
- data.tar.gz: ed909c79a985e26eecb4f87f136b5df0fc0df836edec2c3148fbfbbff0f57de72f32e2f019fa7fc5d0fe39de12b4e1c2ee54b2b50941f94c74fd176243accade
6
+ metadata.gz: 9f78597db7000e0f29338641c4934a7aec2e1249265ab1120a4a9cbb8b5aab54eca6455bf525c8b3d2b3a8c14970e004ee1c59e73553349f9d1c5517bb551a5a
7
+ data.tar.gz: 26196bcaebd8f607bfa0ec327d4d9533d2872556c9a540c7765aa7e49f7e93ff761189153e3fa0a24acea92060593dbb0271425ae7831faab8a47d7393caf838
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.2.1
1
+ 1.3.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.2.1 ruby lib
5
+ # stub: bibmarkdown 1.3.0 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "bibmarkdown".freeze
9
- s.version = "1.2.1"
9
+ s.version = "1.3.0"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib".freeze]
13
13
  s.authors = ["Ruben Verborgh".freeze]
14
- s.date = "2017-08-21"
14
+ s.date = "2017-12-31"
15
15
  s.email = "ruben@verborgh.org".freeze
16
16
  s.extra_rdoc_files = [
17
17
  "LICENSE.md",
@@ -22,16 +22,24 @@ module BibMarkdown
22
22
  raise "Missing reference key in #{match}" if refs.empty?
23
23
  reflinks = refs.map{|r| r[:link]}.join ''
24
24
 
25
- # If the link text is empty, output links to the references
25
+ # If the anchor text is empty, output reference links
26
26
  if text.empty?
27
27
  reflinks
28
- # If there is no URL, output the text followed by links to the references
28
+ # If the reference has no URL, output the anchor text and append reference links
29
29
  elsif refs.first[:url].empty?
30
30
  "#{text} #{reflinks}"
31
- # Otherwise, output the linked text and the references
31
+ # Otherwise, link the anchor text to the first reference URL and append reference links
32
32
  else
33
- property = 'http://purl.org/spar/cito/' + rel
34
- "#{create_link text, refs.first[:url], property: property} #{reflinks}"
33
+ property = 'schema:citation http://purl.org/spar/cito/' + rel
34
+ # Link to the first reference
35
+ first = refs.first
36
+ if first[:id] == first[:url]
37
+ "#{create_element :a, text, property: property, href: first[:url]} #{reflinks}"
38
+ # If the reference's ID is different from its URL, surround with an extra span
39
+ else
40
+ link = create_element :a, text, href: first[:url]
41
+ "#{create_element :span, link, property: property, resource: first[:id]} #{reflinks}"
42
+ end
35
43
  end
36
44
  end
37
45
 
@@ -40,29 +48,32 @@ module BibMarkdown
40
48
  end
41
49
 
42
50
  protected
51
+ def find_entry key
52
+ raise "Reference '#{key}' does not exist." unless @entries.key?(key)
53
+ @entries[key]
54
+ end
55
+
43
56
  def create_reference key
44
57
  return @references[key] if @references.has_key? key
45
58
 
46
59
  # Look up citation and its URL
47
- entry = @entries[key]
48
- raise "Failed to generate references: entry '#{key}' does not exist." unless entry
60
+ entry = find_entry key
49
61
  url = entry[:url] || ''
50
62
 
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'
63
+ # Assign a reference number and create a link to the reference
64
+ number = @references.length + 1
65
+ link = create_element :a, "\\[#{number}\\]", href: "#ref-#{number}", class: 'reference'
54
66
 
55
- @references[key] = { id: id, url: url, link: link }
67
+ @references[key] = { id: reference_id(key), number: number, url: url, link: link }
56
68
  end
57
69
 
58
70
  def h text
59
71
  CGI::escapeHTML(text || '')
60
72
  end
61
73
 
62
- def create_link html, url, attrs = {}
63
- attrs[:href] = url
74
+ def create_element tag, html, attrs = {}
64
75
  attrs = attrs.map { |attr, value| %Q{#{attr}="#{h value}"} }
65
- %Q{<a #{attrs.join ' '}>#{html}</a>}
76
+ %Q{<#{tag} #{attrs.join ' '}>#{html}</#{tag}>}
66
77
  end
67
78
 
68
79
  def references_html
@@ -72,13 +83,36 @@ module BibMarkdown
72
83
  html = %Q{<h2 id="references">References</h2>\n}
73
84
  html += %Q{<dl class="references">\n}
74
85
  @references.each do |key, ref|
75
- html += %Q{ <dt id="ref-#{ref[:id]}">\[#{ref[:id]}\]</dt>\n}
76
- html += %Q{ <dd>#{reference_html key}</dd>\n}
86
+ html += %Q{ <dt id="ref-#{ref[:number]}">\[#{ref[:number]}\]</dt>\n}
87
+ html += %Q{ <dd resource="#{reference_id key}" typeof="#{reference_type key}">#{reference_html key}</dd>\n}
77
88
  end
78
89
  html += %Q{</dl>\n}
79
90
  end
80
91
  end
81
92
 
93
+ def reference_id key
94
+ entry = find_entry key
95
+ entry[:id] ||
96
+ entry[:doi] && "https://dx.doi.org/#{entry[:doi]}" ||
97
+ entry[:url] ||
98
+ "##{key}"
99
+ end
100
+
101
+ def reference_type key
102
+ case find_entry(key).type
103
+ when :article, :inproceedings
104
+ 'schema:Article'
105
+ when :book
106
+ 'schema:Book'
107
+ when :incollection
108
+ 'schema:Chapter'
109
+ when :mastersthesis, :phdthesis
110
+ 'schema:Thesis'
111
+ else
112
+ 'schema:CreativeWork'
113
+ end
114
+ end
115
+
82
116
  def reference_html key
83
117
  # Render reference
84
118
  processor = CiteProc::Processor.new style: @style, format: 'html'
@@ -88,7 +122,7 @@ module BibMarkdown
88
122
 
89
123
  # Replace URLs by links
90
124
  citation.gsub %r{https?://[^ ]+[^ .]} do |match|
91
- create_link h(match), match
125
+ create_element :a, h(match), href: match
92
126
  end
93
127
  end
94
128
  end
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.2.1
4
+ version: 1.3.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-08-21 00:00:00.000000000 Z
11
+ date: 2017-12-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: citeproc-ruby