scholarmarkdown 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +15 -0
  3. data/Gemfile.lock +88 -0
  4. data/LICENSE.txt +21 -0
  5. data/README.md +45 -0
  6. data/Rakefile +24 -0
  7. data/VERSION +1 -0
  8. data/bin/generate-scholarmarkdown +19 -0
  9. data/bin/template/.gitignore +9 -0
  10. data/bin/template/Gemfile +36 -0
  11. data/bin/template/Guardfile +15 -0
  12. data/bin/template/README.md +15 -0
  13. data/bin/template/Rules +51 -0
  14. data/bin/template/config.ru +11 -0
  15. data/bin/template/content/abstract.md +15 -0
  16. data/bin/template/content/index.md.erb +21 -0
  17. data/bin/template/content/introduction.md +4 -0
  18. data/bin/template/content/references.bib +10 -0
  19. data/bin/template/content/styles/lncs.scss +1086 -0
  20. data/bin/template/content/styles/print.scss +2 -0
  21. data/bin/template/content/styles/reset.scss +47 -0
  22. data/bin/template/content/styles/screen.scss +364 -0
  23. data/bin/template/content/styles/shared.scss +77 -0
  24. data/bin/template/layouts/default.html.erb +12 -0
  25. data/bin/template/nanoc.yaml +28 -0
  26. data/lib/scholarmarkdown/citationstyles/lncs-custom.csl +159 -0
  27. data/lib/scholarmarkdown/filter/acronym.rb +13 -0
  28. data/lib/scholarmarkdown/filter/citation.rb +18 -0
  29. data/lib/scholarmarkdown/filter/headerids_to_section.rb +7 -0
  30. data/lib/scholarmarkdown/filter/hyphenate_iri.rb +18 -0
  31. data/lib/scholarmarkdown/filter/include_code.rb +10 -0
  32. data/lib/scholarmarkdown/filter/labelify.rb +94 -0
  33. data/lib/scholarmarkdown/filter/references_to_footer.rb +10 -0
  34. data/lib/scholarmarkdown/snippets.rb +28 -0
  35. data/lib/scholarmarkdown.rb +2 -0
  36. data/scholarmarkdown.gemspec +96 -0
  37. metadata +193 -0
