How convert whatsapp formatted in ruby? - ruby

I have a formated text in ruby with *text in bold* and _ text in italic_
How to replace all *text in bold* by <b> text in bold </b>
and _ text in italic _ by <i> text in italic </i> ?

Related

"ValueError: 'PySide6.QtGui.QPainter.drawText' called with wrong argument values" even though the arguments seem right

MRE:
from PySide6 import QtWidgets as qtw
from PySide6 import QtGui as qtg
from PySide6 import QtCore as qtc
class Delegate(qtw.QAbstractItemDelegate):
def paint(self, painter, option, index):
text = index.model().data(
index, qtc.Qt.ItemDataRole.DisplayRole
)
text_rect = qtc.QRect(
option.rect.left(),
option.rect.top(),
option.rect.width(),
200
)
painter.drawText(text_rect, 0, text, text_rect)
def sizeHint(self, option, index):
return qtc.QSize(200, 200)
class Model(qtc.QAbstractListModel):
def __init__(self) -> None:
super().__init__()
self._texts = ["text" for _ in range(10)]
def rowCount(self, _) -> int:
return 10
def data(self, index, role):
if not index.isValid():
return None
if role == qtc.Qt.ItemDataRole.DisplayRole:
return self._texts[index.row()]
return None
class MainWindow(qtw.QMainWindow):
def __init__(self):
super().__init__()
delegate = Delegate(self)
self._model = Model()
self._view = qtw.QListView(self)
self._view.setModel(self._model)
self._view.setItemDelegate(delegate)
self.setCentralWidget(self._view)
self.show()
app = qtw.QApplication()
mw = MainWindow()
app.exec()
Error:
ValueError: 'PySide6.QtGui.QPainter.drawText' called with wrong argument values:
PySide6.QtGui.QPainter.drawText(PySide6.QtCore.QRect(230, 10, 0, 200), 0, '', PySide6.QtCore.QRect(230, 10, 0, 200))
Found signature:
PySide6.QtGui.QPainter.drawText(PySide6.QtCore.QRect, int, str, PySide6.QtCore.QRect)
One of the signatures I get on VSCode for painter.drawText:
def drawText(r: PySide6.QtCore.QRect, flags: int, text: str, br: PySide6.QtCore.QRect) -> None
The provided signatures and the passed arguments match, don't they? Could this be a bug in PySide6?
The code causing the error is in the paint method in the Delegate class.
Please, ignore this.
Text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text.

inDesign extract special objects form plain text paragraph

i'm trying to find a way to get only the plain text contained in a paragraph, and exclude the special objects contained in the para.
This is an example of my case.
I have this paragraph, obtained with app.activeDocument. :
paragraph , which contains 2 graphics before the plain text.
I achived this by doing:
var style = app.activeDocument.paragraphStyles.item("My Para Style");
app.findTextPreferences.appliedParagraphStyle = style;
var list = app.activeDocument.findText();
If I print the paragraph contents by list[0].paragraphs[0].contents, this is what is written: printed paragraph.
How can I extract and replace only the plain text from this paragraph leaving the first 2 objects?
Thanks
Try list[0].paragraphs[0].texts and loop through the array of texts to put it together

ckeditor removes new line characters from source

Using CKEditor 4.9.2 on a textarea, which already has content, separated by new lines (\r\n). When the CKEditor instance loaded, these new lines were removed like this:
<textarea name="message" >
row 1 text text text
row 2 text text text text text text
row 3 text text
row 4 text
row 5
</textarea>
I can't convert them to <br> tags, have to work with \r\n characters.
How can I keep the \r\n characters?
You can't preserve new line character in CKEditor, it is not regular textarea. It is displaying your content by using html elements on page and it cant work like you want.
Easy solution I can suggest would bo to replace all new lines with <br>.
editor.on( 'setData', function(event) {
event.data.dataValue = event.data.dataValue.replace( 'your regexp', '<br>' );
} );
And then after getting editor data, just replace each <br> with new line character.

Applescript: cut character and paste within span tags

