root/livinglogic.python.xist/src/ll/xist/ns/text.py @ 2590:7b6bba35f3a0

Revision 2590:7b6bba35f3a0, 2.4 KB (checked in by Walter Doerwald <walter@…>, 13 years ago)

htmlspecials.pixel() now no longer uses colored pixels, instead color is
done via CSS. The URL for the one remaining transparent pixel can now be
specified via src (either as an XML attribute or via the converter context).

Rename attrs methods with() and without() to withnames() and withoutnames()
(for Python 2.5 compatibility).

Use elinks instead of w3m for asText() and move/rename this method to a
function ll.xist.ns.html.astext().

Try to make XIST independent from PyXML (however PyXML is still required
for parsing via expat and for dtd2xsc.py (because this requires xmlproc)).

Remove the long dperecated method withSep().

Use Py_ssize_t in the C source where appropriate.

Line 
1#! /usr/bin/env python
2# -*- coding: iso-8859-1 -*-
3
4## Copyright 1999-2006 by LivingLogic AG, Bayreuth/Germany.
5## Copyright 1999-2006 by Walter Dörwald
6##
7## All Rights Reserved
8##
9## See xist/__init__.py for the license
10
11"""
12<par>An &xist; namespace that contains definitions for all the elements and
13entities in <link href="http://www.w3.org/TR/html4/loose.dtd">&html; 4.0 transitional</link>
14(and a few additional ones).</par>
15"""
16
17__version__ = "$Revision$".split()[1]
18# $Source$
19
20import cgi # for parse_header
21
22from ll.xist import xsc
23from ll.xist.ns import html as html_, chars
24
25
26class html(html_.html):
27    def fixcharacters(self, node, converter):
28        if isinstance(node, xsc.Text):
29            node = node.replace(unichr(chars.mdash.codepoint), u"--")
30            node = node.replace(unichr(chars.ndash.codepoint), u"-")
31            node = node.replace(u"\u200b", u"")
32            node = node.replace(unichr(chars.Alpha.codepoint), u"Alpha")
33            node = node.replace(unichr(chars.Beta.codepoint), u"Beta")
34            node = node.replace(unichr(chars.Gamma.codepoint), u"Gamma")
35            node = node.replace(unichr(chars.alpha.codepoint), u"alpha")
36            node = node.replace(unichr(chars.beta.codepoint), u"beta")
37            node = node.replace(unichr(chars.gamma.codepoint), u"gamma")
38        return node
39
40    def convert(self, converter):
41        e = html_.html(self.content.convert(converter), self.attrs.convert(converter))
42        e = e.mapped(self.fixcharacters, converter)
43        return e
44
45
46class HeaderFormattingMixin(object):
47    underline = None
48
49    def convert(self, converter):
50        target = converter.target
51        content = unicode(self.content.convert(converter))
52        l = len(content)
53        if self.underline:
54            underline = ((self.underline*l)[:l], target.br())
55        else:
56            underline = None
57        e = self.base(
58            target.br(),
59            self.content, target.br(),
60            underline
61        )
62        return e.convert(converter)
63
64
65class h1(HeaderFormattingMixin, html_.h1):
66    underline = u"="
67    base = html_.h1
68
69
70class h2(HeaderFormattingMixin, html_.h2):
71    underline = u"="
72    base = html_.h2
73
74
75class h3(HeaderFormattingMixin, html_.h3):
76    underline = u"-"
77    base = html_.h3
78
79
80class h4(HeaderFormattingMixin, html_.h4):
81    underline = u"-"
82    base = html_.h4
83
84
85class h5(HeaderFormattingMixin, html_.h5):
86    underline = u"-"
87    base = html_.h5
88
89
90class h6(HeaderFormattingMixin, html_.h6):
91    underline = u"-"
92    base = html_.h6
93
94
95class __ns__(html_):
96    xmlname = "text"
97    xmlurl = "http://xmlns.livinglogic.de/xist/ns/text"
98__ns__.makemod(vars())
Note: See TracBrowser for help on using the browser.