|
5 | 5 | from trac.web.chrome import INavigationContributor
|
6 | 6 | from trac.web.api import IRequestFilter, IRequestHandler, RequestDone
|
7 | 7 | from trac.web.auth import LoginModule
|
| 8 | +from trac.wiki.macros import WikiMacroBase |
8 | 9 | from trac.wiki.web_ui import WikiModule
|
9 |
| -from trac.util.html import tag |
| 10 | +from trac.util.html import Markup, tag |
10 | 11 | from tracext.github import GitHubLoginModule, GitHubBrowser
|
11 | 12 |
|
12 | 13 | from django.conf import settings
|
|
15 | 16 | from django.utils.http import url_has_allowed_host_and_scheme
|
16 | 17 |
|
17 | 18 |
|
| 19 | +class MarkupMacro(WikiMacroBase): |
| 20 | + """ |
| 21 | + For trusted users (TODO: new/more appropriate permission bit?), |
| 22 | + allow composing interactive HTML inside a Trac Wiki page, to |
| 23 | + facilitate faster iteration on user experiences. |
| 24 | +
|
| 25 | + Example usage in a Trac wiki page: |
| 26 | + {{{#!Markup |
| 27 | + <div id="target">Response code</div> |
| 28 | +
|
| 29 | + <script> |
| 30 | + fetch("/timeline").then( |
| 31 | + resp => document.getElementById("target").innerHTML = resp.status |
| 32 | + ); |
| 33 | + </script> |
| 34 | + }}} |
| 35 | +
|
| 36 | + Trac data could be fetched or markup could be rendered server-side |
| 37 | + and called via `args`: |
| 38 | + See https://trac.edgewall.org/wiki/WikiMacros#Macrowitharguments |
| 39 | + """ |
| 40 | + def expand_macro(self, formatter, name, content, args=None): |
| 41 | + if "TICKET_EDIT_CC" in formatter.perm: # supertriagers |
| 42 | + return Markup(content) |
| 43 | + return Markup("<p>Not authorized</p>") # or raise? |
| 44 | + |
| 45 | + |
18 | 46 | class CustomTheme(Component):
|
19 | 47 | implements(IRequestFilter)
|
20 | 48 |
|
|
0 commit comments