Remove empty indent paragraphs in ckeditor5 - ckeditor

Is there any right way to remove emmpty p tags in ckeditor5 ?
For example like that:
<p><p>contents begin</p><p> </p><p> </p><p> </p><p> </p><p> </p><p>contents end</p><p> </p><p> </p><p> </p><p> </p><p> </p></p>
I know solution with https://ckeditor.com/docs/ckeditor5/latest/api/module_core_editor_utils_dataapimixin-DataApi.html#function-setData
But it seems more like crutch, than right way.

Related

How to select by non-direct child condition in Xpath?

I would like to show an example.
This how the page looks:
<a class="aclass">
<div class="divclass"></div>
<div id="innerclass">
<span class="spanclass">Hello</span>
</div>
</a>
<a class="aclass">
<div class="divclass"></div>
<div id="innerclass">
<span class="spanclass">Pick Delivery Location</span>
</div>
</a>
I want to select anchor tags that have a child (direct or non-direct) span that has the text 'Hello'.
Right now, I do something like this:
//a[#class='aclass'][div/span[text() = 'Hello']]
I want to be able to select without having to select direct children (div in this case), like this:
//a[#class='aclass'][//span[text() = 'Hello']]
However, the second one finds all the anchor tags with the class 'aclass' rather than the one with the span with 'Hello' text.
I hope I worded my question clearly. Please feel free to edit if necessary.
In your attempt, // goes back to the root of the document - effectively you are saying "Give me the as for which there is a span anywhere in the document", which is why you get them all.
What you need is the descendant axis :
//a[#class='aclass' and descendant::span[text() = 'Hello']]
Note I have joined the conditions with and, but two separate conditions would also work.

CSS / xpath selector to find h3 tag with text in a given class?

Selector to find a element with <h3> with some text which is a descendant of a class ?
Tried with xpath="//*[#class='body']//descendant::h3[contains(text(), sampletext]
This doesn't work. Is there a way I can find this ?
<div class="body">
<h3> text1 </h3>
<p>....</p>
<h3> text2 </h3>
<p>... </p>
<h3> text3 </h3>
</div>
Selector to find <h3> tag containing text3 in className="body"?
Try this simple xpath and let me know if facing any issue
//div[#class='body']/h3[text()='text3']
OR for trimming the spaces before and after your text
//div[#class='body']/h3[normalize-space()='text3']
Below to get the element bases on partial text match
//div[#class='body']/h3[contains(.,'text3')]
You missed single quote contains(text(), sampletext)]
It should be 'sampletext'
xpath="//div[#class='body']//descendant::h3[contains(text(), 'sampletext')]"
if you want to find h3 tag
xpath="//div[#class='body']/h3[contains(text(), 'text3')]"

CKEditor bulletlist (and orderedlist) behavior wrong when I cut it?

I am using CKEditor and I love it.
but there's truble when I use bullet(ordered)list and cut it.
1.make list like below.
List item1
List item2
List item3
2.then, cut text from end of "ListItem3" to start of "ListItem1"(not delete but cut using cmd + x).
3.ul(or ol) tag is remain like below.
remained HTML like this
<ul>
<li>​​​​​​​
<ul>
<li>
<ul></ul>
</li>
</ul>
</li>
</ul>
can I avoid this behavior? or are there any workaroud?

Xpth extract plain email text

I'm trying to extract the email text from a list but without success.
In particular I've used this code
//li/div/p//*[contains(., '#')]
but strangely it doesn't work! Could you help me?
Here's the code exemple
<li class="bgmp_list-item">
<h3 class="bgmp_list-placemark-title">
Name1
</h3>
<div class="bgmp_list-description">
<p class="">
<strong class="">Responsible:</strong> John Doe <br>
<strong class="">Site:</strong> <a title="www.exemple.com" href="http://www.exemple.com" onclick="javascript:_gaq.push(['_trackEvent','outbound-article','www.2ld.it']);" target="_blank" class="">www.2ld.it</a>
<br>
<strong class="">Email:</strong> some_email#email.com
<br><strong class="">Address:</strong> 3, Main Street 00000, London <br>
<strong>Tel:</strong> 00 000000 <strong>Fax:</strong> 0000000
</p>
</div>
You're almost there but not quite. For the sample code the correct xpath would be
//p/text()[contains(.,'#')]
Not to reinvent the wheel here is a very good explanation on it on another answer
By using p//*[contains(., '#')] you apply the predicate on individual child elements of <p>, while there is no such child element because
the target email address text is direct child of <p>. This is one of the reason why the intial XPath didn't work. Applying the predicate on <p> directly should work :
//li/div/p[contains(., '#')]
but that will return the <p> element. If you need to return only the text node that contains email address, then the predicate should be applied on individual text nodes within <p>, as mentioned in the other answer :
//li/div/p/text()[contains(., '#')]

Help with regex / ruby

Hey guys, so I'm making a script to featch words/results off of this site (http://grecni.com/texttwist.php), So I already have the http request post ready, ect.
Only thing I need now is to fetch out the words, So I'm working with an html source that looks like so:
<html>
<head>
<title>Text Twist Unscrambler</title>
<META NAME="keywords" CONTENT="Text,Twist,Text Twist,Unscramble,Free,Source,php">
</head>
<body>
<font face="arial,helvetica" size="3">
<p>
<b>3 letter words</b><br>sae sac ess aas ass sea ace sec <p>
<b>4 letter words</b><br>cess secs seas ceca sacs case asea casa aces caca <p>
<b>5 letter words</b><br>cacas casas caeca cases <p>
<b>6 letter words</b><br>access <br><br>
Found 23 words in 0.22962 seconds
<form action="texttwist.php" method="post">
enter scrambled letters and I'll return all word combinations<br>
<input type="text" name="l" value="asceacas" size="20" maxlength="20">
<input type="submit" name="button" value="unscramble">
<input type="button" name="clear" value="clear" onClick="this.form.l.value='';">
</form><p>
<a href=texttwist.phps>php source</a>
- it's kinda ugly, but it's fast<p>
<a href=/>back to my page</a>
</body>
</html>
I'm trying to fetch the words like "sae", "sav", "secs", "seas", "casas", ect.
Any help?
This is the farthest i've gotten, don't know what to do from here.: link text
Any suggestions? Help?
Use a HTML parser like Nokogiri.
If you want any kind of robustness you really want a parser, as mentioned by Adrian, Nokogiri is most popular solution.
If you insist, aware of the madness that you may be in for as the page becomes more complex the following may help:
Search for a line that matches
/^<b>\d+ letter words/
and then you can dig out the bits like so:
a = line.split(/<br>/)[1] # the second half
a.gsub!('<p>', '') # take out the trailing <p>
res = a.split(' ')# this is your data
That being said, this isn't anything you want in production code. You'll be surprised how learning a parser will change how you see this problem.

Resources