Here are the examples of the python api twisted.web.domhelpers.getNodeText taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
9 Examples
3
Example 1
Project: SubliminalCollaborator Source File: latex.py
def visitNode_a_listing(self, node):
fileName = os.path.join(self.currDir, node.getAttribute('href'))
self.writer('\\begin{verbatim}\n')
lines = map(str.rstrip, open(fileName).readlines())
skipLines = int(node.getAttribute('skipLines') or 0)
lines = lines[skipLines:]
self.writer(text.removeLeadingTrailingBlanks('\n'.join(lines)))
self.writer('\\end{verbatim}')
# Write a caption for this source listing
fileName = os.path.basename(fileName)
caption = domhelpers.getNodeText(node)
if caption == fileName:
caption = 'Source listing'
self.writer('\parbox[b]{\linewidth}{\\begin{center}%s --- '
'\\begin{em}%s\\end{em}\\end{center}}'
% (latexEscape(caption), latexEscape(fileName)))
3
Example 2
Project: SubliminalCollaborator Source File: tree.py
def _replaceWithListing(node, val, filename, class_):
captionTitle = domhelpers.getNodeText(node)
if captionTitle == os.path.basename(filename):
captionTitle = 'Source listing'
text = ('<div class="%s">%s<div class="caption">%s - '
'<a href="%s"><span class="filename">%s</span></a></div></div>' %
(class_, val, captionTitle, filename, filename))
newnode = dom.parseString(text).docuementElement
node.parentNode.replaceChild(newnode, node)
3
Example 3
def test_getNodeText(self):
"""
L{getNodeText} returns the concatenation of all the text data at or
beneath the node passed to it.
"""
node = self.dom.parseString('<foo><bar>baz</bar><bar>quux</bar></foo>')
self.assertEqual(domhelpers.getNodeText(node), "bazquux")
3
Example 4
Project: SubliminalCollaborator Source File: test_domhelpers.py
def test_getNodeUnicodeText(self):
"""
L{domhelpers.getNodeText} returns a C{unicode} string when text
nodes are represented in the DOM with unicode, whether or not there
are non-ASCII characters present.
"""
node = self.dom.parseString("<foo>bar</foo>")
text = domhelpers.getNodeText(node)
self.assertEqual(text, u"bar")
self.assertIsInstance(text, unicode)
node = self.dom.parseString(u"<foo>\N{SNOWMAN}</foo>".encode('utf-8'))
text = domhelpers.getNodeText(node)
self.assertEqual(text, u"\N{SNOWMAN}")
self.assertIsInstance(text, unicode)
0
Example 5
Project: SubliminalCollaborator Source File: latex.py
def visitNode_a_href(self, node):
supported_schemes=['http', 'https', 'ftp', 'mailto']
href = node.getAttribute('href')
if urlparse.urlparse(href)[0] in supported_schemes:
text = domhelpers.getNodeText(node)
self.visitNodeDefault(node)
if text != href:
self.writer('\\footnote{%s}' % latexEscape(href))
else:
path, fragid = (href.split('#', 1) + [None])[:2]
if path == '':
path = self.filename
else:
path = os.path.join(os.path.dirname(self.filename), path)
#if path == '':
#path = os.path.basename(self.filename)
#else:
# # Hack for linking to man pages from howtos, i.e.
# # ../doc/foo-man.html -> foo-man.html
# path = os.path.basename(path)
path = realpath(path)
if fragid:
ref = path + 'HASH' + fragid
else:
ref = path
self.writer('\\textit{')
self.visitNodeDefault(node)
self.writer('}')
self.writer('\\loreref{%s}' % ref)
0
Example 6
Project: SubliminalCollaborator Source File: lmath.py
def visitNode_div_latexmacros(self, node):
self.writer(domhelpers.getNodeText(node))
0
Example 7
Project: SubliminalCollaborator Source File: lmath.py
def visitNode_span_latexformula(self, node):
self.writer('\[')
self.writer(domhelpers.getNodeText(node))
self.writer('\]')
0
Example 8
def visitNode_title(self, node):
self.title = domhelpers.getNodeText(node)
0
Example 9
Project: SubliminalCollaborator Source File: tree.py
def generateToC(docuement):
"""
Create a table of contents for the given docuement.
@type docuement: A DOM Node or Docuement
@rtype: A DOM Node
@return: a Node containing a table of contents based on the headers of the
given docuement.
"""
subHeaders = None
headers = []
for element in getHeaders(docuement):
if element.tagName == 'h2':
subHeaders = []
headers.append((element, subHeaders))
elif subHeaders is None:
raise ValueError(
"No H3 element is allowed until after an H2 element")
else:
subHeaders.append(element)
auto = count().next
def addItem(headerElement, parent):
anchor = dom.Element('a')
name = 'auto%d' % (auto(),)
anchor.setAttribute('href', '#' + name)
text = dom.Text()
text.data = domhelpers.getNodeText(headerElement)
anchor.appendChild(text)
headerNameItem = dom.Element('li')
headerNameItem.appendChild(anchor)
parent.appendChild(headerNameItem)
anchor = dom.Element('a')
anchor.setAttribute('name', name)
headerElement.appendChild(anchor)
toc = dom.Element('ol')
for headerElement, subHeaders in headers:
addItem(headerElement, toc)
if subHeaders:
subtoc = dom.Element('ul')
toc.appendChild(subtoc)
for subHeaderElement in subHeaders:
addItem(subHeaderElement, subtoc)
return toc