-
Notifications
You must be signed in to change notification settings - Fork 0
/
wikitext.app
134 lines (109 loc) · 4.98 KB
/
wikitext.app
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
module elib/elib-utils/wikitext
access control rules
rule page liveWikiTextPreview(){ true }
section templates
template outputRelaxed(s: WikiText){ rawoutput(s) }
section input wikitext with a preview
/*
Usage:
put inputWithPreview( someEnt.someWikiTextProp ) where you want the ordinary input on wikitext
put wikiTextPreview( someEnt.someWikiTextProp ) at the area where you want the preview to be displayed
*/
template inputWithPreview( txt : Ref<WikiText> ){
inputWithPreview( txt, false )[all attributes]{ elements }
}
template inputWithPreview( txt : Ref<WikiText>, unsafe : Bool){
var owningEntity := txt.getEntity()
var ph := if(owningEntity == null || owningEntity.version < 1) "wikitext-preview" else "ph-" + owningEntity.id.toString() + "-" + txt.getReflectionProperty().getName()
inputWithPreview( txt, unsafe, ph )[all attributes]{ elements }
}
native class utils.BuildProperties as BuildProperties {
static isWikitextHardwrapsEnabled() : Bool
}
template inputWithPreview( txt : Ref<WikiText>, unsafe : Bool, ph : String){
//Just a wrapper to make this overridable, to hook something in
inputWithPreview_internal( txt, unsafe, ph )[all attributes]{ elements }
}
template inputWithPreview_internal( txt : Ref<WikiText>, unsafe : Bool, ph : String){
var mathjaxHelpHTML := ", <a href=\\\"http://docs.mathjax.org/en/v2.7-latest/mathjax.html\\\" target=\\\"_blank\\\" title=\\\"Opens in new window\\\">MathJax</a> enabled, with delimiters: <code>\\\\\\\\( inline \\\\\\\\)</code> and <code>$$ block $$</code>."
var liveprevservice := navigate(liveWikiTextPreview())
var jsonParams := ""
var hardwrapsAttr := attribute("hardwraps")
init{
jsonParams := "[{name:'inputText', value: textVal}";
if(unsafe){
jsonParams := jsonParams + ",{name:'allowUnsafe', value:'1'}";
}
jsonParams := jsonParams + ",{name:'hardwraps', value:'" + hardwrapsAttr + "'}";
jsonParams := jsonParams + "]";
}
span[id=ph+"-wrap"]{
input( txt )[oninput:="var textVal = $('#" + ph + "-wrap textarea').val(); checkForUnsupportedCharacters( textVal ); replaceWithoutAction('" + liveprevservice + "', " + jsonParams + ", '" + ph + "');" + attribute("oninput"), all attributes except "oninput"]
}
elements
div[class="help-block"]{
markdownHelpLink " " hardwrapsInfo(hardwrapsAttr)
span[id="mathjax-"+id]{}
<script>
if (typeof MathJax != "undefined"){
$("#mathjax-~id").append( "~mathjaxHelpHTML" );
}
</script>
}
}
template hardwrapsInfo( hardwrapsAttr : String ){
var hardwrapsEnabled := (BuildProperties.isWikitextHardwrapsEnabled() || hardwrapsAttr == "true") && hardwrapsAttr != "false"
span[class="hardwraps-info"]{
if(hardwrapsEnabled){
span[title="Prepend input with '<!--DISABLE_HARDWRAPS-->' followed by 2 newlines to disable hardwraps"]{
"hardwraps " strong{ "enabled" } " - new lines are preserved "
}
} else {
span[title="Prepend input with '<!--ENABLE_HARDWRAPS-->' followed by 2 newlines to enable hardwraps"]{
"hardwraps " strong{ "disabled" } " - single new lines are ignored"
}
}
}
}
template wikiTextPreview( txt : Ref<WikiText> ){
wikiTextPreview( txt, false )
}
template wikiTextPreview( txt : Ref<WikiText>, unsafe : Bool ){
var owningEntity := txt.getEntity()
var ph := if(owningEntity == null || owningEntity.version < 1) "wikitext-preview" else "ph-" + owningEntity.id.toString() + "-" + txt.getReflectionProperty().getName()
wikiTextPreview(txt, unsafe, ph)[all attributes]
}
template wikiTextPreview( txt : Ref<WikiText>, unsafe : Bool, ph : String){
placeholder ""+ph{ wikiTextPreviewInternal( txt, unsafe )[all attributes] }
}
ignore-access-control template wikiTextPreviewInternal( txt : WikiText, unsafe : Bool){
if( unsafe ){
rawoutput( txt )[all attributes]
} else {
output( txt )[all attributes]
}
}
page liveWikiTextPreview(){
mimetype("text/plain")
var toRender := (getRequestParameter("inputText") as WikiText)
// var scriptId := "preview-" + now().getTime()
wikiTextPreviewInternal(toRender, getRequestParameter("allowUnsafe") != null)[hardwraps=getRequestParameter("hardwraps")]
//The following script is not needed anymore (requires WebDSL version > 13 Feb 2017) when using postProcess template, e.g.
//postProcess("Prism.highlightAll( node ); if(node != document){ MathJax.Hub.Queue([\"Typeset\",MathJax.Hub, node]); }")
// <script id=scriptId>
// var mathJaxEnabled = typeof MathJax != "undefined";
// var prismEnabled = typeof Prism != "undefined";
// if (mathJaxEnabled || prismEnabled){
// var parent = $('#~scriptId').parent();
// if(mathJaxEnabled){
// MathJax.Hub.Queue(["Typeset",MathJax.Hub, parent.get()]);
// }
// if(prismEnabled){
// Prism.highlightAll( parent );
// }
// }
// </script>
}
template markdownHelpLink(){
navigate url("https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet")[target:="_blank", title:="Opens in new window"]{iQuestionSign() " Markdown Help"}
}