any code to bold text outside parenthesis on Ankidroid automatically?
I used o3 to get this:
(paste this in front/back templates)
<script>
// Function to bold text outside of normal parentheses.
function boldOutsideParentheses(text) {
let output = "";
let currentIndex = 0;
while (true) {
// Find the next opening parenthesis.
let start = text.indexOf("(", currentIndex);
if (start === -1) {
// No more parentheses; bold the remainder and exit.
output += "<b>" + text.substring(currentIndex) + "</b>";
break;
}
// Bold the text before the parenthesis.
output += "<b>" + text.substring(currentIndex, start) + "</b>";
// Find the corresponding closing parenthesis.
let end = text.indexOf(")", start);
if (end === -1) {
// If no closing parenthesis is found, bold the rest.
output += "<b>" + text.substring(start) + "</b>";
break;
}
// Append the parenthesized portion as-is.
output += text.substring(start, end + 1);
// Update the current index past the closing parenthesis.
currentIndex = end + 1;
}
return output;
}
// Get the element containing the field text.
var container = document.getElementById("text-container");
// Replace its content with the processed version.
container.innerHTML = boldOutsideParentheses(container.textContent);
</script>
Then you put <div id="text-container"> {{Field}} </div>
around every field (seperately). It worked for me but maybe someone here will have a better solution.
1 Like
(post deleted by author)