1
Whereas I have random classes, may or may not have a class in the paragraph. I need to put an empty paragraph, when there is not an empty paragraph on top of the text. I can receive texts in these three formats, and the only one that should receive an extra paragraph is the text 3, because he doesn’t have an empty paragraph on top.
Obs: (with or without style and class), the problem happens because of this.
text 1:
<p class="blablabla" style="" ></p>
<p>Nono nonono nonononono </p>
text 2:
<p class="blobloblo"> </p>
<p>Nono nonono nonononono </p>
text 3:
<p class="blublublu" style="" ><span>nono nonono no</span></p>
<p>Nono nonono nonononono </p>
Here’s the method I have, only there’s a problem, it’s not just taking the first paragraph, so I don’t know what to do for it match first paragraph only:
$scope.trustAsHtml = function(string) {
var result = $sce.trustAsHtml(string);
if (angular.isDefined(result)) {
result = result.replace(/\n/gim, '');
if (!result.match(/^<p(.*)?>(\s| )<\/p>/gim)) {
result = '<p class="paragraph-added"></p>' + result;
}
return result;
}
};
I did not understand the reason of the negative... it is quite clear what I need. For anyone to understand.
– Ivan Ferrer
This question I also did not understand the negative, but in the other maybe negatived because it is below google. And the worst that I will go through the same situation you, in the other question, because I intend to use the webview to display my hosted content and now I learned that google will block me because of their new policy.
– Augusto Vasques
My case is that there are two companies that have united becoming one, so we have to join two different architectures in the same app, in the other question that I was negative.
– Ivan Ferrer
"Put two architectures together in the same app": Okay, it really does blow your mind, but it usually does this by creating a layer of data-saving abstraction, so it chews the data into a useful, standardized data model for the app
– Jefferson Quesado
Instead of using regex
DOMParser
withvar el = domparsed.getElementsByTag('p');
and check if there is the first paragraphel[0]
is empty withel[0].textContent.trim() == ''
, would already be much simpler, so if there is not enough avar novo = document.createElement('p'); p.innerHTML = ' '; domparsed.insertBefore(novo, domparsed.firstChild);
– Guilherme Nascimento
@Guilhermenascimento, I’ll try to use this... and I’ll answer you if it works. Thanks for the tip.
– Ivan Ferrer
@Ivanferrer edited the comment with some more relevant code
– Guilherme Nascimento
Today I get one
json
with HTML... in string format, so I need to do this before it leaves for theng-bind-html="saida"
, how could I make it a DOM object, before it exits and is rendered in the view? I would have to create an element?– Ivan Ferrer
like this?
var el = document.createElement('div');
 el.setAttribute('id', 'content_text_materia');
 el.innerHTML = result;
– Ivan Ferrer
But wasn’t it just add the paragraph when it didn’t exist? I’ll try rereading the question to see if I understand your need better.
– Guilherme Nascimento
I think it worked, man, thanks!
– Ivan Ferrer