@@ -30,6 +30,8 @@ import org.nsh07.wikireader.parser.ReferenceData.refCount
3030import org.nsh07.wikireader.parser.ReferenceData.refList
3131import org.nsh07.wikireader.parser.ReferenceData.refListCount
3232import org.nsh07.wikireader.parser.ReferenceData.refListIndex
33+ import org.nsh07.wikireader.parser.ReferenceData.refTemplate
34+ import org.nsh07.wikireader.parser.ReferenceData.refTemplates
3335import kotlin.math.min
3436import kotlin.text.Typography.bullet
3537import kotlin.text.Typography.nbsp
@@ -334,8 +336,13 @@ fun String.toWikitextAnnotatedString(
334336 val currSubstring =
335337 substringMatchingParen(' {' , ' }' , i).substringBeforeLast(" }}" )
336338 when {
337- currSubstring.startsWith(" {{cite" , ignoreCase = true ) -> {
338- val text = if (currSubstring.startsWith(" {{cite book" , true )) {
339+ refTemplates.fastAny { item ->
340+ currSubstring
341+ .startsWith(item, ignoreCase = true )
342+ .also { if (it) refTemplate = item }
343+ } -> {
344+ val text =
345+ if (currSubstring.startsWith(" $refTemplate book" , true )) {
339346 val params = mutableMapOf<String , String >()
340347
341348 // Extract inside of {{Cite book ...}}
@@ -382,10 +389,10 @@ fun String.toWikitextAnnotatedString(
382389 .trim()
383390 .twas()
384391 } else if (
385- currSubstring.startsWith(" {{cite web" , true ) ||
386- currSubstring.startsWith(" {{cite news" , true ) ||
387- currSubstring.startsWith(" {{cite AV media" , true ) ||
388- currSubstring.startsWith(" {{cite press release" , true )
392+ currSubstring.startsWith(" $refTemplate web" , true ) ||
393+ currSubstring.startsWith(" $refTemplate news" , true ) ||
394+ currSubstring.startsWith(" $refTemplate AV media" , true ) ||
395+ currSubstring.startsWith(" $refTemplate press release" , true )
389396 ) {
390397 val params = mutableMapOf<String , String >()
391398
@@ -443,7 +450,11 @@ fun String.toWikitextAnnotatedString(
443450 .plus(" ." )
444451 .trim()
445452 .twas()
446- } else if (currSubstring.startsWith(" {{cite journal" , true )) {
453+ } else if (currSubstring.startsWith(
454+ " $refTemplate journal" ,
455+ true
456+ )
457+ ) {
447458 val params = mutableMapOf<String , String >()
448459
449460 // Extract inside of {{Cite journal ...}}
@@ -1147,7 +1158,7 @@ fun String.buildRefList() {
11471158
11481159fun String.splitNotInBraces (delimiter : Char , open : Char = '[', close : Char = ']'): List <String > {
11491160 var stack = 0
1150- var out = mutableListOf<String >()
1161+ val out = mutableListOf<String >()
11511162 var curr = " "
11521163
11531164 for (c in this ) {
@@ -1174,4 +1185,6 @@ object ReferenceData {
11741185 val refList = mutableMapOf<String , String >()
11751186 val refListIndex = mutableMapOf<Int , String >()
11761187 val refListCount = mutableMapOf<String , Int >()
1188+ var refTemplate = " {{cite"
1189+ val refTemplates = listOf (" {{cite" , " {{lien" , " {{cita" )
11771190}
0 commit comments