예제 #1
0
def _inline_css(e, source_dir, dom, files):
    """Inlines CSS"""
    # Only use CSS stylesheet tags
    if e.nodeType != Node.ELEMENT_NODE \
            or e.tagName != 'link' \
            or e.getAttribute('rel') != 'stylesheet' \
            or e.getAttribute('type') != 'text/css':
        return

    # Read the stylesheet and inline it
    href_path = _src_to_path(
        source_dir,
        e.getAttribute('href'))
    with open(href_path, 'rb') as href:
        cdata = CDATASection()
        cdata.replaceWholeText(href.read().decode('utf-8'))
        e.appendChild(cdata)

    # Remove all attributes except for type
    for i in range(e.attributes.length):
        attribute = e.attributes.item(i)
        if not attribute:
            continue
        if attribute.name == 'type':
            continue
        e.removeAttribute(attribute.name)

    # Change the tag name
    e.tagName = 'style'

    files.append(href_path)
    def test_marshall_cdata(self):
        span = SimpleXMLElement('<span/>')
        cdata = CDATASection()
        cdata.data = 'python'
        span.add_child('a', cdata)

        xml = '<?xml version="1.0" encoding="UTF-8"?><span><a><![CDATA[python]]></a></span>'
        self.eq(span.as_xml(), xml if PY2 else xml.encode('utf-8'))
    def test_marshall_cdata(self):
        span = SimpleXMLElement('<span/>')
        cdata = CDATASection()
        cdata.data = 'python'
        span.add_child('a', cdata)

        xml = '<?xml version="1.0" encoding="UTF-8"?><span><a><![CDATA[python]]></a></span>'
        self.eq(span.as_xml(), xml if PY2 else xml.encode('utf-8'))
예제 #4
0
 def _adder(self, other, parent):
     """This is a helper function so it's possible to go
     recursively through adding elements"""
     if(self == other):
         raise SelfReference('Your adding your self') 
     if type(other).__name__=="list" or type(other).__name__=="List":
         last = None
         for other_element in other:
             if type(other_element).__name__=="list":
                 if(last):
                     self._adder(other_element, last)
                     last = List(other_element)
                     last.parent = parent
                 else:
                     raise EmptyList("You cant start with two lists")
             elif type(other_element).__name__=="str" or \
                  type(other).__name__=="int":
                 cdata = CDATASection()
                 cdata.data = str(other_element)
                 element = parent.getelement()
                 element.appendChild(cdata)
                 last = other_element
             elif type(other_element).__name__=="xulelement":
                 if type(parent).__name__=="List":
                     if parent.parent:
                         element = parent.parent.getelement()
                         eelement = other_element.getelement()
                         element.appendChild(eelement)
                         last = other_element 
                     else:
                         raise ParentList(\
                               "You can't have list as an parent")
                 elif type(parent).__name__=="list":
                     raise ParentList(\
                           "You can't have list as an parent")
                 else:
                     element = parent.getelement()
                     eelement = other_element.getelement()
                     element.appendChild(eelement)
                     last = other_element
             else:
                 print("What is happening")
                 print("type: "+type(other).__name__)
     elif type(other).__name__=="str" or type(other).__name__=="int":
         cdata = CDATASection()
         cdata.data = str(other)
         element = parent.getelement() 
         element.appendChild(cdata)
     elif type(other).__name__=="xulelement":
         element = parent.getelement()
         oelement = other.getelement()
         element.appendChild(oelement)
     else:
         print("What is happening")
         print("type: "+type(other).__name__)
예제 #5
0
def _inline_script(e, source_dir, dom, files):
    """Inlines script tags"""
    # Only use script tags with src attribute
    if e.nodeType != Node.ELEMENT_NODE \
            or e.tagName != 'script' \
            or not e.hasAttribute('src') \
            or e.getAttribute('x-no-inline') == 'true':
        return

    # Read the script source and inline it
    src_path = _src_to_path(
        source_dir,
        e.getAttribute('src'))
    with open(src_path, 'rb') as src:
        cdata = CDATASection()
        cdata.replaceWholeText(src.read().decode('utf-8'))
        e.appendChild(cdata)

    # Make sure to remove the src attribute
    e.removeAttribute('src')

    files.append(src_path)
예제 #6
0
파일: tags.py 프로젝트: kriskowal/planes
 def cdata(self, text):
     cdata = CDATASection()
     cdata.replaceWholeText(text)
     return cdata
		"data": [-169,-58,180,86],
	}
	, "export": {
		"round": 1
		#, "width": 480
		#, "height": 310
		, "width": 1720
		, "height": 948
	}
}

Kartograph().generate(conf, outfile=FILE, stylesheet=open("kartograph.css").read())

svg = parse(FILE)

svg.documentElement.setAttribute('width', '100%')
svg.documentElement.removeAttribute('height')



cd = CDATASection()
#cd.data = open("style-small.css", "r").read()
cd.data = open("style.css", "r").read()

style = svg.createElement('style')
style.appendChild(cd)

svg.getElementsByTagName("defs")[0].appendChild(style)

svg.writexml(open(FILE, "w"))