I have a text with html and css and need formatted text - html

I am re-making a website that takes tests. It was on PHP and now we are taking it to TypeScript.
I am using React and Material UI to display the feedback for the correct answer and explanation when the user sends their answer.
I get the feedback from an old database they were using (and that we will still use), and what they used to do was create a variable called html (string), and then concatenate each part of the html code raw.
Something like this: (in PHP .= and . is what you use to concatenate)
$html = '';
$html = '<div>';
$html .= '<p class="maintext"><span>' . $some_variable_they_want_in_span . '</span>';
$html .= $some_other_variable_that_is_empty_or_not_depending_on_if_clause . '</p>';
$html .= '</div>';
it is a pain... but the thing is. Now that I am showing the feedback, it comes in a terrible format that I can't simply show in a Typography element (Material UI, but I couldn't in a -p- tag either).
The text is, for example, this one:
" <p>Artículo séptimo.\n</p><p>1. En el ejercicio de sus funciones, los miembros de las Fuerzas y Cuerpos de Seguridad tendrán a todos los efectos legales el carácter de AGENTES DE LA AUTORIDAD.\n</p><p>2. Cuando se cometa delito de atentado, empleando en su ejecución armas de fuego, explosivos u otros medios de agresión de análoga peligrosidad, que puedan poner en peligro grave la integridad física de los miembros de las Fuerzas y Cuerpos de Seguridad, tendrán al efecto de su protección penal LA CONSIDERACIÓN DE AUTORIDAD.\n</p><p>3. La Guardia Civil sólo tendrá consideración de fuerza armada en el cumplimiento de las misiones de carácter militar que se le encomienden, de acuerdo CON EL ORDENAMIENTO JURÍDICO.\n</p><p>\n</p> "
How can I show this in a readable and nice text? I tried some npm packages and passing it through decodeURI but no change. Any ideas? Some text will even come with something like
"Artículo 2. Secretaría de Estado de Seguridad.<div>Corresponde a la persona titular de la Secretaría de Estado de Seguridad el ejercicio de las funciones a las que se refiere el artículo 62 de la Ley 40/2015, de 1 de octubre, y en particular, la dirección, coordinación y supervisión de los órganos directivos dependientes de la Secretaría de Estado, bajo la inmediata autoridad de la persona titular del Ministerio, para el ejercicio de las siguientes funciones:&nbsp;</div><ul><li><span style=\"letter-spacing: -0.015rem;\">El ejercicio del mando de las Fuerzas y Cuerpos de Seguridad DEL ESTADO, y la COORDINACIÓN Y SUPERVISIÓN DE LOS SERVICIOS Y MISIONES QUE LES CORRESPONDEN.</span></li></ul>"

Ok! So one of my coworkers found this solution:
import textParserTest from "~/utils/textparser"; // (which uses in its code the following: import parse from "html-react-parser";)
...
<div
contentEditable="true"
dangerouslySetInnerHTML={{
__html: textParserTest(props.question.answer, 0)
.toString()
.replaceAll("\\n", ""),
}}
></div>
So basically. html-react-parser package did the trick

Related

How to encode small caps for abbreviations using CSS if the font doesn't support this option?

