-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
87 additions
and
26 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
"use strict"; | ||
|
||
function getDocuments() { | ||
var content = document.querySelector("#content"); | ||
|
||
var data = []; | ||
var currentId = null; | ||
var current = { body: [], examples: [] }; | ||
|
||
function push() { | ||
if (!currentId) return; | ||
if (current.body.length > 0 || current.examples.length > 0) { | ||
data.push({ id: currentId, ...current }); | ||
current = { body: [], examples: [] }; | ||
} | ||
} | ||
|
||
for (var i = 0; i < content.children.length; i++) { | ||
var child = content.children.item(i); | ||
|
||
// content of subrules should be collapsed to their parent rule | ||
if (child.classList.contains("anchor-subrule")) continue; | ||
|
||
if (child.id) { | ||
push(); | ||
currentId = child.id; | ||
continue; | ||
} | ||
|
||
if (child.classList.contains("rules-example")) | ||
current.examples.push(child.textContent); | ||
else current.body.push(child.textContent); | ||
} | ||
push(); | ||
|
||
return data; | ||
} | ||
|
||
function main() { | ||
var data = getDocuments(); | ||
window.index = new Fuse(data, { | ||
includeScore: true, | ||
includeMatches: true, | ||
minMatchCharLength: 2, | ||
keys: [{ name: "body", weight: 2 }, "examples"], | ||
}); | ||
} | ||
|
||
window.addEventListener("load", main); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,25 @@ | ||
{{ $class := printf "rules-%s" (lower .Type) }} | ||
|
||
{{ if eq .Type "Part" }} | ||
<a id="{{ .ID }}" class="anchor"></a> | ||
<h3 class="{{ $class }}">{{ .Number }} {{ index .Body 0 }}</h3> | ||
{{ else if eq .Type "Chapter" }} | ||
<a id="{{ .ID }}" class="anchor"></a> | ||
<h4 class="{{ $class }}">{{ .Number }} {{ index .Body 0 }}</h4> | ||
{{ else }} | ||
{{ $first := true }} | ||
{{ range .Body }} | ||
{{ if $first }} | ||
{{ $first = false }} | ||
<a id="{{ $.ID }}" class="anchor"></a> | ||
<p class="{{ $class }}"><a href="#{{ $.ID }}">{{ $.Number }}</a> {{ . | ruleLinks | replaceSymbols }}</p> | ||
{{ else }} | ||
<p>{{ . | replaceSymbols | ruleLinks }}</p> | ||
{{ end }} | ||
{{ end }} | ||
|
||
{{ range .Examples }} | ||
<p class="rules-example"><b>Example:</b> <i>{{ . | ruleLinks | replaceSymbols }}</i></p> | ||
{{ end }} | ||
{{ end }} | ||
{{ $anchorClass := printf "anchor anchor-%s" (lower .Type) }} | ||
{{ $class := printf "rules-%s" (lower .Type) }} | ||
|
||
{{ if eq .Type "Part" }} | ||
<a id="{{ .ID }}" class="{{ $anchorClass }}"></a> | ||
<h3 class="{{ $class }}">{{ .Number }} {{ index .Body 0 }}</h3> | ||
{{ else if eq .Type "Chapter" }} | ||
<a id="{{ .ID }}" class="{{ $anchorClass }}"></a> | ||
<h4 class="{{ $class }}">{{ .Number }} {{ index .Body 0 }}</h4> | ||
{{ else }} | ||
{{ $first := true }} | ||
{{ range .Body }} | ||
{{ if $first }} | ||
{{ $first = false }} | ||
<a id="{{ $.ID }}" class="{{ $anchorClass }}"></a> | ||
<p class="{{ $class }}"><a href="#{{ $.ID }}">{{ $.Number }}</a> {{ . | ruleLinks | replaceSymbols }}</p> | ||
{{ else }} | ||
<p>{{ . | replaceSymbols | ruleLinks }}</p> | ||
{{ end }} | ||
{{ end }} | ||
|
||
{{ range .Examples }} | ||
<p class="rules-example"><b>Example:</b> <i>{{ . | ruleLinks | replaceSymbols }}</i></p> | ||
{{ end }} | ||
{{ end }} |