Back to index

moin  1.9.0~rc2
Public Member Functions | Public Attributes | Static Public Attributes | Private Member Functions | Static Private Attributes
MoinMoin.converter.text_html_text_moin_wiki.convert_tree Class Reference
Inheritance diagram for MoinMoin.converter.text_html_text_moin_wiki.convert_tree:
Inheritance graph
[legend]
Collaboration diagram for MoinMoin.converter.text_html_text_moin_wiki.convert_tree:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def do
def check_whitespace
def visit_text
def visit_element
def visit_node_list_element_only
def node_list_text_only
def get_desc
def process_page
def process_br
def process_heading
def process_dl
def process_list
def empty_paragraph_queue
def process_list_item
def process_blockquote
def process_inline
def process_span
def process_div
def process_tt
def process_hr
def process_p
def process_paragraph_item
def process_pre
def process_preformatted_item
def process_table
def process_caption
def process_table_data
def process_table_record
def process_a
def process_img
def process_object
def visit_node_list
def visit
def visit_attribute
def visit_cdata_section

Public Attributes

 request
 pagename
 depth
 text
 new_table

Static Public Attributes

tuple white_space = object()
tuple new_line = object()
tuple new_line_dont_remove = object()
 process_h1 = process_heading
 process_h2 = process_heading
 process_h3 = process_heading
 process_h4 = process_heading
 process_h5 = process_heading
 process_h6 = process_heading
 process_ul = process_list
 process_ol = process_list

Private Member Functions

def _get_list_item_markup
def _process_indent
def _check_length
def _get_color
def _table_style
def _row_style
def _cell_style
def _process_img
def _process_object

Static Private Attributes

dictionary _alignment

Detailed Description

Definition at line 455 of file text_html_text_moin_wiki.py.


Constructor & Destructor Documentation

def MoinMoin.converter.text_html_text_moin_wiki.convert_tree.__init__ (   self,
  request,
  pagename 
)

Definition at line 460 of file text_html_text_moin_wiki.py.

00460 
00461     def __init__(self, request, pagename):
00462         self.request = request
00463         self.pagename = pagename


Member Function Documentation

Definition at line 1051 of file text_html_text_moin_wiki.py.

01051 
01052     def _cell_style(self, node):
01053         # TODO: attrs = get_attrs(node)
01054         if node.hasAttribute("rowspan"):
01055             rowspan = ("|%s" % node.getAttribute("rowspan"))
01056         else:
01057             rowspan = ""
01058 
01059         if node.hasAttribute("colspan"):
01060             colspan = int(node.getAttribute("colspan"))
01061         else:
01062             colspan = 1
01063 
01064         spanning = rowspan or colspan > 1
01065 
01066         align = ""
01067         result = []
01068         result.append(self._get_color(node, ''))
01069         if node.hasAttribute("align"):
01070             value = node.getAttribute("align")
01071             if not spanning or value != "center":
01072                 # ignore "center" in spanning cells
01073                 align += self._alignment.get(value, "")
01074         if node.hasAttribute("valign"):
01075             value = node.getAttribute("valign")
01076             if not spanning or value != "center":
01077                 # ignore "center" in spanning cells
01078                 align += self._alignment.get(value, "")
01079         if node.hasAttribute("width"):
01080             value = node.getAttribute("width")
01081             if value[-1] == "%":
01082                 align += value
01083             else:
01084                 result.append('width="%s"' % self._check_length(value))
01085         if node.hasAttribute("height"):
01086             value = node.getAttribute("height")
01087             result.append('height="%s"' % self._check_length(value))
01088         if node.hasAttribute("class"):
01089             result.append('class="%s"' % node.getAttribute("class"))
01090         if node.hasAttribute("id"):
01091             result.append('id="%s"' % node.getAttribute("id"))
01092         if node.hasAttribute("style"):
01093             result.append('style="%s"' % node.getAttribute("style"))
01094 
01095         if align:
01096             result.insert(0, "%s" % align)
01097         result.append(rowspan)
01098         return " ".join(result).strip()

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 999 of file text_html_text_moin_wiki.py.

00999 
01000     def _check_length(self, value):
01001         try:
01002             int(value)
01003             return value + 'px'
01004         except ValueError:
01005             return value

Here is the caller graph for this function:

def MoinMoin.converter.text_html_text_moin_wiki.convert_tree._get_color (   self,
  node,
  prefix 
) [private]

Definition at line 1006 of file text_html_text_moin_wiki.py.

01006 
01007     def _get_color(self, node, prefix):
01008         if node.hasAttribute("bgcolor"):
01009             value = node.getAttribute("bgcolor")
01010             match = re.match(r"rgb\((\d+),\s*(\d+),\s*(\d+)\)", value)
01011             if match:
01012                 value = '#%X%X%X' % (int(match.group(1)), int(match.group(2)), int(match.group(3)))
01013             else:
01014                 match = re.match(r"#[0-9A-Fa-f]{6}", value)
01015             if not prefix and match:
01016                 result = value
01017             else:
01018                 result = '%sbgcolor="%s"' % (prefix, value)
01019         else:
01020             result = ''
01021         return result

Here is the caller graph for this function:

def MoinMoin.converter.text_html_text_moin_wiki.convert_tree._get_list_item_markup (   self,
  list,
  listitem 
) [private]

Definition at line 592 of file text_html_text_moin_wiki.py.