I have a product named with an acronym and the name of the product is repeated many times on the page.
In Spanish, typographic style rules suggest using acronyms in small-caps, but the font I have does not provide the small-caps option.
What is the best way to code a simulation of small-caps in this case?
#import url('https://fonts.googleapis.com/css2?family=Nunito:wght#400;600;700;800&display=swap');
h1,p{font-family: Nunito;}
h1{font-size: 2em;
font-weight: 600;}
p{font-size: 1em;}
<h1>Cual es el mejor <abbr>SOAP</abbr> para bañar a tu perro</h1>
<p>Bañar a tu perro con <abbr>SOAP</abbr> no debería ser difícil. Sin embargo, es posible que el <abbr>SOAP</abbr> que consigas huela a gato, con lo cual afectes seriamente la personalidad de tu mascota. Es necesario probar el <abbr>SOAP</abbr> que vas a usar sobre tu perro en una persona antes de aplicárselo, asegurándote de que el <abbr>SOAP</abbr> no atraiga otras alimañas. Sigue a la persona a la que engañaste al cambiarle el <abbr>SOAP</abbr> y anota su interacción con otras formas de vida<p>
This is a good solution in any context given a font with enough font-weight options.
#import url('https://fonts.googleapis.com/css2?family=Nunito:wght#300;400;600;700;800&display=swap');
h1,p{font-family: Nunito;}
h1{font-size: 2em;
font-weight: 700;}
p{font-size: 1em;
font-weight:300}
abbr{
font-size: 1.5ex;
font-weight: bolder;
}
<h1>Cual es el mejor <abbr>SOAP</abbr> para bañar a tu perro</h1>
<p>Bañar a tu perro con <abbr>SOAP</abbr> no debería ser difícil. Sin embargo, es posible que el <abbr>SOAP</abbr> que consigas huela a gato, con lo cual afectes seriamente la personalidad de tu mascota. Es necesario probar el <abbr>SOAP</abbr> que vas a usar sobre tu perro en una persona antes de aplicárselo, asegurándote de que el <abbr>SOAP</abbr> no atraiga otras alimañas. Sigue a la persona a la que engañaste al cambiarle el <abbr>SOAP</abbr> y anota su interacción con otras formas de vida<p>

Html style not displayed on my Qweb Report

