This is a test notebookΒΆ
In [4]:
import sys
import re
In [5]:
f = open("transforms.md", "r")
contents = f.read()
In [6]:
t = "hello {{method Jeremy}} there {{method close}}"
In [7]:
def do_method(ps): return str(ps)
In [11]:
fn_lu = {#'class': sub_class,
#'arguments': sub_arguments,
#'arg': sub_arg,
#'xref': sub_xref,
#'methods': sub_methods,
'method': do_method}
In [ ]:
def sub_methods():
"""<h3 class="methods">Methods</h3>
<ul class="methodlist">"""
In [ ]:
def sub_method(ps):
return f'<li id="Transform-set_state" class="method">'
In [12]:
def do_tmpl(s):
inner = s.group(1)
fn_name,*params = inner.split(' ')
fn = fn_lu[fn_name]
return fn(params)
In [13]:
re.sub(r"{{(.*?)}}", do_tmpl, t)
Out[13]:
"hello ['Jeremy'] there ['close']"