00592 
00593     def _get_list_item_markup(self, list, listitem):
00594         before = ""
00595         #indent = str(self.depth) * self.depth # nice for debugging :)
00596         indent = " " * self.depth
00597         markup = ""
00598         name = list.localName
00599         if name == 'ol':
00600             class_ = listitem.getAttribute("class")
00601             if class_ == "gap":
00602                 before = self.new_line_dont_remove
00603             if list.hasAttribute("type"):
00604                 type = list.getAttribute("type")
00605             else:
00606                 type = "1"
00607             markup = "%s. " % type
00608         elif name == 'ul':
00609             class_ = listitem.getAttribute("class")
00610             if class_ == "gap":
00611                 before = self.new_line_dont_remove
00612             style = listitem.getAttribute("style")
00613             if re.match(ur"list-style-type:\s*none", style, re.I):
00614                 markup = ". "
00615                 # set markup with white space when list element containes table
00616                 for i in listitem.childNodes:
00617                     if i.nodeType == Node.ELEMENT_NODE:
00618                         if i.localName == 'table':
00619                             markup = ""
00620             else:
00621                 markup = "* "
00622         elif name == 'dl':
00623             markup = ":: "
00624         else:
00625             raise ConvertError("Illegal list type %s" % name)
00626         return before, indent, markup

Here is the caller graph for this function:

Definition at line 1318 of file text_html_text_moin_wiki.py.

01318 
01319     def _process_img(self, node):
01320         attrs = get_attrs(node)
01321 
01322         title = attrs.pop('title', '')
01323         if title.startswith("smiley:"):
01324             markup = title[len("smiley:"):]
01325             return markup
01326 
01327         alt = attrs.pop('alt', None)
01328         src = attrs.pop('src', None)
01329         css_class = attrs.get('class')
01330 
01331         target = src
01332         if title.startswith("attachment:"):
01333             target = wikiutil.url_unquote(title)
01334             if alt == title[len("attachment:"):]:
01335                 # kill auto-generated alt
01336                 alt = None
01337         elif title.startswith("drawing:"):
01338             target = wikiutil.url_unquote(title)
01339             if alt == title[len("drawing:"):]:
01340                 # kill auto-generated alt
01341                 alt = None
01342         else:
01343             if css_class == 'external_image':
01344                 # kill auto-generated alt and class
01345                 if src == alt:
01346                     alt = None
01347                 del attrs['class']
01348 
01349         if alt:
01350             desc = '|' + alt
01351         else:
01352             desc = ''
01353 
01354         params = ','.join(['%s="%s"' % (k, v) for k, v in attrs.items()])
01355                            # if k in ('width', 'height', )])
01356         if params:
01357             params = '|' + params
01358             if not desc:
01359                 desc = '|'
01360 
01361         markup = "{{%s%s%s}}" % (target, desc, params)
01362         return markup

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 910 of file text_html_text_moin_wiki.py.

00910 
00911     def _process_indent(self, node):
00912         # process indent
00913         node_style = node.getAttribute("style")
00914         match = re.match(r"margin-left:\s*(\d+)px", node_style)
00915         if match:
00916             left_margin = int(match.group(1))
00917             indent_depth = int(left_margin / 40)
00918             if indent_depth > 0:
00919                 self.text.append(' . ')

Here is the caller graph for this function:

Definition at line 1367 of file text_html_text_moin_wiki.py.

01367 
01368     def _process_object(self, node):
01369         attrs = get_attrs(node)
01370         markup = ''
01371         data = attrs.pop('data', None)
01372         if data:
01373             scheme, netloc, path, params, query, fragment = urlparse.urlparse(data)
01374             args = url_decode(query)
01375             action = args.get("action")
01376             attachname = args.get("target")
01377 
01378             if (not scheme and not netloc # same server (local attachment!)
01379                 and path and action == 'AttachFile' and attachname):
01380                 scriptname = self.request.script_root or "/"
01381                 pagename = path[len(scriptname):].lstrip("/")
01382                 pagename = wikiutil.url_unquote(pagename)
01383 
01384                 if pagename != self.request.page.page_name:
01385                     attachname = "%s/%s" % (pagename, attachname)
01386                 data = "attachment:%s" % attachname
01387 
01388             desc = self.get_desc(node.childNodes)
01389             if desc:
01390                 desc = '|' + desc
01391 
01392             # Exlude 'type' attribute cause it generates a 'key already present' error.
01393             params = ','.join(['%s="%s"' % (k, v) for k, v in attrs.items() if not k in ('type', )])
01394             if params:
01395                 params = '|' + params
01396                 if not desc:
01397                     desc = '|'
01398             markup = "{{%s%s%s}}" % (data, desc, params)
01399         return markup
01400         # TODO: for target PAGES, use some code from process_a to get the pagename from URL
01401         # TODO: roundtrip attachment: correctly
01402         # TODO: handle object's content better?

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 1041 of file text_html_text_moin_wiki.py.

01041 
01042     def _row_style(self, node):
01043         # TODO: attrs = get_attrs(node)
01044         result = []
01045         result.append(self._get_color(node, 'row'))
01046         if node.hasAttribute("style"):
01047             result.append('rowstyle="%s"' % node.getAttribute("style"))
01048         if node.hasAttribute("class"):
01049             result.append('rowclass="%s"' % node.getAttribute("class"))
01050         return " ".join(result).strip()

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 1022 of file text_html_text_moin_wiki.py.

