jekyll-wikilinks 0.0.10 → 0.0.11
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c2acbae9be49d78fdcbbe55411349c1321ac86cd8222ccd44657d04bbbd446ea
|
4
|
+
data.tar.gz: 28811da20a489fbd36c8566aea26b493e5a26b11e1e020f52d88b69d17d30e08
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 914ed17d2a796330f190f7e97edb14f7dc328445c2e0a044ddc35532d927bca469baabb90a179455e39d04c368188bdeb328e1a7ce8a1be7d2f01a3356594ebc
|
7
|
+
data.tar.gz: 8bdd89667f8beba351bfd7233245135222d1cb3a432b9ff4b3df2c471252b5f9b09e2cc95cb75f57607e6d47ca73559f7c964b8b1f977a8a5ecd3b734b9d751a
|
@@ -4,6 +4,7 @@ require_relative "../util/regex"
|
|
4
4
|
module Jekyll
|
5
5
|
module WikiLinks
|
6
6
|
|
7
|
+
# todo: move these methods to the 'WikiLink' classes...?
|
7
8
|
#
|
8
9
|
# this class is responsible for answering any questions
|
9
10
|
# related to jekyll markdown documents
|
@@ -55,6 +56,13 @@ module Jekyll
|
|
55
56
|
return docs[0]
|
56
57
|
end
|
57
58
|
|
59
|
+
def get_doc_by_fpath(file_path)
|
60
|
+
Jekyll.logger.error("Jekyll-Wikilinks: Must provide a 'file_path'") if file_path.nil? || file_path.empty?
|
61
|
+
docs = @md_docs.select{ |d| d.relative_path == (file_path + ".md") }
|
62
|
+
return nil if docs.nil? || docs.empty? || docs.size > 1
|
63
|
+
return docs[0]
|
64
|
+
end
|
65
|
+
|
58
66
|
def get_doc_by_url(url)
|
59
67
|
Jekyll.logger.error("Jekyll-Wikilinks: Must provide a 'url'") if url.nil? || url.empty?
|
60
68
|
docs = @md_docs.select{ |d| d.url == url }
|
@@ -78,12 +86,15 @@ module Jekyll
|
|
78
86
|
|
79
87
|
# validators
|
80
88
|
|
81
|
-
def file_exists?(filename)
|
89
|
+
def file_exists?(filename, file_path=nil)
|
82
90
|
Jekyll.logger.error("Jekyll-Wikilinks: Must provide a 'filename'") if filename.nil? || filename.empty?
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
91
|
+
if file_path.nil?
|
92
|
+
return false if get_doc_by_fname(filename).nil? && get_image_by_fname(filename).nil?
|
93
|
+
return true
|
94
|
+
else
|
95
|
+
return false if get_doc_by_fpath(file_path).nil?
|
96
|
+
return true
|
97
|
+
end
|
87
98
|
end
|
88
99
|
|
89
100
|
def doc_has_header?(doc, header)
|
@@ -76,6 +76,8 @@ module Jekyll
|
|
76
76
|
end
|
77
77
|
# replace text
|
78
78
|
return if @wikilink_inlines.nil?
|
79
|
+
# process typed wikilinks first so we don't accidentally
|
80
|
+
# overwrite them when handling untyped wikilinks
|
79
81
|
self.sort_typed_first
|
80
82
|
@wikilink_inlines.each do |wikilink|
|
81
83
|
doc_content.gsub!(
|
@@ -125,24 +127,34 @@ module Jekyll
|
|
125
127
|
# markdown file processing
|
126
128
|
linked_doc = wikilink.linked_doc
|
127
129
|
link_type_txt = wikilink.is_typed? ? " #{$wiki_conf.css_name("typed")} #{wikilink.link_type}" : ""
|
128
|
-
|
129
|
-
inner_txt = wikilink.label_txt if wikilink.labelled?
|
130
130
|
lnk_doc_rel_url = relative_url(linked_doc.url)
|
131
|
-
|
132
|
-
|
133
|
-
|
131
|
+
if wikilink.labelled?
|
132
|
+
inner_txt = wikilink.label_txt
|
133
|
+
elsif linked_doc.data.keys.include?('title')
|
134
|
+
inner_txt = linked_doc.data['title'].downcase
|
135
|
+
# in case there is no 'title' frontmatter attribute
|
136
|
+
# (i'm seeing deprecation warnings, but there might
|
137
|
+
# be bugs caused by not using this...)
|
138
|
+
elsif linked_doc.respond_to?(:title)
|
139
|
+
inner_txt = linked_doc.title.downcase
|
140
|
+
# pages don't have automatically generated titles
|
141
|
+
else
|
142
|
+
inner_txt = Jekyll::Utils.slugify(linked_doc.basename)
|
143
|
+
end
|
144
|
+
# level-specific
|
145
|
+
if (wikilink.level == "file_path" || wikilink.level == "filename")
|
134
146
|
return build_html_embed(
|
135
|
-
linked_doc
|
147
|
+
linked_doc.title,
|
136
148
|
linked_doc.content,
|
137
149
|
lnk_doc_rel_url
|
138
150
|
) if wikilink.embedded?
|
139
151
|
elsif (wikilink.level == "header")
|
140
152
|
# from: https://github.com/jekyll/jekyll/blob/6855200ebda6c0e33f487da69e4e02ec3d8286b7/Rakefile#L74
|
141
153
|
lnk_doc_rel_url += "\#" + Jekyll::Utils.slugify(wikilink.header_txt)
|
142
|
-
inner_txt
|
154
|
+
inner_txt += " > #{wikilink.header_txt.downcase}" if !wikilink.labelled?
|
143
155
|
elsif (wikilink.level == "block")
|
144
156
|
lnk_doc_rel_url += "\#" + wikilink.block_id
|
145
|
-
inner_txt
|
157
|
+
inner_txt += " > ^#{wikilink.block_id}" if !wikilink.labelled?
|
146
158
|
else
|
147
159
|
Jekyll.logger.error("Jekyll-Wikilinks: Invalid wikilink level")
|
148
160
|
end
|
@@ -22,7 +22,7 @@ module Jekyll
|
|
22
22
|
|
23
23
|
# wikitext usable char requirements
|
24
24
|
REGEX_LINK_TYPE_CHARS = /[^\n\s\!\#\^\|\]]+/i
|
25
|
-
REGEX_FILENAME_CHARS = /[
|
25
|
+
REGEX_FILENAME_CHARS = /[^\\:\#\^\|\[\]]+/i
|
26
26
|
REGEX_HEADER_CHARS = /[^\!\#\^\|\[\]]+/i
|
27
27
|
REGEX_BLOCK_ID_CHARS = /[^\\\/:\!\#\^\|\[\]^\n]+/i
|
28
28
|
REGEX_LABEL_CHARS = /(.+?)(?=\]{2}[^\]])/i
|
@@ -136,19 +136,30 @@ module Jekyll
|
|
136
136
|
end
|
137
137
|
|
138
138
|
class WikiLinkInline
|
139
|
-
attr_accessor :context_filename, :embed, :link_type, :filename, :header_txt, :block_id, :label_txt
|
139
|
+
attr_accessor :context_filename, :embed, :link_type, :file_path, :path_type, :filename, :header_txt, :block_id, :label_txt
|
140
140
|
|
141
|
+
FILE_PATH = "file_path"
|
141
142
|
FILENAME = "filename"
|
142
143
|
HEADER_TXT = "header_txt"
|
143
144
|
BLOCK_ID = "block_id"
|
144
145
|
|
145
146
|
# parameters ordered by appearance in regex
|
146
|
-
def initialize(doc_mngr, context_filename, embed, link_type,
|
147
|
+
def initialize(doc_mngr, context_filename, embed, link_type, file_string, header_txt, block_id, label_txt)
|
148
|
+
if file_string.include?('/') && file_string[0] == '/'
|
149
|
+
@path_type = "absolute"
|
150
|
+
@file_path ||= file_string[1...] # remove leading '/' to match `jekyll_collection_doc.relative_path`
|
151
|
+
@filename ||= file_string.split('/').last
|
152
|
+
elsif file_string.include?('/') && file_string[0] != '/'
|
153
|
+
Jekyll.logger.error("Jekyll-Wikilinks: Relative file paths are not yet supported, please use absolute file paths that start with '/' for #{file_string}")
|
154
|
+
# todo:
|
155
|
+
# @path_type = "relative"
|
156
|
+
else
|
157
|
+
@filename ||= file_string
|
158
|
+
end
|
147
159
|
@doc_mngr ||= doc_mngr
|
148
160
|
@context_filename ||= context_filename
|
149
161
|
@embed ||= embed
|
150
162
|
@link_type ||= link_type
|
151
|
-
@filename ||= filename
|
152
163
|
@header_txt ||= header_txt
|
153
164
|
@block_id ||= block_id
|
154
165
|
@label_txt ||= label_txt
|
@@ -164,35 +175,45 @@ module Jekyll
|
|
164
175
|
def md_regex
|
165
176
|
regex_embed = embedded? ? REGEX_LINK_EMBED : %r{}
|
166
177
|
regex_link_type = is_typed? ? %r{#{@link_type}#{REGEX_LINK_TYPE}} : %r{}
|
167
|
-
|
178
|
+
if !@file_path.nil?
|
179
|
+
file_string = described?(FILE_PATH) ? @file_path : ""
|
180
|
+
file_string = '/' + file_string if @path_type == "absolute"
|
181
|
+
else
|
182
|
+
file_string = described?(FILENAME) ? @filename : ""
|
183
|
+
end
|
168
184
|
if described?(HEADER_TXT)
|
169
185
|
header = %r{#{REGEX_LINK_HEADER}#{@header_txt}}
|
170
186
|
block = %r{}
|
171
187
|
elsif described?(BLOCK_ID)
|
172
188
|
header = %r{}
|
173
189
|
block = %r{#{REGEX_LINK_BLOCK}#{@block_id}}
|
174
|
-
elsif !described?(FILENAME)
|
190
|
+
elsif !described?(FILENAME) && !described?(FILE_PATH)
|
175
191
|
Jekyll.logger.error("Jekyll-Wikilinks: WikiLinkInline.md_regex error")
|
176
192
|
end
|
177
193
|
label_ = labelled? ? %r{#{REGEX_LINK_LABEL}#{label_txt}} : %r{}
|
178
|
-
return %r{#{regex_embed}#{regex_link_type}#{REGEX_LINK_LEFT}#{
|
194
|
+
return %r{#{regex_embed}#{regex_link_type}#{REGEX_LINK_LEFT}#{file_string}#{header}#{block}#{label_}#{REGEX_LINK_RIGHT}}
|
179
195
|
end
|
180
196
|
|
181
197
|
def md_str
|
182
198
|
embed = embedded? ? "!" : ""
|
183
199
|
link_type = is_typed? ? "#{@link_type}::" : ""
|
184
|
-
|
200
|
+
if !@file_path.nil?
|
201
|
+
file_string = described?(FILE_PATH) ? @file_path : ""
|
202
|
+
file_string = '/' + file_string if @path_type == "absolute"
|
203
|
+
else
|
204
|
+
file_string = described?(FILENAME) ? @filename : ""
|
205
|
+
end
|
185
206
|
if described?(HEADER_TXT)
|
186
207
|
header = "\##{@header_txt}"
|
187
208
|
block = ""
|
188
209
|
elsif described?(BLOCK_ID)
|
189
210
|
header = ""
|
190
211
|
block = "\#\^#{@block_id}"
|
191
|
-
elsif !described?(FILENAME)
|
212
|
+
elsif !described?(FILENAME) && !described?(FILE_PATH)
|
192
213
|
Jekyll.logger.error("Jekyll-Wikilinks: WikiLinkInline.md_str error")
|
193
214
|
end
|
194
215
|
label_ = labelled? ? "\|#{@label_txt}" : ""
|
195
|
-
return "#{embed}#{link_type}\[\[#{
|
216
|
+
return "#{embed}#{link_type}\[\[#{file_string}#{header}#{block}#{label_}\]\]"
|
196
217
|
end
|
197
218
|
|
198
219
|
# 'fm' -> frontmatter
|
@@ -216,7 +237,11 @@ module Jekyll
|
|
216
237
|
end
|
217
238
|
|
218
239
|
def linked_doc
|
219
|
-
|
240
|
+
# by file path
|
241
|
+
return @doc_mngr.get_doc_by_fpath(@file_path) if !@file_path.nil?
|
242
|
+
# by filename
|
243
|
+
return @doc_mngr.get_doc_by_fname(@filename) if @file_path.nil?
|
244
|
+
return nil
|
220
245
|
end
|
221
246
|
|
222
247
|
def linked_img
|
@@ -258,6 +283,7 @@ module Jekyll
|
|
258
283
|
|
259
284
|
# this method helps to make the 'WikiLinkInline.level' code read like a clean truth table.
|
260
285
|
def described?(chunk)
|
286
|
+
return (!@file_path.nil? && !@file_path.empty?) if chunk == FILE_PATH
|
261
287
|
return (!@filename.nil? && !@filename.empty?) if chunk == FILENAME
|
262
288
|
return (!@header_txt.nil? && !@header_txt.empty?) if chunk == HEADER_TXT
|
263
289
|
return (!@block_id.nil? && !@block_id.empty?) if chunk == BLOCK_ID
|
@@ -265,16 +291,17 @@ module Jekyll
|
|
265
291
|
end
|
266
292
|
|
267
293
|
def level
|
268
|
-
return "
|
269
|
-
return "
|
270
|
-
return "
|
294
|
+
return "file_path" if described?(FILE_PATH) && described?(FILENAME) && !described?(HEADER_TXT) && !described?(BLOCK_ID)
|
295
|
+
return "filename" if !described?(FILE_PATH) && described?(FILENAME) && !described?(HEADER_TXT) && !described?(BLOCK_ID)
|
296
|
+
return "header" if (described?(FILE_PATH) || described?(FILENAME)) && described?(HEADER_TXT) && !described?(BLOCK_ID)
|
297
|
+
return "block" if (described?(FILE_PATH) || described?(FILENAME)) && !described?(HEADER_TXT) && described?(BLOCK_ID)
|
271
298
|
return "invalid"
|
272
299
|
end
|
273
300
|
|
274
301
|
# validation methods
|
275
302
|
|
276
303
|
def is_valid?
|
277
|
-
return false if !@doc_mngr.file_exists?(@filename)
|
304
|
+
return false if !@doc_mngr.file_exists?(@filename, @file_path)
|
278
305
|
return false if (self.level == "header") && !@doc_mngr.doc_has_header?(self.linked_doc, @header_txt)
|
279
306
|
return false if (self.level == "block") && !@doc_mngr.doc_has_block_id?(self.linked_doc, @block_id)
|
280
307
|
return true
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-wikilinks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- manunamz
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-01-
|
11
|
+
date: 2022-01-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|