diff --git a/doc/templ/search.html b/doc/templ/search.html
new file mode 100644
index 0000000..894f7cb
--- /dev/null
+++ b/doc/templ/search.html
@@ -0,0 +1,35 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/raidoc/build.py b/src/raidoc/build.py
index 76b9a24..8aeeb16 100644
--- a/src/raidoc/build.py
+++ b/src/raidoc/build.py
@@ -1,13 +1,14 @@
from pathlib import Path
import shutil
import subprocess
+import json
import sass
import jinja2
import marko
from pygments.formatters import HtmlFormatter
-from raidoc.raimark_ext import RaimarkExt, LinkMixin
+from raidoc.raimark_ext import RaimarkExt, LinkMixin, IndexerMixin
from raidoc.autogen import FilesystemScanner
import raimad
@@ -44,6 +45,8 @@ def build(source='./doc', dest='./build'):
md = marko.Markdown(extensions=['gfm', 'codehilite', RaimarkExt])
+ search_index = []
+
env = jinja2.Environment(
autoescape=False,
undefined=jinja2.StrictUndefined,
@@ -77,6 +80,8 @@ def build(source='./doc', dest='./build'):
markdown = path.read_text()
LinkMixin.links_to = []
+ IndexerMixin.init()
+
try:
content = md(markdown)
except Exception as e:
@@ -106,6 +111,11 @@ def build(source='./doc', dest='./build'):
destpath = destparent / f"{path.stem}.html"
destpath.write_text(html)
+ search_index.append((
+ str(path.relative_to(source).with_suffix('.html')),
+ IndexerMixin.get_index_entry()
+ ))
+
graph.append('}')
map_gv = Path(dest / 'map.gv')
@@ -137,6 +147,7 @@ def build(source='./doc', dest='./build'):
],
).wait()
+
template = env.from_string((source / 'templ/map.html').read_text())
html = template.render({
'webroot': '',
@@ -144,3 +155,15 @@ def build(source='./doc', dest='./build'):
})
(dest / 'map.html').write_text(html)
+ with (dest / 'search_index.js').open('w') as file:
+ file.write('var search_index = ')
+ json.dump(search_index, file)
+ file.write(';\n')
+
+ template = env.from_string((source / 'templ/search.html').read_text())
+ html = template.render({
+ 'webroot': '',
+ })
+ (dest / 'search.html').write_text(html)
+
+
diff --git a/src/raidoc/raimark_ext.py b/src/raidoc/raimark_ext.py
index 3d48d07..e72e1d0 100644
--- a/src/raidoc/raimark_ext.py
+++ b/src/raidoc/raimark_ext.py
@@ -1,5 +1,6 @@
import subprocess
import re
+import copy
import marko
@@ -99,6 +100,28 @@ def render_emphasis(self, element):
))
+class IndexerMixin(object):
+
+ index_entry = None
+
+ @classmethod
+ def init(cls):
+ cls.index_entry = tuple([] for _ in range(10))
+
+ def render_heading(self, element):
+
+ html_text = super().render_heading(element)
+ plain_text = re.sub('<[^>]*>', '', html_text).strip()
+ # TODO horrible inefficient
+
+ self.index_entry[element.level - 1].append(plain_text)
+
+ return html_text
+
+ @classmethod
+ def get_index_entry(cls):
+ return copy.deepcopy(cls.index_entry)
+
codeblock_preamble = """
__raimark_output__ = []
@@ -213,6 +236,12 @@ def _exec_dot(self, code):
RaimarkExt = marko.helpers.MarkoExtension(
- renderer_mixins=[LinkMixin, CodeBlockMixin, CalloutMixin, EmphasisMixin]
+ renderer_mixins=[
+ LinkMixin,
+ CodeBlockMixin,
+ CalloutMixin,
+ EmphasisMixin,
+ IndexerMixin,
+ ]
)