%PDF- %PDF-
Direktori : /home/waritko/jetty-distribution-9.4.21.v20190926/webapps/ROOT/templates/ |
Current File : //home/waritko/jetty-distribution-9.4.21.v20190926/webapps/ROOT/templates/titlevars.vm |
## ---------------------------------------------------------------------------- ## Compute the title by using the set title if defined or extract it from the ## content, taking into account the new title handling introduced in XWiki ## Platform 2.0. ## ## Prerequisite: Have the $renderedContent variable defined before calling ## this template. ## Output: In output the $renderedContent variable will be modified if needed ## and the $titleToDisplay variable created. ## ---------------------------------------------------------------------------- ## ## ---------------------------------------------------------------------------------- ## Remove the first rendered HTML header (H1-H6) if the following conditions are met: ## - the title compatibility flag is on ## - the title extracted from the rendered content is the same as the set title ## ## We need to do this since we've changed how titles are used and we need to ## ensure we don't break existing documents that have not yet migrated to the ## new way. ## ---------------------------------------------------------------------------------- ## NOTE: We don't have to escape the rendered title because: ## * if it comes from the document title/name then it was parsed as plain text ## * if it comes from a heading in the document content then special XML characters are already escaped. #set ($titleToDisplay = $tdoc.getRenderedTitle('xhtml/1.0')) #if ($xwiki.isTitleInCompatibilityMode() && $tdoc.title.length() == 0 && "$!renderedContent" != '') ## Look for first H1-H6 either in lowercase or uppercase #set ($regexResult = $regextool.find($renderedContent, "<([hH][1-6]).*?>(?:<span>)?(.*?)(?:</span>)?</[hH][1-6]>")) #if (!$regexResult.isEmpty() && $regexResult.get(2).group.equals($titleToDisplay)) ## We are extracting the title but putting it back but hidden since there are javascript code such as the ## javascript used to display section edition which needs the header to be there to work properly. #set ($hiddenTitle = "<${regexResult.get(1).group} class='hidden'>${regexResult.get(2).group}</${regexResult.get(1).group}>") #if ($regexResult.get(0).end < $mathtool.sub($renderedContent.length(), 1)) #set ($renderedContent = "${renderedContent.substring(0, $regexResult.get(0).start)}${hiddenTitle}${renderedContent.substring($regexResult.get(0).end)}") #else #set ($renderedContent = "${hiddenTitle}$renderedContent.substring(0, $regexResult.get(0).start)") #end #set ($titleToDisplay = $regexResult.get(2).group) #end #end