scholarmarkdown 2.4.0 → 2.5.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
  SHA256:
3
- metadata.gz: 13c63067f767278858bd96977033c58fdcec1716c344431d1ab3e3beeab1f5a3
4
- data.tar.gz: b499d465bea603e7f6c53235b9ed18399a0cc2fd7d09d89f4168b21db5a6ba86
3
+ metadata.gz: 91f2c165820d1506fffbd6efce12046cad1bfccb257377c925508a40096d985f
4
+ data.tar.gz: c97b69b7409f6bb3a22af5f93fbf141188e7d3a088a48877d6081ed743be0af7
5
5
  SHA512:
6
- metadata.gz: 4037a1e02bf6e3bceb50a09f09b297d5140d7245b1f8e75080b4b4e7e6ab27af5698a968a622c11b24b88745676c0f3600693a661c37855db9e795835a074114
7
- data.tar.gz: 29ac8776f5ecb0230313e9c5f7b97b92dddd0d6917889cd193b4b34be4d58e9ee6f268039c249cbba0aa73dc1b71c194d4c9671bf76118713f5fd352a035725e
6
+ metadata.gz: 58e04398a9606724c7402017ae51257aee8b161cccb7a1342ebc6e802cea9397a19413354a6e68939425717e6ec7bb18f1b16d325aa4ba6e9fabd87df1c385f8
7
+ data.tar.gz: 3bbe1081caeebf61a7f96bb529ccd54dcac0d8f5e06afa08bcb97399fee82188d21a728577c85ca68fee5da64a60a4aac3b8c26286b818ef5d82f72139c083a4
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.4.0
1
+ 2.5.0
@@ -7,3 +7,21 @@ header {
7
7
  display: none;
8
8
  }
9
9
  }
10
+
11
+ // Table of contents
12
+ ol.index-entries {
13
+ margin-bottom: 0;
14
+ }
15
+
16
+ ol.index-entries[depth="0"] {
17
+ li {
18
+ font-weight: bold;
19
+ }
20
+ }
21
+
22
+ ol.index-entries[depth="1"] {
23
+ margin-bottom: 1em;
24
+ li {
25
+ font-weight: normal;
26
+ }
27
+ }
@@ -398,5 +398,10 @@ tbody th {
398
398
  text-align:left;
399
399
  }
400
400
 
401
+ // Hide table of contents in screen-mode
402
+ ol.index-entries {
403
+ display: none;
404
+ }
405
+
401
406
  @import "shared.scss";
402
407
  @import "shared_override.scss";