01022 
01023     def _table_style(self, node):
01024         # TODO: attrs = get_attrs(node)
01025         result = []
01026         result.append(self._get_color(node, 'table'))
01027         if node.hasAttribute("width"):
01028             value = node.getAttribute("width")
01029             result.append('tablewidth="%s"' % self._check_length(value))
01030         if node.hasAttribute("height"):
01031             value = node.getAttribute("height")
01032             result.append('tableheight="%s"' % self._check_length(value))
01033         if node.hasAttribute("align"):
01034             value = node.getAttribute("align")
01035             result.append('tablealign="%s"' % value)
01036         if node.hasAttribute("style"):
01037             result.append('tablestyle="%s"' % node.getAttribute("style"))
01038         if node.hasAttribute("class"):
01039             result.append('tableclass="%s"' % node.getAttribute("class"))
01040         return " ".join(result).strip()

Here is the call graph for this function:

Definition at line 471 of file text_html_text_moin_wiki.py.

00471 
00472     def check_whitespace(self):
00473         i = 0
00474         text = self.text
00475         while i < len(text):
00476             if text[i] is self.white_space:
00477                 if i == 0 or i == len(text)-1:
00478                     del text[i]
00479                 elif text[i-1].endswith(" ") or text[i-1].endswith("\n"):
00480                     # last char of previous element is whitespace
00481                     del text[i]
00482                 elif (text[i+1] is self.white_space or
00483                       # next element is white_space
00484                       text[i+1] is self.new_line):
00485                       # or new_line
00486                     del text[i]
00487                 elif text[i+1].startswith(" ") or text[i+1].startswith("\n"):
00488                     # first char of next element is whitespace
00489                     del text[i]
00490                 else:
00491                     text[i] = " "
00492                     i += 1
00493             elif text[i] is self.new_line:
00494                 if i == 0:
00495                     del text[i]
00496                 elif i == len(text) - 1:
00497                     text[i] = "\n"
00498                     i += 1
00499                 elif text[i-1].endswith("\n") or (
00500                       isinstance(text[i+1], str) and text[i+1].startswith("\n")):
00501                     del text[i]
00502                 else:
00503                     text[i] = "\n"
00504                     i += 1
00505             elif text[i] is self.new_line_dont_remove:
00506                 text[i] = "\n"
00507                 i += 1
00508             else:
00509                 i += 1

Reimplemented from MoinMoin.converter.text_html_text_moin_wiki.visitor.

Definition at line 464 of file text_html_text_moin_wiki.py.

00464 
00465     def do(self, tree):
00466         self.depth = 0
00467         self.text = []
00468         self.visit(tree.documentElement)
00469         self.check_whitespace()
00470         return ''.join(self.text)

Here is the caller graph for this function:

def MoinMoin.converter.text_html_text_moin_wiki.convert_tree.empty_paragraph_queue (   self,
  nodelist,
  indent,
  need_indent 
)

Definition at line 669 of file text_html_text_moin_wiki.py.

00669 
00670     def empty_paragraph_queue(self, nodelist, indent, need_indent):
00671         if need_indent:
00672             self.text.append(indent)
00673         for i in nodelist:
00674             if i.nodeType == Node.ELEMENT_NODE:
00675                 if i.localName == 'br':
00676                     self.text.append('<<BR>>')
00677                 else:
00678                     self.process_inline(i)
00679             elif i.nodeType == Node.TEXT_NODE:
00680                 self.text.append(i.data.strip('\n').replace('\n', ' '))
00681         self.text.append(self.new_line)
00682         del nodelist[:]

Here is the call graph for this function:

Here is the caller graph for this function:

links can have either text or an image as description - we extract
    this from the child nodelist and return wiki markup.

Definition at line 537 of file text_html_text_moin_wiki.py.

00537 
00538     def get_desc(self, nodelist):
00539         """ links can have either text or an image as description - we extract
00540             this from the child nodelist and return wiki markup.
00541         """
00542         markup = ''
00543         text = self.node_list_text_only(nodelist).replace("\n", " ").strip()
00544         if text:
00545             # found some text
00546             markup = text
00547         else:
00548             # search for an img / object
00549             for node in nodelist:
00550                 if node.nodeType == Node.ELEMENT_NODE:
00551                     name = node.localName
00552                     if name == 'img':
00553                         markup = self._process_img(node) # XXX problem: markup containts auto-generated alt text with link target
00554                         break
00555                     elif name == 'object':
00556                         markup = self._process_object(node)
00557                         break
00558         return markup

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 528 of file text_html_text_moin_wiki.py.

00528 
00529     def node_list_text_only(self, nodelist):
00530         result = []
00531         for node in nodelist:
00532             if node.nodeType == Node.TEXT_NODE:
00533                 result.append(node.data)
00534             else:
00535                 result.extend(self.node_list_text_only(node.childNodes))
00536         return "".join(result)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 1209 of file text_html_text_moin_wiki.py.

