mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Update RapydScript
This commit is contained in:
parent
a332b5f182
commit
b44c770bfd
@ -36,27 +36,8 @@ svg_elements = {
|
|||||||
|
|
||||||
html5_tags = html_elements.union(mathml_elements).union(svg_elements)
|
html5_tags = html_elements.union(mathml_elements).union(svg_elements)
|
||||||
|
|
||||||
def _dummy_create_element(name):
|
def _makeelement(tag, *args, **kwargs):
|
||||||
return {
|
ans = this.createElement(tag)
|
||||||
'name':name,
|
|
||||||
'children':[],
|
|
||||||
'attributes':{},
|
|
||||||
'setAttribute': def(name, val): this.attributes[name] = val;,
|
|
||||||
'appendChild': def(child): this.children.push(child);,
|
|
||||||
}
|
|
||||||
|
|
||||||
def _dummy_create_text(value):
|
|
||||||
return value
|
|
||||||
|
|
||||||
if type(document) == 'undefined':
|
|
||||||
create_element = _dummy_create_element
|
|
||||||
create_text_node = _dummy_create_text
|
|
||||||
else:
|
|
||||||
create_element = def(name): return document.createElement(name)
|
|
||||||
create_text_node = def(val): return document.createTextNode(val)
|
|
||||||
|
|
||||||
def E(tag, *args, **kwargs):
|
|
||||||
ans = create_element(tag)
|
|
||||||
|
|
||||||
for attr in kwargs:
|
for attr in kwargs:
|
||||||
vattr = str.replace(str.rstrip(attr, '_'), '_', '-')
|
vattr = str.replace(str.rstrip(attr, '_'), '_', '-')
|
||||||
@ -70,14 +51,28 @@ def E(tag, *args, **kwargs):
|
|||||||
|
|
||||||
for arg in args:
|
for arg in args:
|
||||||
if type(arg) == 'string':
|
if type(arg) == 'string':
|
||||||
ans.appendChild(create_text_node(arg))
|
arg = this.createTextNode(arg)
|
||||||
else:
|
ans.appendChild(arg)
|
||||||
ans.appendChild(arg)
|
|
||||||
return ans
|
return ans
|
||||||
|
|
||||||
def bind_e(tag):
|
def maker_for_document(document):
|
||||||
return def(*args, **kwargs):
|
# Create an elementmaker to be used with the specified document
|
||||||
return E(tag, *args, **kwargs)
|
E = _makeelement.bind(document)
|
||||||
|
for tag in html5_tags:
|
||||||
|
Object.defineProperty(E, tag, {'value':_makeelement.bind(document, tag)})
|
||||||
|
return E
|
||||||
|
|
||||||
for tag in html5_tags:
|
if type(document) == 'undefined':
|
||||||
Object.defineProperty(E, tag, {'value':bind_e(tag)})
|
E = maker_for_document({
|
||||||
|
'createTextNode': def(value): return value;,
|
||||||
|
'createElement': def(name):
|
||||||
|
return {
|
||||||
|
'name':name,
|
||||||
|
'children':[],
|
||||||
|
'attributes':{},
|
||||||
|
'setAttribute': def(name, val): this.attributes[name] = val;,
|
||||||
|
'appendChild': def(child): this.children.push(child);,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
else:
|
||||||
|
E = maker_for_document(document)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user