hematite 0.0.12 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/_includes/extern_library_imports.html +11 -0
- data/_includes/katex_includes.html +1 -1
- data/_includes/mermaid_includes.html +24 -0
- data/_layouts/default.html +6 -2
- data/_layouts/remark_slideshow.html +88 -0
- data/_sass/_elements.scss +17 -0
- data/_sass/_hljs.scss +36 -0
- data/_sass/_layout.scss +15 -0
- data/_sass/_nav.scss +13 -0
- data/_sass/hematite.scss +1 -0
- data/assets/html/remark_presentation_frame.html.resource +69 -0
- data/assets/img/favicon-alternate.svg +12 -0
- data/assets/js/UrlHelper.mjs +20 -0
- data/assets/js/dropdownExpander.mjs +2 -1
- data/assets/js/layout/remark_slideshow.mjs +164 -0
- data/assets/js/search.mjs +59 -14
- data/assets/plugin/mermaid/mermaid.core.js +31940 -0
- data/assets/plugin/mermaid/mermaid.core.js.map +1 -0
- data/assets/plugin/mermaid/mermaid.js +129094 -0
- data/assets/plugin/mermaid/mermaid.js.map +1 -0
- data/assets/plugin/remark_presenter/README.txt +2 -0
- data/assets/plugin/remark_presenter/remark.min.js +18 -0
- data/assets/string_data/en.mjs +5 -1
- data/assets/string_data/es.mjs +5 -1
- data/assets/style_only_syntax.scss +11 -0
- metadata +16 -2
data/assets/js/search.mjs
CHANGED
@@ -54,6 +54,25 @@ class Searcher {
|
|
54
54
|
|
55
55
|
}
|
56
56
|
|
57
|
+
/// Get number of full matches for [query] in [text].
|
58
|
+
/// @precondition [text] is already in a searchable (i.e.
|
59
|
+
/// filtered) form.
|
60
|
+
getNumberOfMatches(query, text) {
|
61
|
+
query = query.toLowerCase();
|
62
|
+
|
63
|
+
return text.toLowerCase().split(query).length - 1;
|
64
|
+
}
|
65
|
+
|
66
|
+
/// Get the index of the first full match for [query] in
|
67
|
+
/// [text], starting at [startPos]. Returns -1 if no match
|
68
|
+
/// is found.
|
69
|
+
/// @precondition [text] is already in a searchable form.
|
70
|
+
getIdxOfFirstMatch(query, text, startPos) {
|
71
|
+
query = query.toLowerCase();
|
72
|
+
|
73
|
+
return text.toLowerCase().indexOf(query, startPos);
|
74
|
+
}
|
75
|
+
|
57
76
|
/// Get the container element for the [n]th search
|
58
77
|
/// result for [query] in the given [elem].
|
59
78
|
/// Returns an Element.
|
@@ -77,7 +96,7 @@ class Searcher {
|
|
77
96
|
|
78
97
|
// If the current node is a leaf,
|
79
98
|
if (elem.childNodes.length == 0) {
|
80
|
-
let numMatches =
|
99
|
+
let numMatches = this.getNumberOfMatches(query, searchText);
|
81
100
|
n -= numMatches;
|
82
101
|
|
83
102
|
// If we've considered enough matches,
|
@@ -154,7 +173,7 @@ class Searcher {
|
|
154
173
|
index ++;
|
155
174
|
pageData.numMatches ++;
|
156
175
|
startPos = matchLoc + query.length;
|
157
|
-
matchLoc =
|
176
|
+
matchLoc = this.getIdxOfFirstMatch(query, toSearch, startPos);
|
158
177
|
}
|
159
178
|
}
|
160
179
|
|
@@ -185,26 +204,52 @@ class Searcher {
|
|
185
204
|
}
|
186
205
|
}
|
187
206
|
|
207
|
+
/// Extract a search query and index from the current page's URL.
|
208
|
+
function getUrlQuery() {
|
209
|
+
let query, resultIndex;
|
210
|
+
|
211
|
+
let urlArgs = UrlHelper.getPageArgs();
|
212
|
+
let pageHash = UrlHelper.getPageHash();
|
213
|
+
|
214
|
+
if (urlArgs === null) {
|
215
|
+
return;
|
216
|
+
}
|
217
|
+
|
218
|
+
// The page's hash also causes scrolling. Don't focus
|
219
|
+
// if the page has a hash.
|
220
|
+
if (pageHash != null) {
|
221
|
+
return;
|
222
|
+
}
|
223
|
+
|
224
|
+
query = urlArgs.query;
|
225
|
+
resultIndex = parseInt(urlArgs.index);
|
226
|
+
|
227
|
+
if (urlArgs.index === undefined) {
|
228
|
+
resultIndex = 0;
|
229
|
+
}
|
230
|
+
|
231
|
+
return { query, resultIndex };
|
232
|
+
}
|
233
|
+
|
188
234
|
/// Scrolls to and shows the search result for the given [query]
|
189
235
|
/// If neither [query] nor [resultIndex] are given, attempt to get them from
|
190
236
|
/// the page's arguments (i.e. from https://example.com/...?search=...,n=...).
|
191
237
|
function focusSearchResult(searcher, elem, query, resultIndex) {
|
192
|
-
if (
|
193
|
-
|
194
|
-
|
238
|
+
if (elem === undefined) {
|
239
|
+
console.warn(`focusSearchResult requires [elem] to function. Not focusing a result.`);
|
240
|
+
return;
|
241
|
+
}
|
195
242
|
|
196
|
-
|
197
|
-
|
198
|
-
}
|
243
|
+
if (query === undefined && resultIndex === undefined) {
|
244
|
+
let pageArgs = getUrlQuery();
|
199
245
|
|
200
|
-
//
|
201
|
-
|
202
|
-
if (pageHash != null) {
|
246
|
+
// No args, nothing to focus.
|
247
|
+
if (!pageArgs) {
|
203
248
|
return;
|
204
249
|
}
|
205
250
|
|
206
|
-
|
207
|
-
|
251
|
+
resultIndex = pageArgs.resultIndex;
|
252
|
+
query = pageArgs.query;
|
208
253
|
|
209
254
|
if (isNaN(resultIndex)) {
|
210
255
|
console.warn("Unable to navigate to result. Given idx is NaN");
|
@@ -355,4 +400,4 @@ function handleSearch(searcher) {
|
|
355
400
|
}
|
356
401
|
|
357
402
|
export default handleSearch;
|
358
|
-
export { handleSearch, Searcher };
|
403
|
+
export { handleSearch, getUrlQuery, Searcher };
|