Back to index

moin  1.9.0~rc2
Public Member Functions | Public Attributes | Static Public Attributes
MoinMoin.parser.text_docbook.Parser Class Reference

List of all members.

Public Member Functions

def __init__
def format
def append_stylesheet
def parse_result

Public Attributes

 db_xsl
 db_compiled_xsl
 wikiParser
 key

Static Public Attributes

int caching = 1
 Dependencies = Dependencies

Detailed Description

    Send XML file formatted via XSLT.

Definition at line 43 of file text_docbook.py.


Constructor & Destructor Documentation

def MoinMoin.parser.text_docbook.Parser.__init__ (   self,
  raw,
  request,
  kw 
)

Definition at line 51 of file text_docbook.py.

00051 
00052     def __init__(self, raw, request, **kw):
00053         XsltParser.__init__(self, raw, request)
00054 
00055         # relative path to docbook.xsl and compiled_xsl
00056         docbook_html_directory = request.cfg.docbook_html_dir
00057         self.db_xsl = os.path.join(docbook_html_directory, 'docbook.xsl')
00058         self.db_compiled_xsl = os.path.join(docbook_html_directory, 'db_compiled.dat')
00059 
00060         self.wikiParser = WikiParser(raw=self.raw, request=self.request, pretty_url=1)
00061         self.key = 'docbook'


Member Function Documentation

"
    virtual function, for docbook parser

Definition at line 66 of file text_docbook.py.

00066 
00067     def append_stylesheet(self):
00068         """"
00069             virtual function, for docbook parser
00070         """
00071         abs_db_xsl = os.path.abspath(self.db_xsl)
00072         abs_db_compiled_xsl = os.path.abspath(self.db_compiled_xsl)
00073 
00074         # same as path.exists, but also test if it is a file
00075         if not os.path.isfile(abs_db_compiled_xsl):
00076             _compile_xsl(abs_db_xsl, abs_db_compiled_xsl)
00077 
00078         assert os.path.isfile(abs_db_compiled_xsl)
00079 
00080         self.processor.appendStylesheetInstance(cPickle.load(file(abs_db_compiled_xsl, 'rb')))

Here is the call graph for this function:

def MoinMoin.parser.text_docbook.Parser.format (   self,
  formatter 
)

Definition at line 62 of file text_docbook.py.

00062 
00063     def format(self, formatter):
00064         self.wikiParser.formatter = formatter
00065         XsltParser.format(self, formatter)

additional parsing to the resulting XSLT'ed result (resultString) before saving

will do:
    BASIC CLEAN UP   : remove unnecessary HTML tags
    RESOLVE IMG SRC  : fix src to find attachment
    RESOLVE WikiNames: if a word is a valid wikiname & a valid wikipage,
               replace word with hyperlink

Definition at line 81 of file text_docbook.py.

00081 
00082     def parse_result(self, result):
00083         """
00084         additional parsing to the resulting XSLT'ed result (resultString) before saving
00085 
00086         will do:
00087             BASIC CLEAN UP   : remove unnecessary HTML tags
00088             RESOLVE IMG SRC  : fix src to find attachment
00089             RESOLVE WikiNames: if a word is a valid wikiname & a valid wikipage,
00090                                replace word with hyperlink
00091         """
00092 
00093         # BASIC CLEAN UP
00094         # remove from beginning until end of body tag
00095         found = re.search('<body.*?>', result)
00096         if found:
00097             result = result[found.end():]
00098 
00099         # remove everything after & including </body>
00100         found = result.rfind('</body>')
00101         if found != -1:
00102             result = result[:found]
00103 
00104         # RESOLVE IMG SRC
00105         found = re.finditer('<img.*?>', result)
00106         if found:
00107             splitResult = _splitResult(found, result)
00108             for index in range(len(splitResult)):
00109                 if splitResult[index].startswith('<img'):
00110                     found = re.search('src="(?P<source>.*?)"', splitResult[index])
00111                     imageSrc = found.group('source')
00112                     imageAlt = None # save alt
00113                     found = re.search('alt="(?P<alt>.*?)"', splitResult[index])
00114                     if found:
00115                         imageAlt = found.group('alt')
00116                     splitResult[index] = self.wikiParser.attachment(('attachment:' + imageSrc, ""))
00117                     if imageAlt: # restore alt
00118                         splitResult[index] = re.sub('alt=".*?"', 'alt="%s"' % imageAlt, splitResult[index])
00119 
00120             result = ''.join(splitResult)
00121 
00122 
00123         # RESOLVE WikiNames
00124         #    if a word is a valid wikiname & a valid wikipage,
00125         #    replace word with hyperlink
00126 
00127         found = re.finditer(self.wikiParser.word_rule, result, re.UNICODE|re.VERBOSE)
00128         if found:
00129             splitResult = _splitResult(found, result)
00130 
00131             for index in range(len(splitResult)):
00132                 if (re.match(self.wikiParser.word_rule, splitResult[index], re.UNICODE|re.VERBOSE)
00133                     and Page.Page(self.request, splitResult[index]).exists()):
00134                     splitResult[index] = self.wikiParser._word_repl(splitResult[index])
00135             result = ''.join(splitResult)
00136 
00137         # remove stuff that fail HTML 4.01 Strict verification
00138 
00139         # remove unsupported attributes
00140         result = re.sub(' target=".*?"| type=".*?"', '', result)
00141         result = re.sub('<hr .*?>', '<hr>', result)
00142 
00143         # remove <p>...</p> inside <a>...</a> or <caption>...</caption>
00144         found = re.finditer('<a href=".*?</a>|<caption>.*?</caption>', result) # XXX re.DOTALL)
00145         if found:
00146             splitResult = _splitResult(found, result)
00147             for index in range(len(splitResult)):
00148                 if (splitResult[index].startswith('<a href="')
00149                     or splitResult[index].startswith('<caption>')):
00150                     splitResult[index] = splitResult[index].replace('<p>', '').replace('</p>', '')
00151             result = ''.join(splitResult)
00152 
00153         return result
00154 
00155 

Here is the call graph for this function:


Member Data Documentation

Definition at line 48 of file text_docbook.py.

Definition at line 57 of file text_docbook.py.

Definition at line 56 of file text_docbook.py.

Definition at line 49 of file text_docbook.py.

Definition at line 60 of file text_docbook.py.

Definition at line 59 of file text_docbook.py.


The documentation for this class was generated from the following file: