Build the ref doc.
This commit is contained in:
parent
52e831a137
commit
902a9f62af
File diff suppressed because one or more lines are too long
|
|
@ -36,3 +36,16 @@ li {
|
||||||
font-family: monospace, 'Inconsolata';
|
font-family: monospace, 'Inconsolata';
|
||||||
display: inline list-item;
|
display: inline list-item;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
a.self_link {
|
||||||
|
color: #bbb;
|
||||||
|
font-family: monospace, 'Inconsolata';
|
||||||
|
}
|
||||||
|
|
||||||
|
a.self_link:hover {
|
||||||
|
color: #000;
|
||||||
|
}
|
||||||
|
|
||||||
|
.func_name {
|
||||||
|
font-family: monospace, 'Inconsolata';
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1895,7 +1895,7 @@ See [ne](#ne).
|
||||||
|
|
||||||
------------------------------------------------------------------------
|
------------------------------------------------------------------------
|
||||||
|
|
||||||
## \<\{\}
|
## <{}
|
||||||
|
|
||||||
Function
|
Function
|
||||||
|
|
||||||
|
|
@ -1920,7 +1920,7 @@ Tuck an empty list just under the first item on the stack.
|
||||||
|
|
||||||
------------------------------------------------------------------------
|
------------------------------------------------------------------------
|
||||||
|
|
||||||
## \<\<\{\}
|
## <<{}
|
||||||
|
|
||||||
Function
|
Function
|
||||||
|
|
||||||
|
|
@ -3918,7 +3918,7 @@ Function
|
||||||
|
|
||||||
------------------------------------------------------------------------
|
------------------------------------------------------------------------
|
||||||
|
|
||||||
## \|\|
|
## ||
|
||||||
|
|
||||||
Combinator
|
Combinator
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,3 +9,5 @@ FuncRef.html: Function-Reference.md
|
||||||
|
|
||||||
mov: FuncRef.html
|
mov: FuncRef.html
|
||||||
cp -v $? ../html/
|
cp -v $? ../html/
|
||||||
|
|
||||||
|
# pandoc --toc --toc-depth=2 --metadata title="Thun Function Reference" --ascii Function-Reference.md
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,98 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
#
|
||||||
|
# The interface of this HTML generation class is pretty directly based on
|
||||||
|
# https://pypi.python.org/pypi/html but it uses ElementTree to render the
|
||||||
|
# HTML output.
|
||||||
|
#
|
||||||
|
# Copyright © 2018 Simon Forman
|
||||||
|
#
|
||||||
|
# This file is html.py.
|
||||||
|
#
|
||||||
|
# html.py is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# html.py is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with html.py. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
from xml.etree.ElementTree import Element, SubElement, tostringlist
|
||||||
|
|
||||||
|
|
||||||
|
HTML4_STRICT_DOCTYPE = (
|
||||||
|
'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"'
|
||||||
|
' "http://www.w3.org/TR/html4/strict.dtd">'
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class HTML(object):
|
||||||
|
|
||||||
|
def __init__(self, element=None):
|
||||||
|
if element is None:
|
||||||
|
element = Element('html')
|
||||||
|
assert isinstance(element, Element), repr(element)
|
||||||
|
self.root = self.element = element
|
||||||
|
|
||||||
|
def __getattr__(self, tag):
|
||||||
|
e = HTML(SubElement(self.element, tag))
|
||||||
|
e.root = self.root
|
||||||
|
return e
|
||||||
|
|
||||||
|
def __iadd__(self, other):
|
||||||
|
return self._append(self.element, other)
|
||||||
|
|
||||||
|
def _append(self, to, other):
|
||||||
|
if isinstance(other, str):
|
||||||
|
if len(to):
|
||||||
|
last = to[-1]
|
||||||
|
if last.tail is None:
|
||||||
|
last.tail = other
|
||||||
|
else:
|
||||||
|
last.tail += other
|
||||||
|
elif to.text is None:
|
||||||
|
to.text = other
|
||||||
|
else:
|
||||||
|
to.text += other
|
||||||
|
elif isinstance(other, Element):
|
||||||
|
to.append(other)
|
||||||
|
elif isinstance(other, HTML):
|
||||||
|
if other.root is self.root:
|
||||||
|
raise ValueError('What are you doing? No recursive HTML.')
|
||||||
|
to.append(other.element)
|
||||||
|
else:
|
||||||
|
raise ValueError('Must only add strings or Elements not %r'
|
||||||
|
% (other,))
|
||||||
|
return self
|
||||||
|
|
||||||
|
def __call__(self, *content, **kw):
|
||||||
|
for it in content:
|
||||||
|
self._append(self.element, it)
|
||||||
|
self.element.attrib.update(
|
||||||
|
(k.rstrip('_').replace('_', '-'), v)
|
||||||
|
for k, v in kw.items()
|
||||||
|
)
|
||||||
|
return self
|
||||||
|
|
||||||
|
def __enter__(self):
|
||||||
|
return self
|
||||||
|
|
||||||
|
def __exit__(self, exc_type, exc_value, exc_tb):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return '<HTML:%r 0x%x>' % (self.element, id(self))
|
||||||
|
|
||||||
|
def _stringify(self, encoding='unicode'):
|
||||||
|
return tostringlist(self.element, method='html', encoding=encoding)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return ''.join(self._stringify())
|
||||||
|
|
||||||
|
def __iter__(self):
|
||||||
|
return iter(self._stringify())
|
||||||
|
|
||||||
|
|
@ -0,0 +1,70 @@
|
||||||
|
import hashlib, re
|
||||||
|
from myhtml import HTML
|
||||||
|
|
||||||
|
TITLE = 'Thun Function Reference'
|
||||||
|
|
||||||
|
with open('Function-Reference.md') as f:
|
||||||
|
md = f.read()
|
||||||
|
|
||||||
|
k = re.split('^-+$', md, flags=re.MULTILINE)
|
||||||
|
#k = md.split('------------------------------------------------------------------------\n')
|
||||||
|
del k[0]
|
||||||
|
k = [section.splitlines() for section in k]
|
||||||
|
|
||||||
|
##s = set(range(len(k)))
|
||||||
|
##for i, section in enumerate(k):
|
||||||
|
## for line in section:
|
||||||
|
## if line.startswith('## '):
|
||||||
|
## #print(i, line)
|
||||||
|
## s.remove(i) # cannot remove same i twice
|
||||||
|
##assert not s # one header per section
|
||||||
|
|
||||||
|
|
||||||
|
def anchor_for(name):
|
||||||
|
return 'function_' + (
|
||||||
|
name
|
||||||
|
if name.isalpha()
|
||||||
|
else hashlib.sha256(name.encode()).hexdigest()
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
d = {}
|
||||||
|
for i, section in enumerate(k):
|
||||||
|
for line in section:
|
||||||
|
if line.startswith('## '):
|
||||||
|
name = line[3:].strip()
|
||||||
|
d[name] = section
|
||||||
|
|
||||||
|
|
||||||
|
doc = HTML()
|
||||||
|
|
||||||
|
with doc.head as h:
|
||||||
|
h.meta(charset='utf-8')
|
||||||
|
h.title(TITLE)
|
||||||
|
h.link(rel='stylesheet', href='/css/fonts.css')
|
||||||
|
h.link(rel='stylesheet', href='/css/func_ref.css')
|
||||||
|
|
||||||
|
with doc.body as b:
|
||||||
|
b.h1(TITLE)
|
||||||
|
b.a('Home', href='/')
|
||||||
|
b.p('Version -10.0.0')
|
||||||
|
b.p('Each function, combinator, or definition should be documented here.')
|
||||||
|
#b.hr
|
||||||
|
ul = b.ul
|
||||||
|
for name, section in sorted(d.items()):
|
||||||
|
ul.li.a(name, href='#' + anchor_for(name))
|
||||||
|
ul += ' '
|
||||||
|
for name, section in sorted(d.items()):
|
||||||
|
d = b.div
|
||||||
|
anchor_id = anchor_for(name)
|
||||||
|
title = d.h2(name, id=anchor_id, class_='func_name')
|
||||||
|
title += ' '
|
||||||
|
title.a('¶', href='#' + anchor_id, class_='self_link')
|
||||||
|
d.pre('\n'.join(section))
|
||||||
|
|
||||||
|
|
||||||
|
html_string = '<!DOCTYPE html>' + str(doc)
|
||||||
|
|
||||||
|
print(html_string)
|
||||||
|
#from bs4 import BeautifulSoup
|
||||||
|
#print(BeautifulSoup(html_string, 'html.parser').prettify())
|
||||||
Loading…
Reference in New Issue