To do this properly, you need a HTML parser (like JSOUP), or better yet, some library that can convert HTML to plain text. Then you have to expose that tool to templates, etc.
But, the question was, how to replace something with its ordinal. You have to write a macro for that:
<#-- Prints 1st parameter with replacements, inserting the ordinal of replacement before each. -->
<#macro printWithNumberedReplacements s replaced replacement>
<#local unprintedIdx = 0>
<#list 1..10000000 as ordinal>
<#local liIdx = s?index_of(replaced, unprintedIdx)>
<#if liIdx == -1>
${s[unprintedIdx ..]}<#t>
<#break>
<#else>
${s[unprintedIdx ..< liIdx]}${ordinal}${replacement}<#t>
<#local unprintedIdx = liIdx + replaced?length>
</#if>
</#list>
</#macro>
and then:
<@printWithNumberedReplacements content '<li>' ' '/>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…