[Python-modules-commits] [python-odf] 08/118: Make it possible to remove CSS from XHTML output
Wolfgang Borgert
debacle at moszumanska.debian.org
Fri Oct 3 21:27:16 UTC 2014
This is an automated email from the git hooks/post-receive script.
debacle pushed a commit to reference refs/remotes/upstream/master
in repository python-odf.
commit a6900a5d07366b1552b423afcaf76c4cc78b61d2
Author: Søren Roug <soren.roug at eea.europa.eu>
Date: Fri Oct 17 20:11:23 2008 +0000
Make it possible to remove CSS from XHTML output
---
odf/odf2xhtml.py | 56 +++++++++++++++++++++++++++++++------------------
odf2xhtml/odf2xhtml | 26 +++++++++++++++++------
odf2xhtml/odf2xhtml.1 | 22 ++++++++++++-------
odf2xhtml/odf2xhtml.xml | 23 ++++++++++++++++++++
4 files changed, 93 insertions(+), 34 deletions(-)
diff --git a/odf/odf2xhtml.py b/odf/odf2xhtml.py
index 8042f08..361ae27 100644
--- a/odf/odf2xhtml.py
+++ b/odf/odf2xhtml.py
@@ -336,8 +336,9 @@ special_styles = {
class ODF2XHTML(handler.ContentHandler):
""" The ODF2XHTML parses an ODF file and produces XHTML"""
- def __init__(self):
+ def __init__(self, generate_css = True):
# Tags
+ self.generate_css = generate_css
self.elements = {
(DCNS, 'title'): (self.s_processcont, self.e_dc_title),
(DCNS, 'language'): (self.s_processcont, self.e_dc_contentlanguage),
@@ -566,7 +567,10 @@ class ODF2XHTML(handler.ContentHandler):
style = style + "left:" + attrs[(SVGNS,"x")] + ";"
if attrs.has_key( (SVGNS,"y") ):
style = style + "top:" + attrs[(SVGNS,"y")] + ";"
- self.opentag('div', {'class': name, 'style': style})
+ if self.generate_css:
+ self.opentag('div', {'class': name, 'style': style})
+ else:
+ self.opentag('div')
def e_draw_frame(self, tag, attrs):
""" End the <draw:frame>
@@ -593,8 +597,9 @@ class ODF2XHTML(handler.ContentHandler):
imghref = attrs[(XLINKNS,"href")]
imghref = self.rewritelink(imghref)
htmlattrs = {'alt':"", 'src':imghref }
- if anchor_type != "char":
- htmlattrs['style'] = "display: block;"
+ if self.generate_css:
+ if anchor_type != "char":
+ htmlattrs['style'] = "display: block;"
self.emptytag('img', htmlattrs)
def s_draw_page(self, tag, attrs):
@@ -607,7 +612,10 @@ class ODF2XHTML(handler.ContentHandler):
stylename = stylename.replace(".","_")
masterpage = attrs.get( (DRAWNS,'master-page-name'),"")
masterpage = masterpage.replace(".","_")
- self.opentag('fieldset', {'class':"DP-%s MP-%s" % (stylename, masterpage) })
+ if self.generate_css:
+ self.opentag('fieldset', {'class':"DP-%s MP-%s" % (stylename, masterpage) })
+ else:
+ self.opentag('fieldset')
self.opentag('legend')
self.writeout(escape(name))
self.closetag('legend')
@@ -617,15 +625,16 @@ class ODF2XHTML(handler.ContentHandler):
def html_body(self, tag, attrs):
self.writedata()
- self.opentag('style', {'type':"text/css"}, True)
- self.writeout('/*<![CDATA[*/\n')
- self.writeout('\nimg { width: 100%; height: 100%; }\n')
- self.writeout('* { padding: 0; margin: 0; }\n')
- self.writeout('body { margin: 0 1em; }\n')
- self.writeout('ol, ul { padding-left: 2em; }\n')
- self.generate_stylesheet()
- self.writeout('/*]]>*/\n')
- self.closetag('style')
+ if self.generate_css:
+ self.opentag('style', {'type':"text/css"}, True)
+ self.writeout('/*<![CDATA[*/\n')
+ self.writeout('\nimg { width: 100%; height: 100%; }\n')
+ self.writeout('* { padding: 0; margin: 0; }\n')
+ self.writeout('body { margin: 0 1em; }\n')
+ self.writeout('ol, ul { padding-left: 2em; }\n')
+ self.generate_stylesheet()
+ self.writeout('/*]]>*/\n')
+ self.closetag('style')
self.purgedata()
self.closetag('head')
self.opentag('body', block=True)
@@ -660,7 +669,10 @@ class ODF2XHTML(handler.ContentHandler):
def generate_footnotes(self):
if self.currentnote == 0:
return
- self.opentag('ol', {'style':'border-top: 1px solid black'}, True)
+ if self.generate_css:
+ self.opentag('ol', {'style':'border-top: 1px solid black'}, True)
+ else:
+ self.opentag('ol')
for key in range(1,self.currentnote+1):
note = self.notedict[key]
# for key,note in self.notedict.items():
@@ -874,7 +886,7 @@ class ODF2XHTML(handler.ContentHandler):
""" Start a table
"""
c = attrs.get( (TABLENS,'style-name'), None)
- if c:
+ if c and self.generate_css:
c = c.replace(".","_")
self.opentag('table',{ 'class': "T-%s" % c })
else:
@@ -958,7 +970,7 @@ class ODF2XHTML(handler.ContentHandler):
for x in range(level + 1,10):
self.headinglevels[x] = 0
special = special_styles.get("P-"+name)
- if special:
+ if special or not self.generate_css:
self.opentag('h%s' % level)
else:
self.opentag('h%s' % level, {'class':"P-%s" % name })
@@ -997,7 +1009,10 @@ class ODF2XHTML(handler.ContentHandler):
# textbox itself may be nested within another list.
level = self.tagstack.count_tags(tag) + 1
name = self.tagstack.rfindattr( (TEXTNS,'style-name') )
- self.opentag('%s' % self.listtypes.get(name), {'class':"%s_%d" % (name, level) })
+ if self.generate_css:
+ self.opentag('%s' % self.listtypes.get(name), {'class':"%s_%d" % (name, level) })
+ else:
+ self.opentag('%s' % self.listtypes.get(name))
self.purgedata()
def e_text_list(self, tag, attrs):
@@ -1113,7 +1128,8 @@ class ODF2XHTML(handler.ContentHandler):
specialtag = special_styles.get("P-"+c)
if specialtag is None:
specialtag = 'p'
- htmlattrs['class'] = "P-%s" % c
+ if self.generate_css:
+ htmlattrs['class'] = "P-%s" % c
self.opentag(specialtag, htmlattrs)
self.purgedata()
@@ -1149,7 +1165,7 @@ class ODF2XHTML(handler.ContentHandler):
if c:
c = c.replace(".","_")
special = special_styles.get("S-"+c)
- if special is None:
+ if special is None and self.generate_css:
htmlattrs['class'] = "S-%s" % c
self.opentag('span', htmlattrs)
self.purgedata()
diff --git a/odf2xhtml/odf2xhtml b/odf2xhtml/odf2xhtml
index 16fd0f5..f7b884e 100755
--- a/odf2xhtml/odf2xhtml
+++ b/odf2xhtml/odf2xhtml
@@ -18,20 +18,34 @@
# Contributor(s):
#
from odf.odf2xhtml import ODF2XHTML
-import sys
+import sys, getopt
try:
from cStringIO import StringIO
except ImportError:
from StringIO import StringIO
-if len(sys.argv) != 2:
- sys.stderr.write("Usage: %s inputfile\n" % sys.argv[0])
- sys.exit(1)
+def usage():
+ sys.stderr.write("Usage: %s [-p] inputfile\n" % sys.argv[0])
+
+try:
+ opts, args = getopt.getopt(sys.argv[1:], "p", ["plain"])
+except getopt.GetoptError:
+ usage()
+ sys.exit(2)
+
+generatecss = True
+for o, a in opts:
+ if o in ("-p", "--plain"):
+ generatecss = False
+
+if len(args) != 1:
+ usage()
+ sys.exit(2)
-odhandler = ODF2XHTML()
+odhandler = ODF2XHTML(generatecss)
try:
- result = odhandler.odf2xhtml(sys.argv[1]).encode('us-ascii','xmlcharrefreplace')
+ result = odhandler.odf2xhtml(args[0]).encode('us-ascii','xmlcharrefreplace')
except:
sys.stderr.write("Unable to open file %s or file is not OpenDocument\n" % sys.argv[1])
sys.exit(1)
diff --git a/odf2xhtml/odf2xhtml.1 b/odf2xhtml/odf2xhtml.1
index fd9e13e..e8cbd31 100644
--- a/odf2xhtml/odf2xhtml.1
+++ b/odf2xhtml/odf2xhtml.1
@@ -1,26 +1,32 @@
.\" Title: odf2xhtml
.\" Author:
-.\" Generator: DocBook XSL Stylesheets v1.72.0 <http://docbook.sf.net/>
-.\" Date: 09/29/2007
+.\" Generator: DocBook XSL Stylesheets v1.73.2 <http://docbook.sf.net/>
+.\" Date: 10/17/2008
.\" Manual:
-.\" Source:
+.\" Source: odfpy
.\"
-.TH "ODF2XHTML" "1" "09/29/2007" "" ""
+.TH "ODF2XHTML" "1" "10/17/2008" "odfpy" ""
.\" disable hyphenation
.nh
.\" disable justification (adjust text to left margin only)
.ad l
.SH "NAME"
-odf2xhtml \- Convert ODF to HTML
+odf2xhtml - Convert ODF to HTML
.SH "SYNOPSIS"
.HP 10
-\fBodf2xhtml\fR \fIpath\fR
+\fBodf2xhtml\fR [\-e] \fIpath\fR
.SH "DESCRIPTION"
.PP
\fBodf2xhtml\fR
-is a program that will create a webpage (.html) from the input file and will write the webpage to stdout.
+is a program that will create a webpage (\.html) from the input file and will write the webpage to stdout\.
.PP
-"Path" is assumed to be an OpenDocument file of text, spreadsheet or presentation type.
+"Path" is assumed to be an OpenDocument file of text, spreadsheet or presentation type\.
+.SH "OPTIONS"
+.PP
+\-p, \-\-plain
+.RS 4
+The \-p flag will generate HTML without CSS\.
+.RE
.SH "EXAMPLE"
.sp
.RS 4
diff --git a/odf2xhtml/odf2xhtml.xml b/odf2xhtml/odf2xhtml.xml
index 2313a12..86803a0 100644
--- a/odf2xhtml/odf2xhtml.xml
+++ b/odf2xhtml/odf2xhtml.xml
@@ -1,6 +1,13 @@
<?xml version="1.0"?>
<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN" "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
<refentry id="odf2xhtml">
+ <refentryinfo>
+ <productname>odfpy</productname>
+ </refentryinfo>
+ <refmeta>
+ <refentrytitle>odf2xhtml</refentrytitle>
+ <manvolnum>1</manvolnum>
+ </refmeta>
<refnamediv>
<refname>odf2xhtml</refname>
<refpurpose>Convert ODF to HTML</refpurpose>
@@ -8,6 +15,7 @@
<refsynopsisdiv>
<cmdsynopsis>
<command>odf2xhtml</command>
+ <arg choice="opt">-e </arg>
<arg choice="plain">
<replaceable>path</replaceable>
</arg>
@@ -23,6 +31,21 @@ a webpage (.html) from the input file and will write the webpage to stdout.
OpenDocument file of text, spreadsheet or presentation type.
</para>
</refsect1>
+
+ <refsect1>
+ <title>Options</title>
+ <variablelist>
+ <varlistentry>
+ <term>-p, --plain</term>
+ <listitem>
+ <para>
+The -p flag will generate HTML without CSS.
+</para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </refsect1>
+
<refsect1>
<title>Example</title>
<screen>
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/python-odf.git
More information about the Python-modules-commits
mailing list