123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- 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 '<span ' + classString + '>' + stringPartWithstyle.stringPart + '</span>'
- })
- let outString = formattedStringParts.join('');
- return outString.replaceAll('\n', '<br>');
- }
|