@@ -61,6 +61,9 @@ fun String.toWikitextAnnotatedString(
6161 var i = 0
6262 var number = 1 // Count for numbered lists
6363
64+ var italic = false
65+ var bold = false
66+
6467 val twas: String .() -> AnnotatedString = {
6568 this .toWikitextAnnotatedString(
6669 colorScheme,
@@ -680,8 +683,52 @@ fun String.toWikitextAnnotatedString(
680683 }
681684 }
682685
686+ currSubstring.startsWith(" {{redirect-distinguish" , true ) -> {
687+ val splitList = currSubstring.substringAfter(' |' ).split(' |' )
688+ append(" \" ${splitList.getOrNull(0 )} \" redirects here; not to be confused with " )
689+ splitList.subList(1 , splitList.size)
690+ .fastForEachIndexed { index: Int , it: String ->
691+ append(
692+ " [[${it.substringBefore(MAGIC_SEP )} |${
693+ it.substringAfter(
694+ MAGIC_SEP
695+ )
696+ } ]]" .twas()
697+ )
698+
699+ if (index == splitList.size - 2 && splitList.size > 2 ) append(
700+ " , or "
701+ )
702+ else if (index < splitList.size - 2 ) append(" , " )
703+ }
704+ append(' .' )
705+ }
706+
707+ currSubstring.startsWith(" {{for" , true ) -> {
708+ val splitList = currSubstring.substringAfter(' |' ).split(' |' )
709+ if (splitList.size > 1 ) {
710+ append(" For ${splitList[0 ]} , see " )
711+ splitList.subList(1 , splitList.size)
712+ .fastForEachIndexed { index: Int , it: String ->
713+ append(
714+ " [[${it.substringBefore(MAGIC_SEP )} |${
715+ it.substringAfter(
716+ MAGIC_SEP
717+ )
718+ } ]]" .twas()
719+ )
720+
721+ if (index == splitList.size - 2 && splitList.size > 2 ) append(
722+ " , and "
723+ )
724+ else if (index < splitList.size - 2 ) append(" , " )
725+ }
726+ append(' .' )
727+ }
728+ }
729+
683730 currSubstring.startsWith(" {{hatnote" , ignoreCase = true ) -> {
684- val curr = currSubstring.substringAfter(' |' )
731+ val curr = currSubstring.substringAfter(' |' ).replace( ' \n ' , ' ' )
685732 append(" ''$curr ''" .twas())
686733 }
687734
@@ -965,6 +1012,13 @@ fun String.toWikitextAnnotatedString(
9651012 append(" <sup>[citation needed]</sup>" .twas())
9661013 }
9671014
1015+ currSubstring.startsWith(" {{url" , true ) -> {
1016+ val curr = currSubstring.substringAfter(' |' , " " )
1017+ if (curr.matches(" .+://.+" .toRegex()))
1018+ append(" [$curr ${curr.substringAfter(" //" )} ]" .twas())
1019+ else append(" [https://$curr $curr ]" .twas())
1020+ }
1021+
9681022 currSubstring.startsWith(" {{Starbox begin" , ignoreCase = true ) -> {
9691023 val templateLength = currSubstring.length
9701024 i = input.indexOf(
@@ -1118,24 +1172,23 @@ fun String.toWikitextAnnotatedString(
11181172
11191173 ' \' ' ->
11201174 if (input.getOrNull(i + 1 ) == ' \' ' && input.getOrNull(i + 2 ) == ' \' ' ) {
1121- val subs = input.substring(i + 3 )
1122- val curr = subs.substring(
1123- 0 ,
1124- min(
1125- subs.length,
1126- (" '''(?!')" .toRegex().find(subs)?.range?.start ? : subs.length) + 2
1127- )
1128- )
1129- withStyle(SpanStyle (fontWeight = FontWeight .Bold )) {
1130- append(curr.twas())
1175+ if (! bold) {
1176+ pushStyle(SpanStyle (fontWeight = FontWeight .Bold ))
1177+ bold = true
1178+ } else {
1179+ pop()
1180+ bold = false
11311181 }
1132- i + = curr.length + 3
1182+ i + = 2
11331183 } else if (input.getOrNull(i + 1 ) == ' \' ' ) {
1134- val curr = input.substring(i + 2 ).substringBefore(" ''" )
1135- withStyle(SpanStyle (fontStyle = FontStyle .Italic )) {
1136- append(curr.twas())
1184+ if (! italic) {
1185+ pushStyle(SpanStyle (fontStyle = FontStyle .Italic ))
1186+ italic = true
1187+ } else {
1188+ pop()
1189+ italic = false
11371190 }
1138- i + = 1 + curr.length + 2
1191+ i + = 1
11391192 } else append(input[i])
11401193
11411194 ' [' ->
@@ -1170,7 +1223,7 @@ fun String.toWikitextAnnotatedString(
11701223 ) {
11711224 append(
11721225 (linkText.substringAfter(' ' ).removeSuffix(" ]" )
1173- .trim() + " \uD83D\uDD17 " )
1226+ .trim() + " \uD83D\uDD17 " )
11741227 )
11751228 }
11761229 i + = linkText.length - 1
0 commit comments