01209 
01210     def process_a(self, node):
01211         attrs = get_attrs(node)
01212 
01213         title = attrs.pop('title', '')
01214         href = attrs.pop('href', None)
01215         css_class = attrs.get('class')
01216 
01217         scriptname = self.request.script_root
01218         if scriptname == "":
01219             scriptname = "/"
01220 
01221         # can either be a link (with href) or an anchor (with e.g. id)
01222         # we don't need to support anchors here as we currently handle them as <<Anchor(id)>> macro
01223         if href:
01224             href = wikiutil.url_unquote(href)
01225 
01226             interwikiname = None
01227             desc = self.get_desc(node.childNodes)
01228 
01229             # interwiki link
01230             if css_class == "interwiki":
01231                 wikitag, wikiurl, wikitail, err = wikiutil.resolve_interwiki(
01232                     self.request, title, "") # the title has the wiki name, page = ""
01233                 if not err and href.startswith(wikiurl):
01234                     pagename = wikiutil.url_unquote(href[len(wikiurl):].lstrip('/'))
01235                     interwikiname = "%s:%s" % (wikitag, pagename)
01236                 else:
01237                     raise ConvertError("Invalid InterWiki link: '%s'" % href)
01238             elif css_class == "badinterwiki" and title:
01239                 if href == "/": # we used this as replacement for empty href
01240                     href = ""
01241                 pagename = wikiutil.url_unquote(href)
01242                 interwikiname = "%s:%s" % (title, pagename)
01243             if interwikiname and pagename == desc:
01244                 if interwiki_re.match(interwikiname+' '): # the blank is needed by interwiki_re to match
01245                     # this is valid as a free interwiki link
01246                     self.text.append("%s" % interwikiname)
01247                 else:
01248                     self.text.append("[[%s]]" % interwikiname)
01249                 return
01250             elif title == 'Self':
01251                 self.text.append('[[%s|%s]]' % (href, desc))
01252                 return
01253             elif interwikiname:
01254                 self.text.append("[[%s|%s]]" % (interwikiname, desc))
01255                 return
01256 
01257             # fix links generated by a broken copy & paste of gecko based browsers
01258             brokenness = '../../../..'
01259             if href.startswith(brokenness):
01260                 href = href[len(brokenness):] # just strip it away!
01261             # TODO: IE pastes complete http://server/Page/SubPage as href and as text, too
01262 
01263             # Attachments
01264             if title.startswith("attachment:"):
01265                 attname = wikiutil.url_unquote(title[len("attachment:"):])
01266                 if 'do=get' in href: # quick&dirty fix for not dropping &do=get param
01267                     parms = '|&do=get'
01268                 else:
01269                     parms = ''
01270                 if attname != desc:
01271                     desc = '|%s' % desc
01272                 elif parms:
01273                     desc = '|'
01274                 else:
01275                     desc = ''
01276                 self.text.append('[[attachment:%s%s%s]]' % (attname, desc, parms))
01277             # wiki link
01278             elif href.startswith(scriptname):
01279                 pagename = href[len(scriptname):]
01280                 pagename = pagename.lstrip('/')    # XXX temp fix for generated pagenames starting with /
01281                 if desc == pagename:
01282                     self.text.append(wikiutil.pagelinkmarkup(pagename))
01283                 # relative link /SubPage
01284                 elif desc.startswith('/') and href.endswith(desc):
01285                     if pagename.startswith(self.pagename): # is this a subpage of us?
01286                         self.text.append(wikiutil.pagelinkmarkup(pagename[len(self.pagename):]))
01287                     else:
01288                         self.text.append(wikiutil.pagelinkmarkup(pagename))
01289                 # relative link ../
01290                 elif desc.startswith('../') and href.endswith(desc[3:]):
01291                     self.text.append(wikiutil.pagelinkmarkup(desc))
01292                 # internal link #internal
01293                 elif '#' in href and pagename.startswith(self.pagename):
01294                     self.text.append(wikiutil.pagelinkmarkup(href[href.index('#'):], desc))
01295                 # labeled link
01296                 else:
01297                     self.text.append(wikiutil.pagelinkmarkup(pagename, desc))
01298             # mailto link
01299             elif href.startswith("mailto:"):
01300                 if href == desc or href[len("mailto:"):] == desc:
01301                     self.text.extend([self.white_space, desc, self.white_space])
01302                 else:
01303                     self.text.append("[[%s|%s]]" % (href, desc)) # XXX use a (renamed) pagelinkmarkup
01304             # link
01305             else:
01306                 if href == desc:
01307                     href = href.replace(" ", "%20")
01308                     self.text.append(href)
01309                 else:
01310                     href = href.replace(" ", "%20")
01311                     if desc:
01312                         desc = '|' + desc
01313                     self.text.append("[[%s%s]]" % (href, desc))

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 733 of file text_html_text_moin_wiki.py.

00733 
00734     def process_blockquote(self, node):
00735         # XXX this does not really work. e.g.:
00736         # <bq>aaaaaa
00737         # <hr---------->
00738         # <bq>bbbbbb
00739         self.depth += 1
00740         for i in node.childNodes:
00741             if i.nodeType == Node.ELEMENT_NODE:
00742                 name = i.localName
00743                 if name == 'p':
00744                     self.text.append(self.new_line)
00745                     self.text.append(" " * self.depth)
00746                     self.process_p(i)
00747                 elif name == 'pre':
00748                     self.text.append(self.new_line)
00749                     self.text.append(" " * self.depth)
00750                     self.process_pre(i)
00751                 elif name in ('h1', 'h2', 'h3', 'h4', 'h5', 'h6', ):
00752                     self.process_heading(i)
00753                 elif name in ('ol', 'ul', ):
00754                     self.process_list(i)
00755                 elif name == 'dl':
00756                     self.process_dl(i)
00757                 elif name == 'a':
00758                     self.process_a(i)
00759                 elif name == 'img':
00760                     self.process_img(i)
00761                 elif name == 'div':
00762                     self.visit_node_list_element_only(i.childNodes)
00763                 elif name == 'blockquote':
00764                     self.process_blockquote(i)
00765                 elif name == 'hr':
00766                     self.process_hr(i)
00767                 elif name == 'br':
00768                     self.process_br(i)
00769                 else:
00770                     raise ConvertError("process_blockquote: Don't support %s element" % name)
00771         self.depth -= 1

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 572 of file text_html_text_moin_wiki.py.

