1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284
|
#
# $Id: formatter_DocBook.py,v 1.1 2001/10/24 21:27:35 doughellmann Exp $
#
# Copyright 2001 Balazs Scheidler
#
#
# All Rights Reserved
#
# Permission to use, copy, modify, and distribute this software and
# its documentation for any purpose and without fee is hereby
# granted, provided that the above copyright notice appear in all
# copies and that both that copyright notice and this permission
# notice appear in supporting documentation, and that the name of Balazs
# Scheidler not be used in advertising or publicity pertaining to
# distribution of the software without specific, written prior
# permission.
#
# BALAZS SCHEIDLER DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
# INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
# NO EVENT SHALL BALAZS SCHEIDLER BE LIABLE FOR ANY SPECIAL, INDIRECT OR
# CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
# OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#
"""Formatter which produces simple DocBook SGML.
"""
__rcs_info__ = {
#
# Creation Information
#
'module_name' : '$RCSfile: formatter_DocBook.py,v $',
'rcs_id' : '$Id: formatter_DocBook.py,v 1.1 2001/10/24 21:27:35 doughellmann Exp $',
'creator' : 'Balazs Scheidler <bazsi@balabit.hu>',
'project' : 'HappyDoc',
'created' : 'Sat, 03-Feb-2001 12:53:37 EST',
#
# Current Information
#
'author' : '$Author: doughellmann $',
'version' : '$Revision: 1.1 $',
'date' : '$Date: 2001/10/24 21:27:35 $',
}
try:
__version__ = __rcs_info__['version'].split(' ')[1]
except:
__version__ = '0.0'
#
# Import Local modules
#
import happydoclib
import happydoclib.formatter.fileformatterbase
#
# Module
#
def entryPoint():
"Return information about this module to the dynamic loader."
return {
'name':'SGMLDocBook',
'factory':DocBookFormatter,
}
class DocBookFormatter(happydoclib.formatter.fileformatterbase.FileBasedFormatter):
'''Formatter which produces simple DocBook SGML.'''
def __init__(self, docSet, **configuration):
self._section_level_counter = 1
self.debug = 0
apply(happydoclib.formatter.fileformatterbase.FileBasedFormatter.__init__,
(self, docSet),
configuration)
return
def openOutput(self, name, title1, title2=""):
"""Write the formatting for a file header to the open file."""
f = happydoclib.formatter.fileformatterbase.FileBasedFormatter.openOutput(
self,
name,
title1)
self.fileHeader(title1, title2, f)
return f
def closeOutput(self, output):
"Close the 'output' handle."
self.fileFooter(output)
output.close()
return
def fileHeader(self, title1, title2, output):
self.comment('file_header', output)
return
def fileFooter(self, output):
self.comment('file_footer', output)
return
# string handling
def writeText(self, text, output, textFormat, quote=0):
"""Format and write the 'text' to the 'output'.
Arguments:
'text' -- String to be written.
'output' -- Stream to which 'text' should be written.
'textFormat' -- Ignored.
'quote=1' -- Boolean option to control whether the text
should be quoted to escape special characters.
"""
text = self._unquoteString(text)
self.writeRaw(text, output)
return
def formatCode(self, text, textFormat):
"Format 'text' as source code and return the new string."
if textFormat in ('HTML', 'StructuredText', 'PlainText'):
formatted_text = '<programlisting>\n%s\n</programlisting>\n' % text
else:
raise ValueError('DocBook formatter cannot handle sourcde code as %s' % textFormat)
return formatted_text
def formatKeyword(self, text):
"Format 'text' as a keyword and return the new string."
formatted_text = '<literal>%s</literal>' % text
return formatted_text
# structure handling
# simple lists
def listHeader(self, output, title=None, allowMultiColumn=1):
"""Output 'title' as a heading for a list. If 'allowMultiColumn' is
true, set up the list to have more than one column.
"""
self.writeRaw('<formalpara>\n<title>%s</title>\n<para><itemizedlist>\n' % title, output)
return
def listItem(self, output, text):
"Format and output the 'text' as a list element."
self.writeRaw('<listitem><para>%s</para></listitem>\n' % text, output)
return
def listFooter(self, output):
"Write the closing footer for a list to the 'output'."
self.writeRaw('\n</itemizedlist></para></formalpara>', output)
return
# descriptive lists
def descriptiveListHeader(self, output, title):
"Write the 'title' as the heading for a descriptive list to the 'output'."
self.writeRaw('<formalpara><title>%s</title>\n<para><variablelist>\n' \
% title, output)
self.comment('descriptive list header', output)
return
def descriptiveListItem(self, output, item, description, descriptionFormat):
"Format and write the 'item' and 'description' for a descriptive list to the 'output'."
self.writeRaw('<varlistitem><term>%s</term><listitem><para>' % item,
output)
self.writeText(description, output, descriptionFormat)
self.writeRaw('</para></listitem></varlistitem>\n', output)
return
def descriptiveListFooter(self, output):
"Write the closing footer for a descriptive list to the 'output'."
self.writeRaw('</variablelist></para></formalpara>\n', output)
return
# headers
def sectionHeader(self, output, title):
"Write a general purpose section openning title to the 'output'."
self.writeRaw('<sect%d>\n<title>%s</title>' \
% (self._section_level_counter, title),
output)
return
def sectionFooter(self, output):
"Write a general purpose section closing footer to the 'output'."
self.writeRaw('</sect%d>' % self._section_level_counter, output)
return
def itemHeader(self, output, infoObject):
"Write a section openning header for an 'infoObject' to the 'output'."
name = infoObject.getName()
self.sectionHeader(output, name)
return
def itemFooter(self, output):
"Write a section closing footer to the 'output'."
self.sectionFooter(output)
return
def pushSectionLevel(self, output):
self._section_level_counter = self._section_level_counter + 1
return
def popSectionLevel(self, output):
self._section_level_counter = self._section_level_counter - 1
return
# misc
def dividingLine(self, output, fill='-'):
"Write a sectional dividing line made up of repeated 'fill' characters to the 'output'."
#output.write('<hr>\n')
return
def comment(self, text, output):
"""Output text as a comment."""
if self.debug: self.writeRaw('<!-- %s -->\n' % text, output)
return
def indent(self, output):
self.comment('indent', output)
return
def dedent(self, output):
self.comment('dedent', output)
return
# refererences
def getReference(self, infoSource, relativeSource, name=None):
"""Returns a reference to the 'infoSource' from 'relativeSource'.
"""
#print '\ngetReference(', infoSource, ',', relativeSource, ')'
#link = computeRelativeLink(relativeSource,
# self.getOutputNameForObject(infoSource)
# )
if not name:
name = self.getNameForInfoSource( infoSource )
info = {
'name':name,
}
ref = '<xref linkend="%(name)s">' % info
return ref
def getNamedReference(self, infoSource, name, relativeSource):
info = {
'name':infoSource.getName(),
}
ref = '<xref linkend="%(name)s">' % info
return ref
def getInternalReference(self, infoSource):
"""Returns a reference to 'infoSource' within the current document.
"""
info = {
'name':infoSource.getName(),
}
ref = '<xref linkend="%(name)s">' % info
return ref
def getPythonReference(self, moduleName):
"""Returns a reference to 'moduleName' documentation on the
"Python.org":http://www.python.org documentation site.
"""
if moduleName in self.sys_modules:
return '<ulink url="http://www.python.org/doc/current/lib/module-%(moduleName)s.html">%(moduleName)s</ulink>' % locals()
else:
return moduleName
def getFilenameExtension(self):
"Returns the extension for creating output files."
return 'sgml'
def getRootNodeName(self):
return 'book.sgml'
|