Modify

Opened 2 months ago

Last modified 2 weeks ago

#14339 new defect

HTML not rendering correctly

Reported by: Ryan J Ollos Owned by:
Priority: normal Component: WikiTableMacro
Severity: normal Keywords:
Cc: mayurlogan@… Trac Release: 1.6

Description

See report on trac-users.

Attachments (0)

Change History (1)

comment:1 Changed 2 weeks ago by Jun Omae

SQLScalar macro always renders a scalar value from the given query as plain text since [14524] because the macro shouldn't render raw html fragment. However, SQLTable macro renders rows from the given query as wiki text, inconsistently.

After the following patch, SQLScalar macro renders a scalar value as wiki text and you can link using such a query SELECT '[https://example.org/ '||COUNT(id)||']' in the macro.

  • wikitable/scalar.py

     
    99#
    1010
    1111from trac.web.chrome import add_stylesheet
    12 from trac.wiki.formatter import system_message
     12from trac.wiki.formatter import format_to_oneliner, system_message
    1313from trac.wiki.macros import WikiMacroBase
    1414from trac.util.html import html as tag
    15 from trac.util.text import exception_to_unicode
     15from trac.util.text import exception_to_unicode, to_unicode
    1616from trac.util.translation import _
    1717
    1818
     19try:
     20    unicode = unicode
     21except NameError:
     22    unicode = str
     23
     24
    1925class SQLScalar(WikiMacroBase):
    2026    """Output a number from a scalar (1x1) SQL query.
    2127
     
    3642            rows = self.env.db_query(content)
    3743        except self.env.db_exc.DatabaseError as e:
    3844            return system_message(_("Invalid SQL"), exception_to_unicode(e))
    39         else:
    40             value = rows[0][0] if len(rows) else "(NULL)"
    4145
     46        def format_(item):
     47            if item is None:
     48                return tag.em('(NULL)')
     49            if item is True:
     50                return 'TRUE'
     51            if item is False:
     52                return 'FALSE'
     53            if not isinstance(item, unicode):
     54                item = to_unicode(item)
     55            return format_to_oneliner(self.env, formatter.context, item)
     56
     57        value = format_(rows[0][0] if rows else None)
    4258        add_stylesheet(formatter.req, 'wikitable/css/wikitable.css')
    4359        return tag.span(value, class_='wikiscalar')
     60
     61    def is_inline(self, content):
     62        return True

Modify Ticket

Change Properties
Set your email in Preferences
Action
as new The ticket will remain with no owner.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.