00572 
00573     def process_br(self, node):
00574         self.text.append(self.new_line) # without this, std multi-line text below some heading misses a whitespace
00575                                         # when it gets merged to float text, like word word wordword word word

Here is the caller graph for this function:

def MoinMoin.converter.text_html_text_moin_wiki.convert_tree.process_caption (   self,
  table,
  node,
  style = "" 
)

Definition at line 1123 of file text_html_text_moin_wiki.py.

01123 
01124     def process_caption(self, table, node, style=""):
01125         # get first row
01126         for i in table.childNodes:
01127             if i.localName in ('thead', 'tbody', 'tfoot'): # XXX is this correct?
01128             #if i.localName == 'tbody': (old version)
01129                 for i in i.childNodes:
01130                     if i.localName == 'tr':
01131                         break
01132                 break
01133             elif i.localName == 'tr':
01134                 break
01135         # count columns
01136         if i.localName == 'tr':
01137             colspan = 0
01138             for td in i.childNodes:
01139                 if not td.nodeType == Node.ELEMENT_NODE:
01140                     continue
01141                 span = td.getAttribute('colspan')
01142                 try:
01143                     colspan += int(span)
01144                 except ValueError:
01145                     colspan += 1
01146         else:
01147             colspan = 1
01148         text = self.node_list_text_only(node.childNodes).replace('\n', ' ').strip()
01149         if text:
01150             if style:
01151                 style = '<%s>' % style
01152             self.text.extend(["%s%s'''%s'''||" % ('||' * colspan, style, text), self.new_line_dont_remove])

Here is the call graph for this function:

Definition at line 878 of file text_html_text_moin_wiki.py.

00878 
00879     def process_div(self, node):
00880         # process indent
00881         self._process_indent(node)
00882 
00883         # ignore div tags - just descend
00884         for i in node.childNodes:
00885             self.visit(i)

Here is the call graph for this function:

Definition at line 627 of file text_html_text_moin_wiki.py.

00627 
00628     def process_dl(self, node):
00629         self.depth += 1
00630         markup = ":: " # can there be a dl dd without dt?
00631         for i in node.childNodes:
00632             if i.nodeType == Node.ELEMENT_NODE:
00633                 name = i.localName
00634                 if name == 'dt':
00635                     before, indent, markup = self._get_list_item_markup(node, i)
00636                     self.text.extend([before, indent])
00637                     text = self.node_list_text_only(i.childNodes)
00638                     self.text.append(text.replace("\n", " "))
00639                 elif name == 'dd':
00640                     self.text.append(markup)
00641                     self.process_list_item(i, indent) # XXX no dt -> indent is undefined!!!
00642                 else:
00643                     raise ConvertError("Illegal list element %s" % i.localName)
00644         self.depth -= 1
00645         if self.depth == 0:
00646             self.text.append(self.new_line_dont_remove)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 576 of file text_html_text_moin_wiki.py.

00576 
00577     def process_heading(self, node):
00578         text = self.node_list_text_only(node.childNodes).strip()
00579         if text:
00580             depth = int(node.localName[1])
00581             hstr = "=" * depth
00582             self.text.append(self.new_line)
00583             self.text.append("%s %s %s" % (hstr, text.replace("\n", " "), hstr))
00584             self.text.append(self.new_line)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 893 of file text_html_text_moin_wiki.py.

00893 
00894     def process_hr(self, node):
00895         if node.hasAttribute("class"):
00896             class_ = node.getAttribute("class")
00897         else:
00898             class_ = "hr0"
00899         if class_.startswith("hr") and class_[2] in "123456":
00900             length = int(class_[2]) + 4
00901         else:
00902             length = 4
00903         self.text.extend([self.new_line, "-" * length, self.new_line])

Here is the caller graph for this function:

Definition at line 1314 of file text_html_text_moin_wiki.py.

01314 
01315     def process_img(self, node):
01316         markup = self._process_img(node)
01317         self.text.extend([self.white_space, markup, self.white_space])

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 772 of file text_html_text_moin_wiki.py.

00772 
00773     def process_inline(self, node):
00774         if node.nodeType == Node.TEXT_NODE:
00775             self.text.append(node.data.strip('\n').replace('\n', ' '))
00776             return
00777 
00778         # do we need to check for Node.ELEMENT_NODE and return (do nothing)?
00779         name = node.localName # can be None for DOM Comment nodes
00780         if name is None:
00781             return
00782 
00783         # unsupported tags
00784         if name in (u'title', u'meta', u'style'):
00785             return
00786 
00787         if name in ('h1', 'h2', 'h3', 'h4', 'h5', 'h6', ): # headers are not allowed here (e.g. inside a ul li),
00788             text = self.node_list_text_only(node.childNodes).strip() # but can be inserted via the editor
00789             self.text.append(text)                          # so we just drop the header markup and keep the text
00790             return
00791 
00792         func = getattr(self, "process_%s" % name, None)
00793         if func:
00794             func(node)
00795             return
00796 
00797         command_close = None
00798         if name in ('em', 'i', ):
00799             command = "''"
00800         elif name in ('strong', 'b', ):
00801             command = "'''"
00802         elif name == 'u':
00803             command = "__"
00804         elif name == 'big':
00805             command = "~+"
00806             command_close = "+~"
00807         elif name == 'small':
00808             command = "~-"
00809             command_close = "-~"
00810         elif name == 'strike':
00811             command = "--("
00812             command_close = ")--"
00813         elif name == 'sub':
00814             command = ",,"
00815         elif name == 'sup':
00816             command = "^"
00817         elif name in ('area', 'center', 'code', 'embed', 'fieldset', 'font', 'form', 'iframe', 'input', 'label', 'link', 'map',
00818                       'meta', 'noscript', 'option', 'script', 'select', 'textarea', 'wbr'):
00819             command = "" # just throw away unsupported elements
00820         else:
00821             raise ConvertError("process_inline: Don't support %s element" % name)
00822 
00823         self.text.append(command)
00824         for i in node.childNodes:
00825             # lonly childnodes checked if they are only 'br'
00826             if command and len(node.childNodes) == 1:
00827                 # formatted br alone is not wanted (who wants a bold br?)
00828                 if i.localName != 'br':
00829                     self.process_inline(i)
00830             else:
00831                 if i.localName == 'br':
00832                     # dont make a real \n because that breaks tables
00833                     self.text.append('<<BR>>')
00834                 else:
00835                     self.process_inline(i)
00836         if command_close:
00837             command = command_close
00838         self.text.append(command)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 647 of file text_html_text_moin_wiki.py.

