Changes for page XWiki Syntax Guide

Last modified by Ludovic Dubost on 2020/07/30 11:21

From version 4.1
edited by Ludovic Dubost
on 2014/11/18 12:31
Change comment: Install extension [org.xwiki.platform:xwiki-platform-help-ui-6.3]
To version 6.1
edited by Ludovic Dubost
on 2015/11/28 14:59
Change comment: Install extension [org.xwiki.platform:xwiki-platform-help-ui-7.3]

Summary

Details

Page properties
Content
... ... @@ -1,21 +1,33 @@
1 1  {{velocity output="false"}}
2 2  #set($SUPPORTED_SYNTAXES = {})
3 -#set($void = $SUPPORTED_SYNTAXES.put(1.0, 'XWiki Syntax 1.0'))
4 -#set($void = $SUPPORTED_SYNTAXES.put(2.0, 'XWiki Syntax 2.0'))
5 -#set($void = $SUPPORTED_SYNTAXES.put(2.1, 'XWiki Syntax 2.1'))
3 +#set($void = $SUPPORTED_SYNTAXES.put('1.0', 'XWiki Syntax 1.0'))
4 +#set($void = $SUPPORTED_SYNTAXES.put('2.0', 'XWiki Syntax 2.0'))
5 +#set($void = $SUPPORTED_SYNTAXES.put('2.1', 'XWiki Syntax 2.1'))
6 +##
7 +## needed for sections that contain descriptions valid for several syntaxes
8 +## basically it is hack to reuse the 2.0 descriptions for 2.1
9 +#set($SUPPORTED_SYNTAX_ORDER = ['1.0', '2.0', '2.1'])
10 +##
11 +## filter all syntaxes that are not installed/configured
12 +#set($configuredSyntaxIds = $xwiki.getConfiguredSyntaxes())
13 +#set($enabledSyntaxIds = [])
14 +#foreach($syntax in $services.rendering.getAvailableParserSyntaxes())
15 + #if($configuredSyntaxIds.contains($syntax.toIdString()))
16 + #set($discard = $enabledSyntaxIds.add($syntax.toIdString()))
17 + #end
18 +#end
19 +#set($unavailableSyntaxes=[])
20 +#foreach($supportedSyntax in $SUPPORTED_SYNTAX_ORDER)
21 + #set($fullSyntaxId = "xwiki/$supportedSyntax")
22 + #if(!$enabledSyntaxIds.contains($fullSyntaxId))
23 + #set($discard = $unavailableSyntaxes.add($supportedSyntax))
24 + #end
25 +#end
26 +#foreach($unavailableSyntax in $unavailableSyntaxes)
27 + #set($discard = $SUPPORTED_SYNTAX_ORDER.remove($unavailableSyntax))
28 + #set($discard = $SUPPORTED_SYNTAXES.removeKey($unavailableSyntax))
29 +#end
6 6  
7 -## We need a way to have a mapping between a string and a number, and we cannot use $mathtool.toDouble() because
8 -## it is locale dependent (see: http://jira.xwiki.org/browse/XWIKI-11343).
9 -## TODO: fix $mathtool or create a script service that handles this english-locale string<->number conversion,
10 -## because this fix is a bit hacky/spaghetti.
11 -## A better fix would be to refactor this application, because the syntax number SHOULD NOT BE USED because a syntax
12 -## is not supposed to be a number (imagine that we switch to 'Markdown', it is impossible to compare).
13 -## Instead, a syntax object should have a list of categories that the syntax supports.
14 -#set($NUMBERS_CONVERSION = {})
15 -#set($void = $NUMBERS_CONVERSION.put('1.0', 1.0))
16 -#set($void = $NUMBERS_CONVERSION.put('2.0', 2.0))
17 -#set($void = $NUMBERS_CONVERSION.put('2.1', 2.1))
18 -
19 19  #if ($request.xaction == 'switchContext')
20 20   $response.sendRedirect($request.target)
21 21   #stop
... ... @@ -26,10 +26,14 @@
26 26   #set ($crtCategoryId = $mathtool.toInteger($crtCategoryId))
27 27  #end
28 28  #set ($crtSectionId = "$!{request.section}")
29 -#set ($crtSyntaxVer = $NUMBERS_CONVERSION.get($request.syntax))
30 -#if ("$!crtSyntaxVer" == '' || !$SUPPORTED_SYNTAXES.containsKey($crtSyntaxVer))
31 - #set ($crtSyntaxVer = 2.1) ## Default to Syntax 2.1
41 +#set ($crtSyntaxVer = "$!{request.syntax}")
42 +#if (!$SUPPORTED_SYNTAXES.containsKey($crtSyntaxVer))
43 + ## Default to the most current one (if we have any)
44 + #if(!$SUPPORTED_SYNTAX_ORDER.isEmpty())
45 + #set ($crtSyntaxVer = $SUPPORTED_SYNTAX_ORDER.get($mathtool.sub($SUPPORTED_SYNTAX_ORDER.size(),1)))
46 + #end
32 32  #end
48 +#set($crtSyntaxPos = $SUPPORTED_SYNTAX_ORDER.indexOf($crtSyntaxVer))
33 33  
34 34  #set ($extraParamList = [])
35 35  #if ($request.language)
... ... @@ -61,7 +61,7 @@
61 61   #set($obj = $sectionDoc.getObject("XWiki.XWikiSyntaxClass"))
62 62  
63 63   ## detect if we entered a new category
64 - #if($catCount < $obj.getProperty("category").value))
80 + #if($catCount < $obj.getProperty("category").value)
65 65   ## Put previous category into map (if existing), and reset children map
66 66   #if($catId)
67 67   #set($cat = { 'id' : $catId, 'name' : $catName, 'children' : $catChildren })
... ... @@ -98,7 +98,7 @@
98 98   #end
99 99  
100 100   ## Add new sections to category children map
101 - #set($child = {'id' : $sectionDoc.getName().substring(11), 'minSyntax' : $obj.getProperty("minSyntaxVersion").value, 'maxSyntax' : $obj.getProperty("maxSyntaxVersion").value, 'name' : $sectionTitle})
117 + #set($child = {'id' : $sectionDoc.getName().substring(11), 'minSyntax' : $obj.getProperty("minSyntaxId").value, 'maxSyntax' : $obj.getProperty("maxSyntaxId").value, 'name' : $sectionTitle})
102 102   $catChildren.add($child)
103 103   #end
104 104  #end
... ... @@ -113,11 +113,11 @@
113 113  #foreach ($category in $syntaxMenu)
114 114   #set ($sectionsToRemove = [])
115 115   #foreach ($section on $category.children)
116 - ## TODO: This should be refactored (see before): a syntax is not supposed to be a number
117 - #if ($section.minSyntax > $crtSyntaxVer)
132 + #set($minSyntaxPos = $SUPPORTED_SYNTAX_ORDER.indexOf($section.minSyntax))
133 + #if ($minSyntaxPos > $crtSyntaxPos)
118 118   #set ($discard = $sectionsToRemove.add($section))
119 119   #if ($section.id == $crtSectionId)
120 - #set ($crtSectionId = '') ## clear section if it doesn't exist (can happen when switching from 2.0 to 2.1 syntax)
136 + #set ($crtSectionId = '') ## clear section if it doesn't exist (can happen when switching from 2.x to 1.0 syntax)
121 121   #end
122 122   #end
123 123   #end
... ... @@ -182,16 +182,24 @@
182 182   *#
183 183  #macro(syntax_displayCategory $sections $translationPrefix $heading)
184 184   #foreach ($section in $sections)
201 + #syntax_displaySection($section $translationPrefix $heading)
202 + #end
203 +#end
204 +
205 +#macro(syntax_displaySection $section $translationPrefix $heading)
185 185   #set ($displayVersion = $crtSyntaxVer)
186 - ## TODO: This should be refactored (see before): a syntax is not supposed to be a number
187 - #if ($crtSyntaxVer > $section.maxSyntax)
207 + ## here is the hack to display the description for 2.0 if we have no description for 2.x
208 + ## this likely needs more work if e.g. there is a 3.x which is not compatible with 2.x
209 + #set($maxSyntaxPos = $SUPPORTED_SYNTAX_ORDER.indexOf($section.maxSyntax))
210 + #if ($crtSyntaxPos > $maxSyntaxPos)
188 188   #set ($displayVersion = $section.maxSyntax)
189 189   #end
213 + #if($heading)
190 190   (% class="sectionheader" %)
191 191   $heading $section.name $heading
192 192  
217 + #end
193 193   {{include reference="XWiki.XWikiSyntax${section.id}" section="H${displayVersion}${section.id}"/}}
194 - #end
195 195  #end
196 196  
197 197  
... ... @@ -236,7 +236,7 @@
236 236   #set ($crtSelection = "$extraParams")
237 237   #end
238 238  {{html}}
239 - <form id="change-context" class="xformInline" action="">
263 + <form id="change-context" class="xformInline" action="$doc.getURL()">
240 240   <div>
241 241   <input type="hidden" name="xaction" value="switchContext" />
242 242   #if ($request.language)
... ... @@ -247,12 +247,10 @@
247 247   #end
248 248   <select id="goto-select" name="target" title="$escapetool.xml($services.localization.render("help.changesyntax"))">
249 249   <optgroup label="$services.localization.render('help.choose_syntax')">
250 - #set ($query = "syntax=1.0&${crtSelection}")
251 - <option value="$doc.getURL('view', $query)" #if($crtSyntaxVer==1.0)selected="selected"#end>$SUPPORTED_SYNTAXES.get(1.0)</option>
252 - #set ($query = "syntax=2.0&${crtSelection}")
253 - <option value="$doc.getURL('view', $query)" #if($crtSyntaxVer==2.0)selected="selected"#end>$SUPPORTED_SYNTAXES.get(2.0)</option>
254 - #set ($query = "syntax=2.1&${crtSelection}")
255 - <option value="$doc.getURL('view', $query)" #if($crtSyntaxVer==2.1)selected="selected"#end>$SUPPORTED_SYNTAXES.get(2.1)</option>
274 + #foreach($syntaxId in $SUPPORTED_SYNTAX_ORDER)
275 + #set ($query = "syntax=${escapetool.url($syntaxId)}&${crtSelection}")
276 + <option value="$escapetool.xml($doc.getURL('view', $query))"#if($crtSyntaxVer == $syntaxId) selected="selected"#end>$escapetool.html($SUPPORTED_SYNTAXES.get($syntaxId))</option>
277 + #end
256 256   </optgroup>
257 257   </select>
258 258   <span class="buttonwrapper"><input type="submit" value="$escapetool.xml($services.localization.render('admin.switchContext'))" class="button" /></span>
... ... @@ -280,7 +280,7 @@
280 280  #syntaxSwitch()
281 281  (((
282 282  #set ($query = "syntax=$escapetool.url(${crtSyntaxVer})${extraParams}")
283 -#if ($crtCategory){{html}}<a href="${doc.getURL('view', ${query})}">$syntaxTitle</a>{{/html}}#{else}(% class="current" %)$syntaxTitle#{end}#if ($crtCategory) (% class="separator" %)» #if ($crtSection){{html}}<a href="${crtCategory.url}">${crtCategory.name}</a>{{/html}}#{else}(% class="current" %)${crtCategory.name}#{end}#if ($crtSection) (% class="separator" %)» (% class="current" %)${crtSection.name}#end#end
305 +#if ($crtCategory){{html}}<a href="${doc.getURL('view', ${query})}">$syntaxTitle</a>{{/html}}#{else}(% class="current" %)$syntaxTitle#{end}#if ($crtCategory) » #if ($crtSection){{html}}<a href="${crtCategory.url}">${crtCategory.name}</a>{{/html}}#{else}(% class="current" %)${crtCategory.name}#{end}#if ($crtSection) » (% class="current" %)${crtSection.name}#end#end
284 284  )))
285 285  == $syntaxTitle: $sectionName ==
286 286  
... ... @@ -295,12 +295,7 @@
295 295   #set ($subHeading = '===')
296 296   #syntax_displayCategory($crtCategory.children 'syntax.' '==')
297 297   #else
298 - #set ($displayVersion = $crtSyntaxVer)
299 - #if ($crtSyntaxVer > $crtSection.maxSyntax)
300 - #set ($displayVersion = $crtSection.maxSyntax)
301 - #end
302 - #set ($subHeading = '==')
303 - {{include reference="XWiki.XWikiSyntax${crtSection.id}" section="H${displayVersion}${crtSection.id}"/}}
320 + #syntax_displaySection($crtSection 'syntax.' false)
304 304   #end
305 305   ))) ## syntax-page-content
306 306  {{/velocity}}