htexpr package¶
Submodules¶
htexpr.htexpr module¶
Parse HTML with embedded Python expressions into Python code objects
-
class
htexpr.htexpr.Htexpr(html, *, map_tag=None, map_attribute=None)¶ Bases:
objectA code object that can be evaluated to effect a sequence of function calls.
-
code¶
-
eval(bindings={})¶ Evaluate the code object with the given bindings.
The bindings should include any global variables such as imports of
dash.html. A more convenient method that captures these automatically isrun().Example:
from dash import html htexpr.compile( "<div>[(<span>{i}</span>) for i in range(10) if i not in removed]</div>" ).eval({**globals(), "removed": {1, 2, 3}})
-
run(**bindings)¶ Evaluate the code object with the given bindings added to globals and locals.
The globals are obtained using
sys._getframe(), which is intended “for internal and specialized purposes only”. A cleaner method that avoids this kind of magic iseval().Example:
from dash import html as html htexpr.compile( "<div>[(<span>{i}</span>) for i in range(10) if i not in removed]</div>" ).run(removed={1, 2, 3})
-
-
htexpr.htexpr.compile¶ Compile the html string into an Htexpr object.
Parameters: - map_tag – tuple of callables or mappings that return for tag
names the corresponding pair (module name, function name);
the default is
htexpr.mappings.defaultwhich allows writinghtmltags in any case but does not convert the case ofdccordash_tabletags. For backward compatibility, a single callable is allowed. - map_attribute – mapping from attribute names to function
parameters; attributes not found in the mapping are passed
as-is. The default (
mappings.default_attributes) mapsclasstoclassNameand some lower-case attributes to camel case, such asrowspantorowSpan.
Returns: the compiled code
Return type: - map_tag – tuple of callables or mappings that return for tag
names the corresponding pair (module name, function name);
the default is
-
htexpr.htexpr.parse(html)¶
-
htexpr.htexpr.simplify(tree)¶
-
htexpr.htexpr.to_ast(tree, map_tag=None, map_attribute=None)¶
-
htexpr.htexpr.wrap_ast(body)¶
htexpr.mappings module¶
Functions or mappings for use with htexpr.compile().
default is a suitable value for the map_tag argument
of compile(); it assumes that
dash.htmlis imported ashtmldash.dccis imported asdccdash.tableis imported asdash_table
and allows you to type html tags in any case but requires title
case for the others.
dbc_and_default is similar, but adds in the front
dash_bootstrap_components as dbc. To type html tags
shadowed by dbc tags, use non-title case.
If you import the modules under other names, you can instantiate the mapping functions with those, e.g.:
other_names = [html('dash_html_components'), dcc('dash_core_components')]
default_attributes is the default value for the
map_attribute argument of compile()
-
htexpr.mappings.datatable¶ Mapping for DataTable.
-
htexpr.mappings.dbc¶ Mapping for dash bootstrap components.
The default assumes that
dash_bootstrap_componentsis imported asdbc, which can be changed by setting module.
-
htexpr.mappings.dcc¶ Mapping for dash core components.
-
htexpr.mappings.html¶ Mapping for html tags.
Maps tags to title case, so you can type html tags as
<audio>or<AuDiO>or whichever way.