I created a 0.11b1 Macro that renders WikiMarkup to HTML, as shown in
the Trac Wiki. The important part looks like:
text = "'''%s'''[[br]]%s[[br]]%s[[br]]%s, %s %s" % fields # row
from cursor
out = StringIO()
Formatter(self.env, formatter.context).format(text, out)
This works, but when placed in a wiki page like so:
----------------------------------------------
=== Header ===
[[SomeMacro()]]
----------------------------------------------
It renders nested <p>'s as below:
----------------------------------------------
<h3>Header</h3>
<p>
<p>
field0<br />field1<br />field2<br />field3, field4 field5
</p>
</p>
----------------------------------------------
Here's a patch to wiki/formatter.py to disable the inner <p>. It
allows my macro to call
Formatter(self.env, formatter.context).format(text, out,
no_paragraph=1)
Yes, I realize this diff will probably get mangled by Google Groups,
but it's short. Sorry.
--- /c/TracDev/trac/trac/wiki/formatter.py 2008-01-30
13:39:22.517726700 -0500
+++ /c/Python25/lib/site-packages/trac/wiki/formatter.py
2008-02-18 16:26:12.437410700 -0500
@@ -822,7 +822,7 @@
self.in_table_cell = 0
self.paragraph_open = 0
- def format(self, text, out=None, escape_newlines=False):
+ def format(self, text, out=None, escape_newlines=False,
no_paragraph=0):
self.reset(text, out)
for line in text.splitlines():
# Handle code block
@@ -871,7 +871,7 @@
self.close_table()
if len(result) and not self.in_list_item and not
self.in_def_list \
- and not self.in_table:
+ and not self.in_table and not no_paragraph:
self.open_paragraph()
self.out.write(result + os.linesep)
self.close_table_row()
Unrelated: I also found that the following function in
OneLinerFormatter wouldn't let me embed macros in paragraphs of
WikiMarkup (like "blah blah blah [[MacroName]] blah blah"), so I just
commented it out. What did I miss?
@@ -907,15 +907,15 @@
def _table_cell_formatter(self, match, fullmatch): return match
def _last_table_cell_formatter(self, match, fullmatch): return
match
- def _macro_formatter(self, match, fullmatch):
- name = fullmatch.group('macroname')
- if name.lower() == 'br':
- return ' '
- elif name == 'comment':
- return ''
- else:
- args = fullmatch.group('macroargs')
- return '[[%s%s]]' % (name, args and '(...)' or '')
+# def _macro_formatter(self, match, fullmatch):
+# name = fullmatch.group('macroname')
+# if name.lower() == 'br':
+# return ' '
+# elif name == 'comment':
+# return ''
+# else:
+# args = fullmatch.group('macroargs')
+# return '[[%s%s]]' % (name, args and '(...)' or '')
def format(self, text, out, shorten=False):
if not text:
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Trac
Users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/trac-users?hl=en
-~----------~----~----~----~------~----~------~--~---