00647 
00648     def process_list(self, node):
00649         self.depth += 1
00650         for i in node.childNodes:
00651             if i.nodeType == Node.ELEMENT_NODE:
00652                 name = i.localName
00653                 if name == 'li':
00654                     before, indent, markup = self._get_list_item_markup(node, i)
00655                     self.text.extend([before, indent, markup])
00656                     self.process_list_item(i, indent)
00657                 elif name in ('ol', 'ul', ):
00658                     self.process_list(i)
00659                 elif name == 'dl':
00660                     self.process_dl(i)
00661                 else:
00662                     raise ConvertError("Illegal list element %s" % i.localName)
00663         self.depth -= 1
00664         if self.depth == 0:
00665             self.text.append(self.new_line_dont_remove)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 683 of file text_html_text_moin_wiki.py.

00683 
00684     def process_list_item(self, node, indent):
00685         found = False
00686         need_indent = False
00687         pending = []
00688 
00689         # If this is a empty list item, we just terminate the line
00690         if node.childNodes.length == 0:
00691             self.text.append(self.new_line)
00692             return
00693 
00694         for i in node.childNodes:
00695             name = i.localName
00696 
00697             if name in ('p', 'pre', 'ol', 'ul', 'dl', 'table', ) and pending:
00698                 self.empty_paragraph_queue(pending, indent, need_indent)
00699                 need_indent = True
00700 
00701             if name == 'p':
00702                 if need_indent:
00703                     self.text.append(indent)
00704                 self.process_paragraph_item(i)
00705                 self.text.append(self.new_line)
00706                 found = True
00707             elif name == 'pre':
00708                 if need_indent:
00709                     self.text.append(indent)
00710                 self.process_preformatted_item(i)
00711                 found = True
00712             elif name in ('ol', 'ul', ):
00713                 self.process_list(i)
00714                 found = True
00715             elif name == 'dl':
00716                 self.process_dl(i)
00717                 found = True
00718             elif name == 'table':
00719                 if need_indent:
00720                     self.text.append(indent)
00721                 self.process_table(i)
00722                 found = True
00723             elif name == 'br':
00724                 pending.append(i)
00725             else:
00726                 pending.append(i)
00727 
00728             if found:
00729                 need_indent = True
00730 
00731         if pending:
00732             self.empty_paragraph_queue(pending, indent, need_indent)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 1363 of file text_html_text_moin_wiki.py.

01363 
01364     def process_object(self, node):
01365         markup = self._process_object(node)
01366         self.text.append(markup)

Here is the call graph for this function:

Definition at line 904 of file text_html_text_moin_wiki.py.

00904 
00905     def process_p(self, node):
00906         # process indent
00907         self._process_indent(node)
00908         self.process_paragraph_item(node)
00909         self.text.append("\n\n") # do not use self.new_line here!

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 559 of file text_html_text_moin_wiki.py.

00559 
00560     def process_page(self, node):
00561         for i in node.childNodes:
00562             if i.nodeType == Node.ELEMENT_NODE:
00563                 self.visit_element(i)
00564             elif i.nodeType == Node.TEXT_NODE: # if this is missing, all std text under a headline is dropped!
00565                 txt = i.data.strip() # IMPORTANT: don't leave this unstripped or there will be wrong blanks
00566                 if txt:
00567                     self.text.append(txt)
00568             #we use <pre class="comment"> now, so this is currently unused:
00569             #elif i.nodeType == Node.COMMENT_NODE:
00570             #    self.text.append(i.data)
00571             #    self.text.append("\n")

Here is the call graph for this function:

Definition at line 920 of file text_html_text_moin_wiki.py.

00920 
00921     def process_paragraph_item(self, node):
00922         for i in node.childNodes:
00923             if i.nodeType == Node.ELEMENT_NODE:
00924                 self.process_inline(i)
00925             elif i.nodeType == Node.TEXT_NODE:
00926                 self.text.append(i.data.strip('\n').replace('\n', ' '))

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 927 of file text_html_text_moin_wiki.py.

00927 
00928     def process_pre(self, node):
00929         self.process_preformatted_item(node)
00930         self.text.append(self.new_line)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 931 of file text_html_text_moin_wiki.py.

