Module tf.browser.html
HTML generation done in the Pythonic way.
Global variables
var H_ELEMENTS
-
The HTML elements used in this tool.
Functions
def dig(*content, sep='')
-
Expand source code Browse git
def dig(*content, sep=""): """A method to join nested iterables of strings into a string. Parameters ---------- content: iterable or string Arbitrarily nested iterable of strings. sep: string, optional "" The string by which the individual strings from the iterables are to be joined. Returns ------- string The fully joined string corresponding to the original iterables. """ if len(content) == 0: return "" if len(content) == 1: content = content[0] return ( sep.join(dig(c) for c in content) if isIterable(content) else str(content) ) return sep.join(dig(c) for c in content)
A method to join nested iterables of strings into a string.
Parameters
content
:iterable
orstring
- Arbitrarily nested iterable of strings.
sep
:string
, optional""
- The string by which the individual strings from the iterables are to be joined.
Returns
string
- The fully joined string corresponding to the original iterables.
def elemFunc(close, elem)
-
Expand source code Browse git
def elemFunc(close, elem): """Generates a function to serialize a specific HTML element. Parameters ---------- close: boolean Whether the element needs an end tag. elem: string The name of the element. Returns ------- function The function has the same signature as `generate()` except it does not take the parameters `close` and `tag`. """ if close: def result(*content, **atts): return generate(close, elem, *content, **atts) else: def result(**atts): return generate(close, elem, **atts) return result
Generates a function to serialize a specific HTML element.
Parameters
close
:boolean
- Whether the element needs an end tag.
elem
:string
- The name of the element.
Returns
function
- The function has the same signature as
generate()
except it does not take the parametersclose
andtag
.
def generate(close, tag, *content, **atts)
-
Expand source code Browse git
def generate(close, tag, *content, **atts): """Transform the logical information for an HTML element into an HTML string. Parameters ---------- close: boolean Whether the element must be closed with an end tag. tag: string The name of the tag. content: iterable The content of the element. This may be an arbitrarily nested iterable of strings. atts: dict The attributes of the element. Returns ------- string The HTML string representation of an element. """ endRep = f"""</{tag}>""" if close else "" attsRep = " ".join( (k if vl else "") if type(vl) is bool else f'''{"class" if k == "cls" else k}="{vl}"''' for (k, vl) in atts.items() ) if attsRep: attsRep = f" {attsRep}" contentRep = dig(content) return f"""<{tag}{attsRep}>{contentRep}{endRep}"""
Transform the logical information for an HTML element into an HTML string.
Parameters
close
:boolean
- Whether the element must be closed with an end tag.
tag
:string
- The name of the tag.
content
:iterable
- The content of the element. This may be an arbitrarily nested iterable of strings.
atts
:dict
- The attributes of the element.
Returns
string
- The HTML string representation of an element.
Classes
class H
-
Expand source code Browse git
class H: """Provider of HTML serializing functions per element type. Also has a class attribute `nb`: the non-breaking space. For each HTML element in the specs (`H_ELEMENTS`) a corresponding generating function is added as method. """ nb = NBSP
Provider of HTML serializing functions per element type.
Also has a class attribute
nb
: the non-breaking space.For each HTML element in the specs (
H_ELEMENTS
) a corresponding generating function is added as method.Class variables
var nb
-
The type of the None singleton.
Methods
def a(*content, **atts)
-
Expand source code Browse git
def result(*content, **atts): return generate(close, elem, *content, **atts)
def b(*content, **atts)
-
Expand source code Browse git
def result(*content, **atts): return generate(close, elem, *content, **atts)
def br(**atts)
-
Expand source code Browse git
def result(**atts): return generate(close, elem, **atts)
-
Expand source code Browse git
def result(*content, **atts): return generate(close, elem, *content, **atts)
def code(*content, **atts)
-
Expand source code Browse git
def result(*content, **atts): return generate(close, elem, *content, **atts)
def details(*content, **atts)
-
Expand source code Browse git
def result(*content, **atts): return generate(close, elem, *content, **atts)
def div(*content, **atts)
-
Expand source code Browse git
def result(*content, **atts): return generate(close, elem, *content, **atts)
def i(*content, **atts)
-
Expand source code Browse git
def result(*content, **atts): return generate(close, elem, *content, **atts)
def input(**atts)
-
Expand source code Browse git
def result(**atts): return generate(close, elem, **atts)
def join(*content, sep='')
-
Expand source code Browse git
def dig(*content, sep=""): """A method to join nested iterables of strings into a string. Parameters ---------- content: iterable or string Arbitrarily nested iterable of strings. sep: string, optional "" The string by which the individual strings from the iterables are to be joined. Returns ------- string The fully joined string corresponding to the original iterables. """ if len(content) == 0: return "" if len(content) == 1: content = content[0] return ( sep.join(dig(c) for c in content) if isIterable(content) else str(content) ) return sep.join(dig(c) for c in content)
A method to join nested iterables of strings into a string.
Parameters
content
:iterable
orstring
- Arbitrarily nested iterable of strings.
sep
:string
, optional""
- The string by which the individual strings from the iterables are to be joined.
Returns
string
- The fully joined string corresponding to the original iterables.
def li(*content, **atts)
-
Expand source code Browse git
def result(*content, **atts): return generate(close, elem, *content, **atts)
def ol(*content, **atts)
-
Expand source code Browse git
def result(*content, **atts): return generate(close, elem, *content, **atts)
def option(*content, **atts)
-
Expand source code Browse git
def result(*content, **atts): return generate(close, elem, *content, **atts)
def p(*content, **atts)
-
Expand source code Browse git
def result(*content, **atts): return generate(close, elem, *content, **atts)
def select(*content, **atts)
-
Expand source code Browse git
def result(*content, **atts): return generate(close, elem, *content, **atts)
def span(*content, **atts)
-
Expand source code Browse git
def result(*content, **atts): return generate(close, elem, *content, **atts)
def style(*content, **atts)
-
Expand source code Browse git
def result(*content, **atts): return generate(close, elem, *content, **atts)
def summary(*content, **atts)
-
Expand source code Browse git
def result(*content, **atts): return generate(close, elem, *content, **atts)
def table(*content, **atts)
-
Expand source code Browse git
def result(*content, **atts): return generate(close, elem, *content, **atts)
def td(*content, **atts)
-
Expand source code Browse git
def result(*content, **atts): return generate(close, elem, *content, **atts)
def tr(*content, **atts)
-
Expand source code Browse git
def result(*content, **atts): return generate(close, elem, *content, **atts)
def ul(*content, **atts)
-
Expand source code Browse git
def result(*content, **atts): return generate(close, elem, *content, **atts)