export function getFormattedContext(formattedContext){
let formatArray = JSON.parse(formattedContext);
// Correct formatting style where needed
formatArray.forEach(
formatObj => {
formatObj.cssStyles = [];
let formatting = formatObj.formatting;
if (formatting.includes('grassetto')){
formatObj.cssStyles.push('bold');
}
if (formatting.includes('corsivo')) {
formatObj.cssStyles.push("italic");
}
// Handle 'barrato' and 'sottolineato' together!
if (formatting.includes('sottolineato') && formatting.includes('barrato')) {
formatObj.cssStyles.push("underlinethrough");
}
else if (formatting.includes('sottolineato')) {
formatObj.cssStyles.push("underline");
}
else if (formatting.includes('barrato')) {
formatObj.cssStyles.push("linethrough");
}
if (formatting.includes('evidenziato')) {
formatObj.cssStyles.push("highlight")
}
}
);
return combineStringPartsWithStyles(formatArray);
}
export function combineStringPartsWithStyles(stringPartArray){
let formattedStringParts = stringPartArray.map(stringPartWithstyle => {
let classString = 'class="' + stringPartWithstyle.cssStyles.join(" ") + '"';
return '' + stringPartWithstyle.stringPart + ''
})
let outString = formattedStringParts.join('');
return outString.replaceAll('\n', '
');
}