00931 
00932     def process_preformatted_item(self, node):
00933         if node.hasAttribute("class"):
00934             class_ = node.getAttribute("class")
00935         else:
00936             class_ = None
00937         if class_ == "comment": # we currently use this for stuff like ## or #acl
00938             for i in node.childNodes:
00939                 if i.nodeType == Node.TEXT_NODE:
00940                     self.text.append(i.data.replace('\n', ''))
00941                 elif i.localName == 'br':
00942                     self.text.append(self.new_line)
00943                 else:
00944                     pass
00945         else:
00946             content_buffer = []
00947             longest_inner_formater = ''
00948             bang_args = ''
00949             delimiters = []
00950 
00951             """
00952             below code fixed for MoinMoinBugs/GuiEditorCantNest bug
00953             this has problem when outer delimiter has two more { than inside one
00954             e.g. {{{{{{ {{{ foo }}} }}}}}}  --> {{{{ {{{ foo }}} }}}}
00955                    {{{foo {{{ }}} foo}}} --> {{{{ {{{ }}} }}}}
00956             """
00957 
00958             for i in node.childNodes:
00959                 if i.nodeType == Node.TEXT_NODE:
00960                     # get longest pre tag({{{ or }}}) from content
00961                     delimiters.extend(re.compile("((?u){+)").findall(i.data))
00962                     delimiters.extend(re.compile("((?u)}+)").findall(i.data))
00963                     # when first line is empty, start iteration second line of i.data
00964                     data_lines = i.data.rstrip().split('\n')
00965                     if data_lines[0].strip() == '':
00966                         data_lines = data_lines[1:]
00967                     for line in data_lines:
00968                         if line.strip().startswith('#!'):
00969                             if bang_args == '':
00970                                 bang_args = line.strip()
00971                             else:
00972                                 content_buffer.extend([line, self.new_line])
00973                         else:
00974                             content_buffer.extend([line, self.new_line])
00975                 elif i.localName == 'br':
00976                     content_buffer.append(self.new_line_dont_remove)
00977                 else:
00978                     pass
00979 
00980             if delimiters:
00981                 longest_inner_formater = max(delimiters)
00982 
00983             if (len(longest_inner_formater) >= 3):
00984                 self.text.extend([("{" * (len(longest_inner_formater) + 1)) + bang_args, \
00985                                       self.new_line])
00986                 self.text.extend(content_buffer)
00987                 self.text.extend(["}" * (len(longest_inner_formater) + 1), \
00988                                       self.new_line])
00989             else:
00990                 self.text.extend(["{{{"+bang_args, self.new_line])
00991                 self.text.extend(content_buffer)
00992                 self.text.extend(["}}}", self.new_line])

Here is the caller graph for this function:

Definition at line 839 of file text_html_text_moin_wiki.py.

00839 
00840     def process_span(self, node):
00841         # process span tag for firefox3
00842         node_style = node.getAttribute("style")
00843 
00844         is_strike = node.getAttribute("class") == "strike"
00845         is_strike = is_strike or "line-through" in node_style
00846         is_strong = "bold" in node_style
00847         is_italic = "italic" in node_style
00848         is_underline = "underline" in node_style
00849         is_comment = node.getAttribute("class") == "comment"
00850 
00851         # start tag
00852         if is_comment:
00853             self.text.append("/* ")
00854         if is_strike:
00855             self.text.append("--(")
00856         if is_strong:
00857             self.text.append("'''")
00858         if is_italic:
00859             self.text.append("''")
00860         if is_underline:
00861             self.text.append("__")
00862 
00863         # body
00864         for i in node.childNodes:
00865             self.process_inline(i)
00866 
00867         # end tag
00868         if is_underline:
00869             self.text.append("__")
00870         if is_italic:
00871             self.text.append("''")
00872         if is_strong:
00873             self.text.append("'''")
00874         if is_strike:
00875             self.text.append(")--")
00876         if is_comment:
00877             self.text.append(" */")

Here is the call graph for this function:

Definition at line 1099 of file text_html_text_moin_wiki.py.

01099 
01100     def process_table(self, node, style=""):
01101         if self.depth == 0:
01102             self.text.append(self.new_line)
01103         self.new_table = True
01104         style += self._table_style(node)
01105         for i in node.childNodes:
01106             if i.nodeType == Node.ELEMENT_NODE:
01107                 name = i.localName
01108                 if name == 'tr':
01109                     self.process_table_record(i, style)
01110                     style = ""
01111                 elif name in ('thead', 'tbody', 'tfoot'):
01112                     self.process_table(i, style)
01113                 elif name == 'caption':
01114                     self.process_caption(node, i, style)
01115                     style = ''
01116                 elif name in ('col', 'colgroup', 'strong', ):
01117                     pass # we don't support these, but we just ignore them
01118                 else:
01119                     raise ConvertError("process_table: Don't support %s element" % name)
01120             #else:
01121             #    raise ConvertError("Unexpected node: %r" % i)
01122         self.text.append(self.new_line_dont_remove)

Here is the caller graph for this function:

Definition at line 1153 of file text_html_text_moin_wiki.py.

