comparison MoinMoin/formatter/text_html.py @ 515:1b9f0d6b9f48

fixed double CSS class attribute for nonexistent links, removed ugly formatter.url attrs keyword handling code imported from: moin--main--1.5--patch-519
author Thomas Waldmann <tw@waldmann-edv.de>
date Tue, 28 Mar 2006 21:52:01 +0000
parents ca35d9e6d63e
children ec330d9ec20b
comparison
equal deleted inserted replaced
514:fc74944187ad 515:1b9f0d6b9f48
537 attrs - just include this string verbatim inside 537 attrs - just include this string verbatim inside
538 the <a> element; can be used for arbitrary attrs; 538 the <a> element; can be used for arbitrary attrs;
539 all escaping and quoting is the caller's responsibility. 539 all escaping and quoting is the caller's responsibility.
540 540
541 Note that the 'attrs' keyword argument is for backwards compatibility 541 Note that the 'attrs' keyword argument is for backwards compatibility
542 only. It should not be used for new code--instead just pass 542 only. It should not be used for new code -- instead just pass
543 any attributes in as separate keyword arguments. 543 any attributes in as separate keyword arguments.
544 """ 544
545 if not on: 545 1.5.3: removed ugly "attrs" keyword argument handling code
546 return self._close('a') 546 """
547 attrs = self._langAttr() 547 if on:
548 548 attrs = self._langAttr()
549 # Handle the URL mapping 549
550 if url is None and kw.has_key('href'): 550 # Handle the URL mapping
551 url = kw['href'] 551 if url is None and kw.has_key('href'):
552 del kw['href'] 552 url = kw['href']
553 if url is not None: 553 del kw['href']
554 url = wikiutil.mapURL(self.request, url) 554 if url is not None:
555 url = wikiutil.mapURL(self.request, url)
556 # TODO just calling url_quote does not work, as it will also quote "http:" to "http%xx" X)
557 if 0: # do_escape: # protocol and server part must not get quoted, path should get quoted
558 url = wikiutil.url_quote(url)
559 attrs['href'] = url
560
561 if css:
562 attrs['class'] = css
555 563
556 # TODO just calling url_quote does not work, as it will also quote "http:" to "http%xx" X) 564 markup = self._open('a', attr=attrs, **kw)
557 if 0: # do_escape: # protocol and server part must not get quoted, path should get quoted 565 else:
558 url = wikiutil.url_quote(url) 566 markup = self._close('a')
559 567 return markup
560 attrs['href'] = url
561
562 if css:
563 attrs['class'] = css
564
565 if kw.has_key('attrs'):
566 # for backwards compatibility, raw pre-formated attribute string
567 extra_attrs = kw['attrs']
568 del kw['attrs']
569 else:
570 extra_attrs = None
571
572 # create link
573 if on:
574 str = self._open('a', attr=attrs, **kw)
575 if extra_attrs:
576 # insert this into the tag verbatim (messy)
577 if str[-2:] == '/>':
578 str = '%s %s />' % (str[:-2], extra_attrs)
579 else:
580 str = '%s %s>' % (str[:-1], extra_attrs)
581 else:
582 str = self._close('a')
583 return str
584 568
585 def anchordef(self, id): 569 def anchordef(self, id):
586 """Inserts an invisible element used as a link target. 570 """Inserts an invisible element used as a link target.
587 571
588 Inserts an empty <span> element with an id attribute, used as an anchor 572 Inserts an empty <span> element with an id attribute, used as an anchor
731 else: 715 else:
732 return wikiutil.link_tag(self.request, 716 return wikiutil.link_tag(self.request,
733 edit_link, 717 edit_link,
734 self.image(alt=url, 718 self.image(alt=url,
735 src=AttachFile.getAttachUrl(pagename, filename, self.request, addts=1), css="drawing"), 719 src=AttachFile.getAttachUrl(pagename, filename, self.request, addts=1), css="drawing"),
736 attrs='title="%s"' % (_('Edit drawing %(filename)s') % {'filename': self.text(fname)})) 720 title="%s" % (_('Edit drawing %(filename)s') % {'filename': self.text(fname)}))
737 721
738 722
739 # def attachment_inlined(self, url, text, **kw): 723 # def attachment_inlined(self, url, text, **kw):
740 # moved to MoinMoin/formatter/base.py 724 # moved to MoinMoin/formatter/base.py
741 725