Toggle navigation
Log-in
Wiki Index
Page Index
User Index
XWiki
XWiki Syntax Guide
Wiki source code of
XWiki Syntax Guide
Last modified by
Ricardo Rodríguez Fernández
on 2015/11/24 10:23
Hide line numbers
1: {{velocity output="false"}} 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')) 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 30: 31: #if ($request.xaction == 'switchContext') 32: $response.sendRedirect($request.target) 33: #stop 34: #end 35: 36: #set ($crtCategoryId = "$!{request.category}") 37: #if ($crtCategoryId != '') 38: #set ($crtCategoryId = $mathtool.toInteger($crtCategoryId)) 39: #end 40: #set ($crtSectionId = "$!{request.section}") 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 47: #end 48: #set($crtSyntaxPos = $SUPPORTED_SYNTAX_ORDER.indexOf($crtSyntaxVer)) 49: 50: #set ($extraParamList = []) 51: #if ($request.language) 52: #set ($discard = $extraParamList.add("language=$escapetool.url($request.language)")) 53: #end 54: #if ($request.xpage) 55: #set ($discard = $extraParamList.add("xpage=$escapetool.url($request.xpage)")) 56: #end 57: #if ($extraParamList.isEmpty()) 58: #set ($extraParams = '') 59: #else 60: #set ($extraParams = '&'+$stringtool.join($extraParamList,'&')) 61: #end 62: 63: ## 64: ## Syntax menu map 65: ## 66: #set($syntaxMenu = []) 67: #set($catCount = -1) 68: #set($catName = "") 69: #set($catChildren = []) 70: #set($results = $services.query.xwql('from doc.object(XWiki.XWikiSyntaxClass) as syntax order by syntax.category, syntax.section').addFilter('currentlanguage').addFilter('unique').execute()) 71: 72: #if($results.empty) 73: No syntax sections found! 74: #else 75: #foreach ($item in $results) 76: #set($sectionDoc = $xwiki.getDocument($item)) 77: #set($obj = $sectionDoc.getObject("XWiki.XWikiSyntaxClass")) 78: 79: ## detect if we entered a new category 80: #if($catCount < $obj.getProperty("category").value) 81: ## Put previous category into map (if existing), and reset children map 82: #if($catId) 83: #set($cat = { 'id' : $catId, 'name' : $catName, 'children' : $catChildren }) 84: $syntaxMenu.add($cat) 85: #set($catChildren = []) 86: #end 87: ## extract new catId and catName values, and sectionTitle as we are already traveling the DOM 88: #foreach($headerBlock in $sectionDoc.getDocument().getXDOM().getBlocks('class:HeaderBlock', 'DESCENDANT')) 89: #if($headerBlock.getLevel().getAsInt() == 1) 90: #set($catId = $headerBlock.getId().substring(1)) 91: #set($catName = $services.rendering.render($headerBlock, 'plain/1.0')) 92: #elseif($headerBlock.getLevel().getAsInt() == 2) 93: #set($sectionTitle = $services.rendering.render($headerBlock, 'plain/1.0')) 94: #break 95: #end 96: #end 97: #foreach($headerBlock in $sectionDoc.getTranslatedDocument().getDocument().getXDOM().getBlocks('class:HeaderBlock', 'DESCENDANT')) 98: #if($headerBlock.getLevel().getAsInt() == 1) 99: #set($catName = $services.rendering.render($headerBlock, 'plain/1.0')) 100: #elseif($headerBlock.getLevel().getAsInt() == 2) 101: #set($sectionTitle = $services.rendering.render($headerBlock, 'plain/1.0')) 102: #break ## otherwise finds nested example headlines 103: #end 104: #end 105: #set($catCount = $obj.getProperty("category").value) 106: #else 107: ## still in same category, only need new section title 108: #foreach($headerBlock in $sectionDoc.getTranslatedDocument().getDocument().getXDOM().getBlocks('class:HeaderBlock', 'DESCENDANT')) 109: #if($headerBlock.getLevel().getAsInt() == 2) 110: #set($sectionTitle = $services.rendering.render($headerBlock, 'plain/1.0')) 111: #break 112: #end 113: #end 114: #end 115: 116: ## Add new sections to category children map 117: #set($child = {'id' : $sectionDoc.getName().substring(11), 'minSyntax' : $obj.getProperty("minSyntaxId").value, 'maxSyntax' : $obj.getProperty("maxSyntaxId").value, 'name' : $sectionTitle}) 118: $catChildren.add($child) 119: #end 120: #end 121: #set($cat = { 'id' : $catId, 'name' : $catName, 'children' : $catChildren }) 122: $syntaxMenu.add($cat) 123: 124: 125: ## 126: ## Filter only the sections that are valid for a Syntax 127: ## 128: #set ($categoriesToRemove = []) 129: #foreach ($category in $syntaxMenu) 130: #set ($sectionsToRemove = []) 131: #foreach ($section on $category.children) 132: #set($minSyntaxPos = $SUPPORTED_SYNTAX_ORDER.indexOf($section.minSyntax)) 133: #if ($minSyntaxPos > $crtSyntaxPos) 134: #set ($discard = $sectionsToRemove.add($section)) 135: #if ($section.id == $crtSectionId) 136: #set ($crtSectionId = '') ## clear section if it doesn't exist (can happen when switching from 2.x to 1.0 syntax) 137: #end 138: #end 139: #end 140: #set ($discard = $category.children.removeAll($sectionsToRemove)) 141: #if ($category.children.size() == 0) 142: #set ($discard = $categoriesToRemove.add($category)) 143: #end 144: #end 145: #set ($discard = $syntaxMenu.removeAll($categoriesToRemove)) 146: #if ("$!crtCategoryId" != '' && $crtCategoryId >= $syntaxMenu.size()) 147: #set ($crtCategoryId = '') 148: #end 149: 150: #if ($crtSectionId != '') 151: #set ($crtItemId = $crtSectionId) 152: #elseif ($crtCategoryId != '') 153: #set ($crtItemId = $syntaxMenu.get($crtCategoryId).id) 154: #end 155: #set ($crtSection = $util.null) 156: #set ($crtCategory = $util.null) 157: 158: 159: ## 160: ## Prepare the Syntax menu map for processing 161: ## 162: #foreach ($category in $syntaxMenu) 163: ## "Standard" URLs and icons for categories 164: #set ($category.url = "?syntax=$escapetool.url(${crtSyntaxVer})&category=${mathtool.sub($velocityCount, 1)}${extraParams}") 165: #set ($category.cssClass = "${category.id}Icon") 166: #if ("$!{crtCategoryId}" != '' && $velocityCount == $mathtool.add($crtCategoryId, 1)) 167: #set ($crtCategory = $category) 168: #end 169: ## 170: ## Process each syntax section 171: #foreach ($section in $category.children) 172: #if ($xwiki.exists("XWiki.XWikiSyntax${section.id}")) 173: #if ($crtSectionId == $section.id) 174: #set ($crtSection = $section) 175: #set ($crtCategory = $category) 176: #end 177: #set ($section.url = "?syntax=$escapetool.url(${crtSyntaxVer})§ion=$escapetool.url(${section.id})${extraParams}") 178: #end 179: #end 180: #end 181: 182: #** 183: * Displays the sections from a syntax category 184: * 185: * Expected format: 186: * sections = vector of items 187: * item = map with the following fields: 188: * 'id' : mandatory 189: * 'name' : the text displayed for the corresponding menu item; 190: * optional, defaults to 191: * $services.localization.render("$!{translationPrefix}${item.id}") 192: * 193: * @param $sections the sections list, in the format described above 194: * @param $translationPrefix the translation prefix added to the id of each 195: * item, in order to generate the name and description; ignored when 196: * name or description are specified 197: * @param $heading the heading syntax 198: *# 199: #macro(syntax_displayCategory $sections $translationPrefix $heading) 200: #foreach ($section in $sections) 201: #syntax_displaySection($section $translationPrefix $heading) 202: #end 203: #end 204: 205: #macro(syntax_displaySection $section $translationPrefix $heading) 206: #set ($displayVersion = $crtSyntaxVer) 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) 211: #set ($displayVersion = $section.maxSyntax) 212: #end 213: #if($heading) 214: (% class="sectionheader" %) 215: $heading $section.name $heading 216: 217: #end 218: {{include reference="XWiki.XWikiSyntax${section.id}" section="H${displayVersion}${section.id}"/}} 219: #end 220: 221: 222: #** 223: * Displays the syntax categories 224: * 225: * Expected format: 226: * sections = vector of items 227: * item = map with the following fields: 228: * 'id' : mandatory 229: * 'name' : the text displayed for the corresponding menu item; 230: * optional, defaults to 231: * $services.localization.render("$!{translationPrefix}${item.id}") 232: * 233: * @param $sections the sections list, in the format described above 234: * @param $translationPrefix the translation prefix added to the id of each 235: * item, in order to generate the name and description; ignored when 236: * name or description are specified 237: *# 238: #macro(syntax_displayCategories $syntaxMenu $translationPrefix) 239: #set ($subHeading = '====') 240: #foreach ($category in $syntaxMenu) 241: == $category.name == 242: 243: #syntax_displayCategory($category.children 'syntax.' '===') 244: #end 245: #end 246: 247: #** 248: * Displays the drop down allowing to switch the syntax. 249: *# 250: #macro (syntaxSwitch) 251: #set ($crtSelection = "") 252: #if ("$!{crtCategoryId}" != '') 253: #set ($crtSelection = "category=$escapetool.url($!{crtCategoryId})") 254: #elseif ($crtSectionId != '') 255: #set ($crtSelection = "section=$escapetool.url($!{crtSectionId})") 256: #end 257: #if ($crtSelection != "") 258: #set ($crtSelection = "${crtSelection}${extraParams}") 259: #else 260: #set ($crtSelection = "$extraParams") 261: #end 262: {{html}} 263: <form id="change-context" class="xformInline" action="$doc.getURL()"> 264: <div> 265: <input type="hidden" name="xaction" value="switchContext" /> 266: #if ($request.language) 267: <input type="hidden" name="language" value="$escapetool.xml($request.language)" /> 268: #end 269: #if ($request.xpage) 270: <input type="hidden" name="xpage" value="$escapetool.xml($request.xpage)" /> 271: #end 272: <select id="goto-select" name="target" title="$escapetool.xml($services.localization.render("help.changesyntax"))"> 273: <optgroup label="$services.localization.render('help.choose_syntax')"> 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 278: </optgroup> 279: </select> 280: <span class="buttonwrapper"><input type="submit" value="$escapetool.xml($services.localization.render('admin.switchContext'))" class="button" /></span> 281: </div> 282: </form> 283: {{/html}} 284: #end 285: {{/velocity}} 286: 287: {{velocity}} 288: ##************************************************************************************************** 289: ## From the Administration Sheet, used to display a common UI for some wiki features 290: ## here used to display all categories / sections of the syntax guide 291: ##************************************************************************************************** 292: $xwiki.get('jsx').use($doc.getFullName())## 293: $xwiki.get('ssx').use($doc.getFullName())## 294: #if ($crtSectionId != '') 295: #set ($sectionName = ${crtSection.name}) 296: #elseif ($crtCategoryId != '') 297: #set ($sectionName = ${crtCategory.name}) 298: #else 299: #set ($sectionName = $services.localization.render("help.syntaxall")) 300: #end 301: #set ($syntaxTitle = $services.localization.render("help.syntaxtitle", ["${crtSyntaxVer}"])) 302: #syntaxSwitch() 303: ((( 304: #set ($query = "syntax=$escapetool.url(${crtSyntaxVer})${extraParams}") 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 306: ))) 307: == $syntaxTitle: $sectionName == 308: 309: #verticalNavigation($syntaxMenu {'translationPrefix' : 'syntax.', 'crtItemId' : "$!crtItemId", 'cssClass' : 'syntax-menu'}) 310: ##----------------------------------------- 311: ## syntax-page display 312: ##----------------------------------------- 313: (% id="syntax-page-content" %)((( 314: #if(!$crtSection && !$crtCategory) 315: #syntax_displayCategories($syntaxMenu 'syntax.') 316: #elseif (!$crtSection) 317: #set ($subHeading = '===') 318: #syntax_displayCategory($crtCategory.children 'syntax.' '==') 319: #else 320: #syntax_displaySection($crtSection 'syntax.' false) 321: #end 322: ))) ## syntax-page-content 323: {{/velocity}}