NIHVIVO-1557 Fix firstLastList macro so it works with li elements that have class or other attributes

This commit is contained in:
rjy7 2011-02-04 17:53:37 +00:00
parent df9b1cb99d
commit dad29a5516

View file

@ -32,11 +32,11 @@
--> -->
<#macro firstLastList> <#macro firstLastList>
<#assign text> <#local text>
<#nested> <#nested>
</#assign> </#local>
<@processListItems text?matches("<li>.*?</li>", "s") /> <@processListItems text?matches("<li.*?</li>", "s") />
</#macro> </#macro>
<#----------------------------------------------------------------------------> <#---------------------------------------------------------------------------->
@ -94,13 +94,13 @@
RY Consider rewriting in Java. Probably designers won't want to modify this. RY Consider rewriting in Java. Probably designers won't want to modify this.
--> -->
<#macro firstLastListNested delim=","> <#macro firstLastListNested delim=",">
<#assign text> <#local text>
<#nested> <#nested>
</#assign> </#local>
<#-- Strip out a list-final delimiter, else (unlike most languages) it <#-- Strip out a list-final delimiter, else (unlike most languages) it
results in an empty final array item. --> results in an empty final array item. -->
<#assign text = text?replace("${delim}\\s*$", "", "r")> <#local text = text?replace("${delim}\\s*$", "", "r")>
<@processListItems text?split(delim) /> <@processListItems text?split(delim) />
@ -121,29 +121,29 @@
<#list items as item> <#list items as item>
<#-- A FreeMarker loop variable cannot have its value modified, so we use a new variable. --> <#-- A FreeMarker loop variable cannot have its value modified, so we use a new variable. -->
<#assign newItem = item?trim> <#local newItem = item?trim>
<#assign classVal = ""> <#local classVal = "">
<#-- Keep any class value already assigned --> <#-- Keep any class value already assigned -->
<#assign currentClass = newItem?matches("^<li [^>]*(class=[\'\"](.*?)[\'\"])")> <#local currentClass = newItem?matches("^<li [^>]*(class=[\'\"](.*?)[\'\"])")>
<#list currentClass as m> <#list currentClass as m>
${m?groups[2]}<br /> <#local classVal = m?groups[2]> <#-- get the assigned class value -->
<#assign classVal = m?groups[2]> <#local newItem = newItem?replace(m?groups[1], "")> <#-- remove 'class="xyz"' -->
<#assign newItem = newItem?replace(m?groups[1], "")>
</#list> </#list>
<#if item_index == 0> <#if item_index == 0>
<#assign classVal = "${classVal} first"> <#local classVal = "${classVal} first">
</#if> </#if>
<#if ! item_has_next> <#if ! item_has_next>
<#assign classVal = "${classVal} last"> <#local classVal = "${classVal} last">
</#if> </#if>
<#if classVal != ""> <#local classVal = classVal?trim>
<#assign classVal = classVal?replace("^ ", "", "r")>
<#if classVal?has_content>
<#-- Replace first instance only, in case the item contains nested li tags. --> <#-- Replace first instance only, in case the item contains nested li tags. -->
<#assign newItem = newItem?replace("<li", "<li class=\"${classVal}\"", "f")> <#local newItem = newItem?replace("<li", "<li class=\"${classVal}\"", "f")>
</#if> </#if>
${newItem} ${newItem}
</#list> </#list>