I've been automating a process that we do for work that involves converting word documents to html files in TextWrangler. I've got everything sorted except for one final step, which involves moving the first character of the article inside of span tags (Boss's design choice, and the website doesn't support CSS that isn't inline or I'd just use first-letter).
Anyway, the HTML looks like this:
<p style='color: #444; font-size: 1.4em; line-height: 1.8em; font-weight: bold;'>
<img style='display: block; float: right; margin-bottom: 30px; margin-left: 15px; width: 475px;' src='*****.jpg' alt='' width='950' height='713' />
<span style='color: #444; float: left; font-size: 3em;'></span>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer at rhoncus velit. Sed velit libero, venenatis non ornare ac, egestas vitae quam.</p>
The idea would just be to move the first letter following the closing span tag to inside the span tag, but I've looked around and don't really have any idea where to begin.
Edit: This might be made easier knowing in that the number of characters prior to the necessary letter in the line won't ever change. So maybe finding a way to isolate the nth character in the line and go from there?
This is a silly example, you'll want to polish it a bit:
set htmlText to "... your HTML ..."
set endSpanLength to 7
set endSpanPos to offset of "</span>" in htmlText
set firstCharPos to (endSpanPos + endSpanLength + 1)
set firstChar to character firstCharPos of htmlText
set oldEndSpan to "</span>" & linefeed & firstChar
set newEndSpan to firstChar & "</span>" & linefeed
findAndReplaceInText(htmlText, oldEndSpan, newEndSpan)
on findAndReplaceInText(theText, theSearchString, theReplacementString)
set AppleScript's text item delimiters to theSearchString
set theTextItems to every text item of theText
set AppleScript's text item delimiters to theReplacementString
set theText to theTextItems as string
set AppleScript's text item delimiters to ""
return theText
end findAndReplaceInText

Xpath with text() contains and not contains other text, case insensitive

I am trying to locate an element based on its text (I know, I know), and because there are two labels that contain some of the same words, I have to be able to locate it by some words but ensure it doesn't include other words. On top of that, it needs to be case insensitive.
Example: I am trying to locate and click the checkbox associated with the text Some Text, but not Some Text Too. The id and name, as well as the order (sometimes 'Some Text' is first, sometimes 'Some Text Too' is first) can vary from page to page depending on what else is shown, so I cannot rely on that to locate the correct checkbox.
<td style="padding-bottom: 2px"><input id="c_58" style="padding-left: 3px; background-color: rgb(255, 255, 255);" name="c_58" value="[dbo].[table].[Field]" type="checkbox"><label for="c_59" style="padding-left: 3px;">Some Text Too</label></td>
<td style="padding-bottom: 2px"><input id="c_59" style="padding-left: 3px; background-color: rgb(255, 255, 255);" name="c_59" value="[dbo].[table].[Field]" type="checkbox"><label for="c_59" style="padding-left: 3px;">Some Text</label></td>
What I have that works:
//*[*[text()[contains(translate(., 'SOME TEXT','some text'), 'some text')]]]
This finds the elements with 'Some Text', but also finds the elements with 'Some Text Too'. Since sometimes the page renders with the elements in different order, I need to be able to ensure I'm only finding 'Some Text' and not 'Some Text Too'
I have tried :
//*[*[text()[contains(translate(., 'SOME TEXT','some text'), 'some text') and not(contains(translate(., 'TOO', 'too'), 'too'))]]]
but that is not locating any element on the page.
Abdou you were correct - my scenario was more like:
label 1 : Some Text Here Too
label 2 : Some Texts Here
So the having the term "Some Text Here" couldn't find the second label because of the non-matching "Texts". I resolved this scenario by using:
//*[*[text()[contains(translate(., 'SOME','some'), 'some') and contains(translate(., 'TEXT','text'), 'text') and contains(translate(., 'HERE','here'), 'here') and not(contains(translate(., 'TOO','too'), 'too'))]]]
//*[*[text()[contains(translate(., 'SOME','some'), 'some') and contains(translate(., 'TEXT','text'), 'text') and contains(translate(., 'HERE','here'), 'here') and contains(translate(., 'TOO','too'), 'too')]]]

Resources