Skip to content

Commit af5e207

Browse files
[PoC] Added Markup wiki macro.
1 parent f1011af commit af5e207

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

DjangoPlugin/tracdjangoplugin/plugins.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
from trac.web.chrome import INavigationContributor
66
from trac.web.api import IRequestFilter, IRequestHandler, RequestDone
77
from trac.web.auth import LoginModule
8+
from trac.wiki.macros import WikiMacroBase
89
from trac.wiki.web_ui import WikiModule
9-
from trac.util.html import tag
10+
from trac.util.html import Markup, tag
1011
from tracext.github import GitHubLoginModule, GitHubBrowser
1112

1213
from django.conf import settings
@@ -15,6 +16,33 @@
1516
from django.utils.http import url_has_allowed_host_and_scheme
1617

1718

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+
1846
class CustomTheme(Component):
1947
implements(IRequestFilter)
2048

0 commit comments

Comments
 (0)