This commit is contained in:
sforman
2023-10-01 12:48:25 -07:00
parent 8661373435
commit 7ccfba86fd
3 changed files with 1464 additions and 3762 deletions
+810 -1705
View File
File diff suppressed because one or more lines are too long
+625 -2051
View File
File diff suppressed because one or more lines are too long
+29 -6
View File
@@ -1,6 +1,8 @@
import xml.etree.ElementTree as ET
from collections import defaultdict from collections import defaultdict
import hashlib, re, sys import hashlib, re, sys
sys.path.append('../../implementations/Python') sys.path.append('../../implementations/Python')
import markdown
import joy import joy
from myhtml import HTML from myhtml import HTML
@@ -64,6 +66,23 @@ def def_format(to, name):
to += end to += end
def foo(to, text):
html = markdown.markdown(text, output_format="html5")
html = '<div class="notes">' + html + '</div>'
try:
t = ET.fromstringlist([html])
except:
print(repr(html))
raise
to += t
basis_functions = set('''\
i dip branch loop
cons first rest stack swaack
dup swap pop clear'''.split())
k = re.split('^-+$', md, flags=re.MULTILINE) k = re.split('^-+$', md, flags=re.MULTILINE)
#k = md.split('------------------------------------------------------------------------\n') #k = md.split('------------------------------------------------------------------------\n')
del k[0] del k[0]
@@ -78,7 +97,7 @@ k = [section.splitlines() for section in k]
##assert not s # one header per section ##assert not s # one header per section
def anchor_for(name): def anchor_for(name):
return 'function_' + ( return (
name name
if name.isalpha() if name.isalpha()
else hashlib.sha256(name.encode()).hexdigest() else hashlib.sha256(name.encode()).hexdigest()
@@ -103,8 +122,6 @@ combinators = set(
for name in combinators: for name in combinators:
sections[name].remove('Combinator') sections[name].remove('Combinator')
# Crosslinks
crosslinks = {} crosslinks = {}
for name, section in sections.items(): for name, section in sections.items():
try: try:
@@ -200,9 +217,15 @@ with doc.body as b:
title = d.h2(name, id=anchor_id, class_='func_name') title = d.h2(name, id=anchor_id, class_='func_name')
title += ' ' title += ' '
title.a('', href='#' + anchor_id, class_='self_link') title.a('', href='#' + anchor_id, class_='self_link')
if name in combinators: with d.p as tags:
d.p.span('combinator', class_='kind') if name in combinators:
d.pre('\n'.join(section)) tags.span('combinator', class_='kind')
tags += ' '
if name in basis_functions:
tags.span('built-in', class_='kind')
foo(d, '\n'.join(section))
def_format(d, name) def_format(d, name)
add_discussion(d, name) add_discussion(d, name)
add_crosslinks(d, name) add_crosslinks(d, name)