@@ -0,0 +1,18 @@
1
+ require 'bibmarkdown'
2
+ require 'bibtex'
3
+ require 'csl/styles'
4
+
5
+ # Sets the default directory of citation styles.
6
+ CSL::Style.root = File.dirname(__FILE__) + '/../citationstyles'
7
+
8
+ # Define a citation filter using bibmarkdown
9
+ Nanoc::Filter.define(:scholar_citation) do |content, params|
10
+ bib = params[:bibfile]
11
+ if not bib
12
+ raise "Could not find bibliography file"
13
+ end
14
+ entries = BibTeX.parse(bib.raw_content).entries
15
+ entries.each_value { |e| e.convert!(:latex) { |key| key != :url } }
16
+ params = params.merge(entries: entries)
17
+ BibMarkdown::Document.new(content, params).to_markdown
18
+ end
@@ -0,0 +1,7 @@
1
+ # Moves IDs on headings to their parent section
2
+ Nanoc::Filter.define(:scholar_headerids_to_section) do |content|
3
+ content = content.dup
4
+ content.gsub! /<section>(\s*)(<h\d[^>]*)(\sid=[^\s>]+)/,
5
+ '<section\3>\1\2'
6
+ content
7
+ end
@@ -0,0 +1,18 @@
1
+ # Define a filter for hyphenating long IRIs
2
+ Nanoc::Filter.define(:scholar_hyphenate_iri) do |content|
3
+ content = content.dup
4
+ # Replace in-text URLs
5
+ content.gsub! %r{>https?://[^>]+?} do |match|
6
+ hyphenate(match)
7
+ end
8
+ # Replace mandatory links
9
+ content.gsub! %r{<a href="([^"]+)"[^>]*\s+class="mandatory"} do |match|
10
+ %{#{match} data-link-text="#{hyphenate $1}"}
11
+ end
12
+ content
13
+ end
14
+
15
+ # Add zero-width space after slashes and hyphens to allow hyphenation
16
+ def hyphenate text
17
+ text.gsub %r{(?<=/|-)}, "\u200B"
18
+ end
@@ -0,0 +1,10 @@
1
+ # Includes code blocks from external files
2
+ Nanoc::Filter.define(:scholar_include_code) do |content|
3
+ content = content.dup
4
+ content.gsub! %r{````(/[^`]+)````} do
5
+ code = @items[$1]
6
+ raise "Code block #{$1} not found." unless code
7
+ "<pre>" + code.raw_content.lines.map{|line| "<code>#{h line}</code>"}.join() + "</pre>"
8
+ end
9
+ content
10
+ end
@@ -0,0 +1,94 @@
1
+ # Add labels to elements such as figures and sections, and make them referencable.
2
+ Nanoc::Filter.define(:scholar_labelify) do |content|
3
+ content = content.dup
4
+
5
+ labels = create_labels content
6
+ add_labels_to_figures content, labels
7
+ set_reference_labels content, labels
8
+
9
+ content
10
+ end
11
+
12
+ # Creates labels for referenceable elements
13
+ def create_labels content
14
+ @reference_counts = {}
15
+ main = content[%r{<main>.*</main>}m]
16
+ appendix = content[%r{<div id="appendix"[^>]*>.*</div>}m] || ""
17
+ labels = (main + appendix).scan(/<(\w+)([^>]*\s+id="([^"]+)"[^>]*)>/)
18
+ .map do |tag, attribute_list, id|
19
+ type = label_type_for tag.downcase.to_sym, attribute_list
20
+ number = number_for type
21
+ [id, "#{type} #{number}"]
22
+ end
23
+ labels.to_h
24
+ end
25
+
26
+ # Determines the label type of a given element
27
+ def label_type_for tag, attribute_list
28
+ case tag
29
+ when :h2
30
+ 'Section'
31
+ when :h3
32
+ 'Subsection'
33
+ when :figure
34
+ unless parse_attributes(attribute_list)[:class].nil?
35
+ for clazz in parse_attributes(attribute_list)[:class].split(' ') do
36
+ case clazz
37
+ when 'algorithm'
38
+ return 'Algorithm'
39
+ when 'listing'
40
+ return 'Listing'
41
+ when 'table'
42
+ return 'Table'
43
+ end
44
+ end
45
+ end
46
+ 'Fig.'
47
+ else
48
+ 'Unknown'
49
+ end
50
+ end
51
+
52
+ def number_for type
53
+ # Determine number of elements
54
+ @reference_counts[type] ||= 0
55
+ number = @reference_counts[type] += 1
56
+
57
+ # Perform hierarchical numbering when needed
58
+ case type
59
+ when 'Section'
60
+ @reference_counts['Subsection'] = 0
61
+ when 'Subsection'
62
+ number = "#{reference_counts['Section']}.#{number}"
63
+ end
64
+ number
65
+ end
66
+
67
+ # Adds labels to referenceable figures
68
+ def add_labels_to_figures content, labels
69
+ content.gsub! %r{<figure[^>]*\s+id="([^"]+)".*?<figcaption>(?:\s*<p>)?}m do |match|
70
+ if labels.key? $1
71
+ %{#{match}<span class="label">#{h labels[$1]}:</span> }
72
+ else
73
+ match
74
+ end
75
+ end
76
+ end
77
+
78
+ # Sets the labels of unlabeled references in the text
79
+ def set_reference_labels content, labels
80
+ content.gsub! %r{(<a href="#([^"]+)">)(</a>)} do |match|
81
+ if labels.key? $2
82
+ "#{$1}#{h labels[$2]}#{$3}"
83
+ else
84
+ match
85
+ end
86
+ end
87
+ end
88
+
89
+ # Parses a string of HTML attributes
90
+ def parse_attributes attribute_list
91
+ attribute_list.scan(/\s*(\w+)\s*=\s*"([^"]+)"\s*/)
92
+ .map { |k,v| [k.downcase.to_sym, v] }
93
+ .to_h
94
+ end
@@ -0,0 +1,10 @@
1
+ # Moves the references section into <footer>
2
+ Nanoc::Filter.define(:scholar_references_to_footer) do |content|
3
+ content = content.dup
4
+ references = content[%r{<h2 id="references">.*?</dl>}m]
5
+ if references
6
+ content[references] = ''
7
+ content['</footer>'] = "<section>\n" + references + "\n</section>\n</footer>"
8
+ end
9
+ content
10
+ end
@@ -0,0 +1,28 @@
1
+ require 'erb'
2
+
3
+ # Proper escaping of IRIs
4
+ include ERB::Util
5
+
6
+ # Create a section block with the given file contents
7
+ def section id
8
+ item = @items["/#{id.to_s}.*"]
9
+ if not item
10
+ raise "Could not find the file '" + id.to_s + "'"
11
+ end
12
+ <<-HTML
13
+ <section markdown="block">
14
+ #{item.raw_content}
15
+ </section>
16
+ HTML
17
+ end
18
+
19
+ # Create a person block
20
+ def person name, website, profile
21
+ if not website
22
+ h name
23
+ elsif not profile
24
+ %{<a href="#{h website}">#{h name}</a>}
25
+ else
26
+ %{<a href="#{h website}" typeof="http://xmlns.com/foaf/0.1/Person" resource="#{profile}">#{h name}</a>}
27
+ end
28
+ end
@@ -0,0 +1,2 @@
1
+ require 'scholarmarkdown/snippets'
2
+ require 'scholarmarkdown/filter/*'
@@ -0,0 +1,96 @@
1
+ # Generated by juwelier
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Juwelier::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+ # stub: scholarmarkdown 1.0.0 ruby lib
6
+
7
+ Gem::Specification.new do |s|
8
+ s.name = "scholarmarkdown"
9
+ s.version = "1.0.0"
10
+
11
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
+ s.require_paths = ["lib"]
13
+ s.authors = ["Ruben Taelman"]
14
+ s.date = "2018-04-19"
15
+ s.email = "rubensworks@gmail.com"
16
+ s.executables = ["generate-scholarmarkdown"]
17
+ s.extra_rdoc_files = [
18
+ "LICENSE.txt",
19
+ "README.md"
20
+ ]
21
+ s.files = [
22
+ "Gemfile",
23
+ "Gemfile.lock",
24
+ "LICENSE.txt",
25
+ "README.md",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "bin/generate-scholarmarkdown",
29
+ "bin/template/.gitignore",
30
+ "bin/template/Gemfile",
31
+ "bin/template/Guardfile",
32
+ "bin/template/README.md",
33
+ "bin/template/Rules",
34
+ "bin/template/config.ru",
35
+ "bin/template/content/abstract.md",
36
+ "bin/template/content/index.md.erb",
37
+ "bin/template/content/introduction.md",
38
+ "bin/template/content/references.bib",
39
+ "bin/template/content/styles/lncs.scss",
40
+ "bin/template/content/styles/print.scss",
41
+ "bin/template/content/styles/reset.scss",
42
+ "bin/template/content/styles/screen.scss",
43
+ "bin/template/content/styles/shared.scss",
44
+ "bin/template/layouts/default.html.erb",
45
+ "bin/template/nanoc.yaml",
46
+ "lib/scholarmarkdown.rb",
47
+ "lib/scholarmarkdown/citationstyles/lncs-custom.csl",
48
+ "lib/scholarmarkdown/filter/acronym.rb",
49
+ "lib/scholarmarkdown/filter/citation.rb",
50
+ "lib/scholarmarkdown/filter/headerids_to_section.rb",
51
+ "lib/scholarmarkdown/filter/hyphenate_iri.rb",
52
+ "lib/scholarmarkdown/filter/include_code.rb",
53
+ "lib/scholarmarkdown/filter/labelify.rb",
54
+ "lib/scholarmarkdown/filter/references_to_footer.rb",
55
+ "lib/scholarmarkdown/snippets.rb",
56
+ "scholarmarkdown.gemspec"
57
+ ]
58
+ s.homepage = "http://github.com/rubensworks/ScholarMarkdown"
59
+ s.licenses = ["MIT"]
60
+ s.rubygems_version = "2.5.1"
61
+ s.summary = "A framework for writing markdown-based scholarly articles."
62
+
63
+ if s.respond_to? :specification_version then
64
+ s.specification_version = 4
65
+
66
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
67
+ s.add_runtime_dependency(%q<i18n>, [">= 0"])
68
+ s.add_runtime_dependency(%q<bibtex-ruby>, [">= 0"])
69
+ s.add_runtime_dependency(%q<latex-decode>, [">= 0"])
70
+ s.add_runtime_dependency(%q<citeproc-ruby>, [">= 1.1.6"])
71
+ s.add_runtime_dependency(%q<csl-styles>, [">= 0"])
72
+ s.add_runtime_dependency(%q<bibmarkdown>, ["~> 1.3.2"])
73
+ s.add_development_dependency(%q<bundler>, ["~> 1.0"])
74
+ s.add_development_dependency(%q<juwelier>, ["~> 2.4.7"])
75
+ else
76
+ s.add_dependency(%q<i18n>, [">= 0"])
77
+ s.add_dependency(%q<bibtex-ruby>, [">= 0"])
78
+ s.add_dependency(%q<latex-decode>, [">= 0"])
79
+ s.add_dependency(%q<citeproc-ruby>, [">= 1.1.6"])
80
+ s.add_dependency(%q<csl-styles>, [">= 0"])
81
+ s.add_dependency(%q<bibmarkdown>, ["~> 1.3.2"])
82
+ s.add_dependency(%q<bundler>, ["~> 1.0"])
83
+ s.add_dependency(%q<juwelier>, ["~> 2.4.7"])
84
+ end
85
+ else
86
+ s.add_dependency(%q<i18n>, [">= 0"])
87
+ s.add_dependency(%q<bibtex-ruby>, [">= 0"])
88
+ s.add_dependency(%q<latex-decode>, [">= 0"])
89
+ s.add_dependency(%q<citeproc-ruby>, [">= 1.1.6"])
90
+ s.add_dependency(%q<csl-styles>, [">= 0"])
91
+ s.add_dependency(%q<bibmarkdown>, ["~> 1.3.2"])
92
+ s.add_dependency(%q<bundler>, ["~> 1.0"])
93
+ s.add_dependency(%q<juwelier>, ["~> 2.4.7"])
94
+ end
95
+ end
96
+
metadata ADDED
@@ -0,0 +1,193 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: scholarmarkdown
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Ruben Taelman
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-04-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: i18n
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bibtex-ruby
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: latex-decode
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: citeproc-ruby
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: 1.1.6
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: 1.1.6
69
+ - !ruby/object:Gem::Dependency
70
+ name: csl-styles
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: bibmarkdown
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 1.3.2
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 1.3.2
97
+ - !ruby/object:Gem::Dependency
98
+ name: bundler
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '1.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '1.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: juwelier
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 2.4.7
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 2.4.7
125
+ description:
126
+ email: rubensworks@gmail.com
127
+ executables:
128
+ - generate-scholarmarkdown
129
+ extensions: []
130
+ extra_rdoc_files:
131
+ - LICENSE.txt
132
+ - README.md
133
+ files:
134
+ - Gemfile
135
+ - Gemfile.lock
136
+ - LICENSE.txt
137
+ - README.md
138
+ - Rakefile
139
+ - VERSION
140
+ - bin/generate-scholarmarkdown
141
+ - bin/template/.gitignore
142
+ - bin/template/Gemfile
143
+ - bin/template/Guardfile
144
+ - bin/template/README.md
145
+ - bin/template/Rules
146
+ - bin/template/config.ru
147
+ - bin/template/content/abstract.md
148
+ - bin/template/content/index.md.erb
149
+ - bin/template/content/introduction.md
150
+ - bin/template/content/references.bib
151
+ - bin/template/content/styles/lncs.scss
152
+ - bin/template/content/styles/print.scss
153
+ - bin/template/content/styles/reset.scss
154
+ - bin/template/content/styles/screen.scss
155
+ - bin/template/content/styles/shared.scss
156
+ - bin/template/layouts/default.html.erb
157
+ - bin/template/nanoc.yaml
158
+ - lib/scholarmarkdown.rb
159
+ - lib/scholarmarkdown/citationstyles/lncs-custom.csl
160
+ - lib/scholarmarkdown/filter/acronym.rb
161
+ - lib/scholarmarkdown/filter/citation.rb
162
+ - lib/scholarmarkdown/filter/headerids_to_section.rb
163
+ - lib/scholarmarkdown/filter/hyphenate_iri.rb
164
+ - lib/scholarmarkdown/filter/include_code.rb
165
+ - lib/scholarmarkdown/filter/labelify.rb
166
+ - lib/scholarmarkdown/filter/references_to_footer.rb
167
+ - lib/scholarmarkdown/snippets.rb
168
+ - scholarmarkdown.gemspec
169
+ homepage: http://github.com/rubensworks/ScholarMarkdown
170
+ licenses:
171
+ - MIT
172
+ metadata: {}
173
+ post_install_message:
174
+ rdoc_options: []
175
+ require_paths:
176
+ - lib
177
+ required_ruby_version: !ruby/object:Gem::Requirement
178
+ requirements:
179
+ - - ">="
180
+ - !ruby/object:Gem::Version
181
+ version: '0'
182
+ required_rubygems_version: !ruby/object:Gem::Requirement
183
+ requirements:
184
+ - - ">="
185
+ - !ruby/object:Gem::Version
186
+ version: '0'
187
+ requirements: []
188
+ rubyforge_project:
189
+ rubygems_version: 2.5.1
190
+ signing_key:
191
+ specification_version: 4
192
+ summary: A framework for writing markdown-based scholarly articles.
193
+ test_files: []