[Trac] patch to run IncludeMacro with Trac 1.6
Ales Horak <[email protected]> Sat, 13 Sep 2025 04:13:16 -0700 (PDT)
| Newsgroups | gmane.comp.version-control.subversion.trac.general |
|---|---|
| Message-ID | <[email protected]> |
------=_Part_352354_1892473440.1757761996971 Content-Type: multipart/alternative; boundary="----=_Part_352355_91814351.1757761996971" ------=_Part_352355_91814351.1757761996971 Content-Type: text/plain; charset="UTF-8" current https://trac-hacks.org/wiki/IncludeMacro does not run under Trac 1.6 due to genshi imports see the attached patch to make it functional -- ales horak -- You received this message because you are subscribed to the Google Groups "Trac Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to trac-users+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/[email protected] To view this discussion visit https://groups.google.com/d/msgid/trac-users/25183efb-9d0d-4e7c-a6dd-6b68feb09f5bn%40googlegroups.com. ------=_Part_352355_91814351.1757761996971 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable current https://trac-hacks.org/wiki/IncludeMacro does not run under Trac 1.= 6<div>due to genshi imports<br /><br />see the attached patch to make it fu= nctional</div><div><br /></div><div>--=C2=A0</div><div>ales horak</div><div= ><br /></div> <p></p> -- <br /> You received this message because you are subscribed to the Google Groups &= quot;Trac Users" group.<br /> To unsubscribe from this group and stop receiving emails from it, send an e= mail to <a href=3D"mailto:trac-users+unsubscribe-/[email protected]">trac-use= rs+unsubscribe-/[email protected]</a>.<br /> To view this discussion visit <a href=3D"https://groups.google.com/d/msgid/= trac-users/25183efb-9d0d-4e7c-a6dd-6b68feb09f5bn%40googlegroups.com?utm_med= ium=3Demail&utm_source=3Dfooter">https://groups.google.com/d/msgid/trac-use= rs/25183efb-9d0d-4e7c-a6dd-6b68feb09f5bn%40googlegroups.com</a>.<br /> ------=_Part_352355_91814351.1757761996971-- ------=_Part_352354_1892473440.1757761996971 Content-Type: text/x-patch; charset=US-ASCII; name=macros.py.patch Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=macros.py.patch X-Attachment-Id: f63c328d-0c5d-4107-be4c-ad260a990fd5 Content-ID: <f63c328d-0c5d-4107-be4c-ad260a990fd5> --- macros.orig.py 2025-09-13 12:32:03.342878939 +0200 +++ macros.py 2025-09-13 12:32:23.145049545 +0200 @@ -18,8 +18,9 @@ import re -from genshi.filters.html import HTMLSanitizer -from genshi.input import HTMLParser, ParseError +#from genshi.filters.html import HTMLSanitizer +#from genshi.input import HTMLParser, ParseError +from html.parser import HTMLParser from trac.core import TracError, implements from trac.mimeview.api import Mimeview, get_mimetype from trac.perm import IPermissionRequestor @@ -28,7 +29,7 @@ from trac.util import as_bool, as_int from trac.util.html import escape from trac.util.text import to_unicode -from trac.util.translation import _ +from trac.util.translation import _, cleandoc_ from trac.versioncontrol.api import NoSuchChangeset, NoSuchNode, \ RepositoryManager from trac.web.chrome import web_context @@ -45,10 +46,12 @@ class IncludeMacro(WikiMacroBase): + _domain = 'messages' + _description = cleandoc_( """A macro to include other resources in wiki pages. More documentation to follow. - """ + """) implements(IPermissionRequestor) @@ -60,6 +63,8 @@ # IWikiMacroProvider methods def expand_macro(self, formatter, name, content): + self.env.log.debug("hello from IncludeMacro") + largs, kwargs = parse_args(content) if len(largs) == 1: largs.append(None) @@ -206,8 +211,9 @@ if not self.config.getbool('wiki', 'render_unsafe_content', False): out = to_unicode(out) try: - out = HTMLParser(StringIO(out)).parse() | HTMLSanitizer() - except ParseError: + out = HTMLParser(StringIO(out)).parse() | TracHTMLSanitizer() + #except ParseError: no ParseError in HTMLParser now + except: out = escape(out) return out @@ -289,11 +295,11 @@ return out, ctxt, dest_format, annotations def _extract_section(self, text, section): - m1 = re.search("(^\s*(?P<heading>={1,6})\s(.*?)(\#%s)\s*$)" % section, + m1 = re.search(r"(^\s*(?P<heading>={1,6})\s(.*?)(\#%s)\s*$)" % section, text, re.MULTILINE) if m1: stext = text[m1.end(0):] - m2 = re.search("(^\s*%s\s(.*?)(\#%s)?\s*$)" + m2 = re.search(r"(^\s*%s\s(.*?)(\#%s)?\s*$)" % (m1.group('heading'), WikiParser.XML_NAME), stext, re.MULTILINE) if m2: ------=_Part_352354_1892473440.1757761996971--