01153 
01154     def process_table_data(self, node, style=""):
01155         if node.hasAttribute("colspan"):
01156             colspan = int(node.getAttribute("colspan"))
01157         else:
01158             colspan = 1
01159         self.text.append("||" * colspan)
01160 
01161         style += self._cell_style(node)
01162         if style:
01163             self.text.append("<%s>" % style)
01164 
01165         found = False
01166         for i in node.childNodes:
01167             name = i.localName
01168             if name == 'p':
01169                 self.process_paragraph_item(i)
01170                 self.text.append(self.white_space)
01171                 found = True
01172         if not found:
01173             for i in node.childNodes:
01174                 name = i.localName
01175                 if i.nodeType == Node.ELEMENT_NODE:
01176                     if name == 'br':
01177                         # if we get a br for a cell from e.g. cut and paste from OOo
01178                         # or if someone simulates a list by enter in a cell
01179                         # it should be appended as macro BR.
01180                         self.text.append('<<BR>>')
01181                         found = True
01182                         continue
01183                     else:
01184                         self.process_inline(i)
01185                         found = True
01186                 elif i.nodeType == Node.TEXT_NODE:
01187                     data = i.data.strip('\n').replace('\n', ' ')
01188                     if data:
01189                         found = True
01190                         self.text.append(data)
01191         if not found:
01192             self.text.append(" ")

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 1193 of file text_html_text_moin_wiki.py.

01193 
01194     def process_table_record(self, node, style=""):
01195         if not self.new_table:
01196             self.text.append(" " * self.depth)
01197         else:
01198             self.new_table = False
01199         style += self._row_style(node)
01200         for i in node.childNodes:
01201             if i.nodeType == Node.ELEMENT_NODE:
01202                 name = i.localName
01203                 if name in ('td', 'th', ):
01204                     self.process_table_data(i, style=style)
01205                     style = ""
01206                 else:
01207                     raise ConvertError("process_table_record: Don't support %s element" % name)
01208         self.text.extend(["||", self.new_line_dont_remove])

Here is the call graph for this function:

Definition at line 886 of file text_html_text_moin_wiki.py.

00886 
00887     def process_tt(self, node):
00888         text = self.node_list_text_only(node.childNodes).replace("\n", " ")
00889         if node.getAttribute("class") == "backtick":
00890             self.text.append("`%s`" % text)
00891         else:
00892             self.text.append("{{{%s}}}" % text)

Here is the call graph for this function:

def MoinMoin.converter.text_html_text_moin_wiki.visitor.visit (   self,
  node 
) [inherited]

Definition at line 410 of file text_html_text_moin_wiki.py.

00410 
00411     def visit(self, node):
00412         nodeType = node.nodeType
00413         if node.nodeType == Node.ELEMENT_NODE:
00414             return self.visit_element(node)
00415         elif node.nodeType == Node.ATTRIBUTE_NODE:
00416             return self.visit_attribute(node)
00417         elif node.nodeType == Node.TEXT_NODE:
00418             return self.visit_text(node)
00419         elif node.nodeType == Node.CDATA_SECTION_NODE:
00420             return self.visit_cdata_section(node)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 425 of file text_html_text_moin_wiki.py.

00425 
00426     def visit_attribute(self, node):
00427         pass

Here is the caller graph for this function:

Definition at line 431 of file text_html_text_moin_wiki.py.

00431 
00432     def visit_cdata_section(self, node):
00433         pass
00434 

Here is the caller graph for this function:

Reimplemented from MoinMoin.converter.text_html_text_moin_wiki.visitor.

Definition at line 513 of file text_html_text_moin_wiki.py.

00513 
00514     def visit_element(self, node):
00515         name = node.localName
00516         if name is None: # not sure this can happen here (DOM comment node), but just for the case
00517             return
00518         func = getattr(self, "process_%s" % name, None)
00519         if func:
00520             func(node)
00521         else:
00522             self.process_inline(node)

Here is the call graph for this function:

def MoinMoin.converter.text_html_text_moin_wiki.visitor.visit_node_list (   self,
  nodelist 
) [inherited]

Definition at line 406 of file text_html_text_moin_wiki.py.

00406 
00407     def visit_node_list(self, nodelist):
00408         for node in nodelist:
00409             self.visit(node)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 523 of file text_html_text_moin_wiki.py.

00523 
00524     def visit_node_list_element_only(self, nodelist):
00525         for node in nodelist:
00526             if node.nodeType == Node.ELEMENT_NODE:
00527                 self.visit_element(node)

Here is the call graph for this function:

Here is the caller graph for this function:

Reimplemented from MoinMoin.converter.text_html_text_moin_wiki.visitor.

Definition at line 510 of file text_html_text_moin_wiki.py.

00510 
00511     def visit_text(self, node):
00512         self.text.append(node.data)


Member Data Documentation

Initial value:
{"left": "(",
                  "center": ":",
                  "right": ")",
                  "top": "^",
                  "bottom": "v"}

Definition at line 993 of file text_html_text_moin_wiki.py.

Definition at line 465 of file text_html_text_moin_wiki.py.

Definition at line 457 of file text_html_text_moin_wiki.py.

Definition at line 458 of file text_html_text_moin_wiki.py.

Definition at line 1102 of file text_html_text_moin_wiki.py.

Definition at line 462 of file text_html_text_moin_wiki.py.

Definition at line 585 of file text_html_text_moin_wiki.py.

Definition at line 586 of file text_html_text_moin_wiki.py.

Definition at line 587 of file text_html_text_moin_wiki.py.

Definition at line 588 of file text_html_text_moin_wiki.py.

Definition at line 589 of file text_html_text_moin_wiki.py.

Definition at line 590 of file text_html_text_moin_wiki.py.

Definition at line 667 of file text_html_text_moin_wiki.py.

Definition at line 666 of file text_html_text_moin_wiki.py.

Definition at line 461 of file text_html_text_moin_wiki.py.

Definition at line 466 of file text_html_text_moin_wiki.py.

Definition at line 456 of file text_html_text_moin_wiki.py.


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