I got a Qweb Report on odoo11 that works perfectly ,but when i try adapting it on odoo12 the Html text loose it's style after adding [url.report ,http:/0.0.0.0:8069]
Here My Html field :
CGV_field = fields.Html(string="CGV", default=
"""<div><b>EXEMPLE DE CONDITIONS GENERALES DE VENTE</b></div>
<div><b><br>\n</b></div>
<b>Article 1 – Objet</b>
<br>
<p>Les présentes conditions régissent les ventes par la société (catégories ou nature des produits commercialisés par le site Internet).</p>
<br>
<b>Article 2 – Prix</b>
<br>
<p>Les prix de nos produits sont indiqués en Dinars toutes taxes comprises (TVA et autres taxes applicables au jour de la commande), sauf
indication contraire et hors frais de traitement et d’expédition.
Toutes les commandes quelle que soit leur origine sont payables en dinars.
La société se réserve le droit de modifier ses prix à tout moment, mais le produit sera facturé sur la base du tarif en vigueur au moment de la
validation de la commande et sous réserve de disponibilité.
Les produits demeurent la propriété de la société jusqu’au paiement complet du prix.
Attention : dès que vous prenez possession physiquement des produits commandés, les risques de perte ou d’endommagement des
produits vous sont transférés.</p>"""
Calling it on xml report :
<template id="report_cgv_account">
<t t-call="web.html_container">
<t t-foreach="docs" t-as="o">
<t t-call="elosys_cgv_in_report.internal_layout_cgv_o">
<div class="page">
<div class="oe_structure"/>
<div class="row" style="margin-left:10px;margin-right:10px;">
<span style=" margin-left:10px;margin-right:10px;" t-raw="o.company_id.CGV_field"/>
</div>
</div>
</t>
</t>
</t>
</template>
what it's supposed to show :
What i've got :
The System parameters key is report.url not url.report.
I've found the answer if any of you wish to know :
just add <![CDATA[ ]]> before <span>

How to enter Carriage Return in XSL

I am programming a simple web app. I have the following xml :`
<pelis>
<nombre id="avengers">Valoracion de Avengers Engame
<Valoracion>Calificacion general: 7.5</Valoracion>
<Valorpro>Calificacion de Cartelera Tinajo: 8</Valorpro>
<ComentariosP>Positivo: Buena pelicula, con un argumento interesante y envolvente. Las escenas estan bien rodadas y las coreografias bien ejecutadas. La banda sonora es buena, asi como el vestuario y sobre todo el maquillaje y los efectos especiales.</ComentariosP>
<ComentariosN>Negativo: Demasiado larga para nuestro gusto. Algunos fallos de guion y de realizacion. El sonido en algunas escenas es demasiado elevado y poco claro. El argumento es predecible desde muy temprano.</ComentariosN>
</nombre>
<nombre id="mamma">Valoracion de Mamma Mia!
<Valoracion>Calificacion general: 8</Valoracion>
<Valorpro>Calificacion de Cartelera Tinajo: 8</Valorpro>
<ComentariosP>Positivo: Pelicula muy recomendable. Unifica una comedia elaborada con una trama interesante y adictiva. La banda sonora de ABBA es impecable, sumado a un escenario espectacular, asi como unas coreografias muy elaboradas.</ComentariosP>
<ComentariosN>Negativo: Guion predecible. En algunas partes se hace un poco aburrida y no consigue captar al espectador. </ComentariosN>
</nombre>
<nombre id="hobbit">Valoracion de El Hobbit
<Valoracion>Calificacion general: 8</Valoracion>
<Valorpro>Calificacion de Cartelera Tinajo: 10</Valorpro>
<ComentariosP>Positivo: Gran película. Al igual que sus predecesoras (El señor de los Anillos I,II y III), es una obra de arte. Música impresionante, universo envolvente, escenas increibles, trama interesante, vestuario peculiar y una infinidad de aspectos positivos.</ComentariosP>
<ComentariosN>Negativo: El unico punto negativo es que puede ser un poco larga</ComentariosN>
</nombre>
<nombre id="hotel">Valoracion de Hotel Transilvania
<Valoracion>Calificacion general: 8.5</Valoracion>
<Valorpro>Calificacion de Cartelera Tinajo: 8</Valorpro>
<ComentariosP>Positivo: Una comedia para toda la familia. Peculiar en gran medida, dado que enfoca a los monstruos como seres humanizados. Buena trama, actores conocidos. Muy entretenida.</ComentariosP>
<ComentariosN>Negativo: No tiene ningun punto negativo destacable</ComentariosN>
</nombre>
<nombre id="lobo">Valoracion de El Lobo de Wall Street
<Valoracion>Calificacion general: 8</Valoracion>
<Valorpro>Calificacion de Cartelera Tinajo: 9</Valorpro>
<ComentariosP>Positivo: Una pelicula muy curiosa. Cuenta con grandes actores, un guion elaborado, unas escenas muy bien rodadas. Se sigue con gran interes y tiene giros que la convierten en un peliculon</ComentariosP>
<ComentariosN>Negativo: Demasiado larga (3 horas de duracion)</ComentariosN>
</nombre>
</pelis>`
and I also have the following XSL to transform it to HTML:
What I want is that all the text that will be shown in the html have carriage return after every line. I have tried adding and also what you can see in the code, but it doesnt work.
Because XSLT output is HTML, you can use <br/> for that. Or CSS for the <p> tag.
A NL or CR character in an HTML document displays as an ordinary space in the browser. If you want text to start on a new line when rendered in the browser, you typically want to output a <br> element.

sed remove anchor from text on specific href

I need to remove anchor in an HTML file, but only those with href containing todaycycling.com/tag.
What I do have:
<strong>Un Allemand peut en cacher un autre. Après Marcel Kittel, c\'est André Greipel qui a imposé sa pointe de vitesse à l\'issue de la cinquième étape du Tour d\'Italie. Dans une arrivée en faux plat montant, le sprinteur de la formation Lotto Soudal a produit un intense effort pour aller chercher la victoire devant Arnaud Démare (FDJ), encore deuxième, et Sonny Colbrelli (Bardiani-CSF).
What I am willing to have:
<strong>Un Allemand peut en cacher un autre. Après Marcel Kittel, c\'est André Greipel qui a imposé sa pointe de vitesse à l\'issue de la cinquième étape du Tour d\'Italie. Dans une arrivée en faux plat montant, le sprinteur de la formation Lotto Soudal a produit un intense effort pour aller chercher la victoire devant Arnaud Démare (FDJ), encore deuxième, et Sonny Colbrelli (Bardiani-CSF).
What I have tried so far:
sed 's|<a [^>]*todaycycling\.com\/tag\/[^>]*>\([^>]*\)</a>|\1|Ig' old.html > new.html
You were really close from the result, you can use the following sed command for this purpose:
sed 's#<a\s\+href\s*=\s*\\"http://todaycycling\.com/[^>]*>\([^<]*\)</a>#\1#g' tourDeFrance.txt
output:
<strong>Un Allemand peut en cacher un autre. Après Marcel Kittel, c\'est André Greipel qui a imposé sa pointe de vitesse à l\'issue de la cinquième étape du Tour d\'Italie. Dans une arrivée en faux plat montant, le sprinteur de la formation Lotto Soudal a produit un intense effort pour aller chercher la victoire devant Arnaud Démare (FDJ), encore deuxième, et Sonny Colbrelli (Bardiani-CSF).

Html rendering in ios

In order to render html tags in the description section of my ios app . im using "core text extension"
Normally it is working 100%.
But sometimes its not working.It is displayng a blank section.
ex - :
COMITE DE SELECTION « ARTWIGO »COMMENT ÇA MARCHE ? But et objectifs du comité de sélectionLe but de notre comité de sélection est d’opérer un choix, réfléchi et cohérent, des artistes présentés par ARTWIGO ; ceci, afin de préserver la qualité et le niveau nécessaires au succès de l’application et donc, de garantir la promotion des artistes.Cette sélection tient compte de critères spécifiques à chaque type d’expression artistique.Le comité est composé de spécialistes, indépendants, reconnus dans chaque domaine proposé par « Artwigo » et venant d’univers différents ;Le comité de sélection est constitué de 11 membres répartis de la manière suivante :- 3 membres « fondateurs » composant le bureau- 6 membres composant le comité consultatif.Christine Jamart, rédactrice en chef de l’Art Même. BruxellesCarine Fol, Directrice Artistique de La Centrale Electrique. BruxellesJoël Benzakin, Bela Edition. BruxellesJean-Louis Godefroid, Directeur Espace Contretype. BruxellesAndré Goldberg, resonsable Secteur Arts Plastiques au Centre Culturel Jacques Franck. BruxellesEmmanuel d’Autreppe, responsable de l’Annexe des Brasseurs (art contemporain). LiègeLa composition du bureau du comité est la suivante :Le Directeur du Comité : Jean-François Picaud Laethier de Morfouace La Secrétaire générale : Carole de Vleeschouwer le Rapporteur : Joël Van AudenhaegeLe comité de sélection se prononce à la majorité des voix.Confidentialité Le résultat des votes et leurs motivations ne sont pas fournis aux candidats.Les candidats sont juste informés, par email, de l’acceptation ou du rejet de leur candidature par la Secrétaire générale.Référence jfplm08-10-2012
Im rendering this using the folowing code structure
htmlText = [htmlText stringByReplacingOccurrencesOfString:#"''" withString:#"'"];
NSData *data = [htmlText dataUsingEncoding:NSUTF8StringEncoding];
NSAttributedString *string = [[NSAttributedString alloc] initWithHTML:data options:nil documentAttributes:NULL];
[DTAttributedTextContentView setLayerClass:[CATiledLayer class]];
DTAttributedTextView *_textView = [[DTAttributedTextView alloc] initWithFrame:frame];
_textView.textDelegate = self;
_textView.attributedString = string;
[self.view addSubview:_textView];
I dont know the reason but its not rendering properly
Is thr any solution for this issue
Thank you