@@ -76,3 +76,23 @@ dl {
76
76
  var {
77
77
  font-style: italic;
78
78
  }
79
+
80
+ main {
81
+ h1.no-label-increment,
82
+ h2.no-label-increment,
83
+ h3.no-label-increment,
84
+ h4.no-label-increment,
85
+ h5.no-label-increment {
86
+ &::before {
87
+ content: "";
88
+ }
89
+ }
90
+ }
91
+
92
+ ol.index-entries {
93
+ list-style-type: decimal;
94
+
95
+ li {
96
+ margin-left: 1em;
97
+ }
98
+ }
@@ -3,11 +3,31 @@ require 'csv'
3
3
  # A filter for displaying full names of acronyms
4
4
  Nanoc::Filter.define(:scholar_acronym) do |content, params|
5
5
  acronyms = CSV.parse(params[:acronyms].raw_content, :headers => true)
6
+
7
+ # Annotate all occurrences with their full name
6
8
  transformed = content.dup
7
9
  acronyms.each do |row|
8
- transformed.gsub! %r{(?<=[^a-zA-Z0-9])#{row['abbreviation']}(?=[^a-zA-Z0-9])} do |match|
10
+ transformed.gsub! %r{(?<=[\s\.,!?])#{row['abbreviation']}(?=[\s\.,!?])} do |match|
9
11
  %{<abbr title='#{row['full']}'>#{row['abbreviation']}</abbr>}
10
12
  end
11
13
  end
14
+
15
+ # Inject acronyms list
16
+ transformed = transformed.gsub! %r{<div id="scholarmarkdown-acronyms-list"></div>} do |match|
17
+ serialize_acronyms acronyms
18
+ end
19
+
12
20
  transformed
13
21
  end
22
+
23
+ # Serialize the list of acronyms to a table
24
+ def serialize_acronyms acronyms
25
+ table = "<table class=\"acronyms\">"
26
+
27
+ acronyms.each do |row|
28
+ table += "<tr><th>#{row['abbreviation']}</th><td>#{row['full']}</td></tr>"
29
+ end
30
+
31
+ table += "</table>"
32
+ table
33
+ end
@@ -1,40 +1,61 @@
1
1
  # Add labels to elements such as figures and sections, and make them referencable.
2
- Nanoc::Filter.define(:scholar_labelify) do |content|
2
+
3
+ DOCUMENT_SECTIONS = [
4
+ 'Chapter',
5
+ 'Section',
6
+ 'Subsection',
7
+ 'Subsubsection'
8
+ ]
9
+
10
+ Nanoc::Filter.define(:scholar_labelify) do |content, params|
11
+ if params[:chapters]
12
+ document_sections = DOCUMENT_SECTIONS
13
+ else
14
+ document_sections = DOCUMENT_SECTIONS[1, DOCUMENT_SECTIONS.length]
15
+ end
16
+
3
17
  content = content.dup
4
-
5
- labels = create_labels content
18
+ sections_index = []
19
+
20
+ labels = create_labels document_sections, sections_index, content
6
21
  add_labels_to_figures content, labels
7
22
  set_reference_labels content, labels
8
23
 
24
+ serialize_sections_index sections_index, params[:sections_index_depth] || 3, content
25
+
9
26
  content
10
27
  end
11
28
 
12
29
  # Creates labels for referenceable elements
13
- def create_labels content
30
+ def create_labels document_sections, sections_index, content
14
31
  @reference_counts = {}
15
32
  main = content[%r{<main>.*</main>}m]
16
33
  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
34
+ labels = (main + appendix).scan(/<(\w+)([^>]*\s+id="([^"]+)"[^>]*)>([^<]*)(?=<)/)
35
+ .map do |tag, attribute_list, id, name|
36
+ attributes = parse_attributes(attribute_list)
37
+ type = label_type_for document_sections, tag.downcase.to_sym, attributes
38
+ number = 0
39
+ if attributes[:class].nil? or !attributes[:class].include? 'no-label-increment'
40
+ number = number_for document_sections, type, name, id, sections_index
41
+ end
21
42
  [id, "#{type} #{number}"]
22
43
  end
23
44
  labels.to_h
24
45
  end
25
46
 
26
47
  # Determines the label type of a given element
27
- def label_type_for tag, attribute_list
48
+ def label_type_for document_sections, tag, attributes
28
49
  case tag
29
50
  when :h2
30
- 'Section'
51
+ document_sections[0]
31
52
  when :h3
32
- 'Subsection'
53
+ document_sections[1]
33
54
  when :h4
34
- 'Subsubsection'
55
+ document_sections[2]
35
56
  when :figure
36
- unless parse_attributes(attribute_list)[:class].nil?
37
- for clazz in parse_attributes(attribute_list)[:class].split(' ') do
57
+ unless attributes[:class].nil?
58
+ for clazz in attributes[:class].split(' ') do
38
59
  case clazz
39
60
  when 'algorithm'
40
61
  return 'Algorithm'
@@ -44,6 +65,8 @@ def label_type_for tag, attribute_list
44
65
  return 'Table'
45
66
  when 'equation'
46
67
  return 'Equation'
68
+ when 'subfigure'
69
+ return 'Subfig.'
47
70
  end
48
71
  end
49
72
  end
@@ -53,27 +76,46 @@ def label_type_for tag, attribute_list
53
76
  end
54
77
  end
55
78
 
56
- def number_for type
79
+ def number_for document_sections, type, name, id, sections_index
57
80
  # Determine number of elements
58
81
  @reference_counts[type] ||= 0
59
82
  number = @reference_counts[type] += 1
60
83
 
61
84
  # Perform hierarchical numbering when needed
62
85
  case type
63
- when 'Section'
64
- @reference_counts['Subsection'] = 0
65
- @reference_counts['Subsubsection'] = 0
66
- when 'Subsection'
67
- @reference_counts['Subsubsection'] = 0
68
- number = "#{reference_counts['Section']}.#{number}"
69
- when 'Subsubsection'
70
- number = "#{reference_counts['Section']}.#{reference_counts['Subsection']}.#{number}"
86
+ when document_sections[0]
87
+ @reference_counts[document_sections[1]] = 0
88
+ @reference_counts[document_sections[2]] = 0
89
+ sections_index[@reference_counts[document_sections[0]] - 1] = { :name => name, :id => id, :children => [] }
90
+ when document_sections[1]
91
+ @reference_counts[document_sections[2]] = 0
92
+ number = "#{reference_counts[document_sections[0]]}.#{number}"
93
+ sections_index[@reference_counts[document_sections[0]] - 1][:children][@reference_counts[document_sections[1]] - 1] = { :name => name, :id => id, :children => [] }
94
+ when document_sections[2]
95
+ number = "#{reference_counts[document_sections[0]]}.#{reference_counts[document_sections[1]]}.#{number}"
96
+ sections_index[@reference_counts[document_sections[0]] - 1][:children][@reference_counts[document_sections[1]] - 1][:children][@reference_counts[document_sections[2]] - 1] = { :name => name, :id => id, :children => [] }
97
+ when 'Fig.'
98
+ @reference_counts['Subfig.'] = 0
99
+ when 'Subfig.'
100
+ number = "#{reference_counts['Fig.']}.#{number}"
71
101
  end
72
102
  number
73
103
  end
74
104
 
75
105
  # Adds labels to referenceable figures
76
106
  def add_labels_to_figures content, labels
107
+ # Subfigures
108
+ content.gsub! %r{<figure[^>]*\s+id="([^"]+)"\s+class="[^"]*subfigure[^"]*".*?<figcaption>(?:\s*<p>)?}m do |match|
109
+ id=$1
110
+ match = match.sub! '<figcaption>', '<figcaption class="for-subfigure">'
111
+ if labels.key? id
112
+ %{#{match}<span class="label">#{h labels[id]}:</span> }
113
+ else
114
+ match
115
+ end
116
+ end
117
+
118
+ # Main figures
77
119
  content.gsub! %r{<figure[^>]*\s+id="([^"]+)".*?<figcaption>(?:\s*<p>)?}m do |match|
78
120
  if labels.key? $1
79
121
  %{#{match}<span class="label">#{h labels[$1]}:</span> }
@@ -100,3 +142,25 @@ def parse_attributes attribute_list
100
142
  .map { |k,v| [k.downcase.to_sym, v] }
101
143
  .to_h
102
144
  end
145
+
146
+ # Replace '<div id="toc-index"></div>' with the sections index
147
+ def serialize_sections_index sections_index, max_depth, content
148
+ content.gsub! %r{<div id="scholarmarkdown-toc-index"></div>} do |match|
149
+ serialize_sections_index_row sections_index, max_depth, 0, true
150
+ end
151
+ end
152
+
153
+ # Serialize a single row of index entries, and recursively create the index for sub-entries
154
+ def serialize_sections_index_row sections_index, max_depth, depth, root
155
+ if max_depth == 0
156
+ return ""
157
+ end
158
+
159
+ table = "<ol class=\"#{root ? "index-entries index-entries-root" : "index-entries"}\" depth=\"#{depth}\">"
160
+ sections_index.each do |section|
161
+ index_sub = serialize_sections_index_row section[:children], max_depth - 1, depth + 1, false
162
+ table += "<li><a href=\"##{section[:id]}\" class=\"index-entry-name\">#{section[:name]}</a>#{index_sub}</li>"
163
+ end
164
+ table += "</ol>"
165
+ table
166
+ end
@@ -4,13 +4,17 @@ require 'erb'
4
4
  include ERB::Util
5
5
 
6
6
  # Create a section block with the given file contents
7
- def section id
7
+ def section id, classes = nil
8
+ section_suffix=''
9
+ if classes
10
+ section_suffix=" class=\"" + classes + "\""
11
+ end
8
12
  item = @items["/#{id.to_s}.*"]
9
13
  if not item
10
14
  raise "Could not find the file '" + id.to_s + "'"
11
15
  end
12
16
  <<-HTML
13
- <section markdown="block">
17
+ <section markdown="block"#{section_suffix}>
14
18
  #{item.raw_content}
15
19
  </section>
16
20
  HTML
@@ -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: scholarmarkdown 2.4.0 ruby lib
5
+ # stub: scholarmarkdown 2.5.0 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "scholarmarkdown".freeze
9
- s.version = "2.4.0"
9
+ s.version = "2.5.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 Taelman".freeze]
14
- s.date = "2019-07-01"
14
+ s.date = "2019-07-22"
15
15
  s.email = "rubensworks@gmail.com".freeze
16
16
  s.executables = ["generate-scholarmarkdown".freeze]
17
17
  s.extra_rdoc_files = [
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scholarmarkdown
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.0
4
+ version: 2.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ruben Taelman
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-07-01 00:00:00.000000000 Z
11
+ date: 2019-07-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: i18n