How can I output text with blank lines in Raphael - raphael

I want to place a text in Raphael which contains also blank lines. If there is only one blank line, i can replace "\n\n" by "\n \n" and the blank lines show up.
But if there are multiple blank lines, it does not work.
for example
paper.text(100,100, "this\n \n \nblank\nline")
does not yield two blank lines between "this" and "blank"

Related

BBEdit GREP - To break line if there is no blank line above

I am trying to organise a bunch of documents that has
" [ " brackets.
I have achieved to organise them to [ to come on as new line all the time
however I need them to have 1 line of blank space on top every time.
Conditionally if there is blank line already, no need to be done, just one line.

Split mixed upper and lowercase in the same word into two lines

I have a string in cells that is lacking new lines.
It looks like this:
Text Text TextText Text Text T5df Tdfcv TextNeu
In other words:
If there is a change from Lowercase to Uppercase within a word, this is where a new line should be inserted as \n.
So the example would convert to
Text Text Text
Text Text Text T5df Tdfcv Text
Neu
Resp.:
Text Text Text\nText Text Text T5df Tdfcv Text\nNeu
I found
String[] r = s.split("(?=\\p{Lu})");
I tried REGAUS(F2;"(?=\\p{Upper})";"\n";"g") yet I get a 502, as something is wrong with the regex.
Which formula do I need for calc to do this?
With english formula names, the following formula will do the trick:
=REGEX(A1;"([:lower:])([:upper:])";"$1"&CHAR(10)&"$2";"g")
Same on multiple lines for sake of readability:
=REGEX(
A1;
"([:lower:])([:upper:])";
"$1" & CHAR(10) & "$2";
"g"
)
It matches a lower-case letter followed by an upper-case letter, and inserts a newline using the CHAR() function.
You'll have to adapt the line heigth manually, otherwise you will see only "Neu" (the last line).
For localised formula names (german), it would be:
=REGAUS(A1;"([:lower:])([:upper:])";"$1"&ZEICHEN(10)&"$2";"g")
I would have expected that inserting "\n" should work, too, but i did'nt manage got get it working, thus the recourse to CHAR(10).

google doc script to capitalize sentences

i am writing the google doc script below to capitalize the sentences in a document.
function cap6() {
var body = DocumentApp.getActiveDocument().getBody();
var text = body.editAsText();
var str1 = text.getText();
Logger.log(str1);
// define function "replacement" to change the matched pattern to uppercase
function replacement(match) { return match.toUpperCase(); }
// period followed by any number of blank spaces (1,2,3, etc.)
var reg = /\.(\s*\s)[a-z]/g;
// capitalize sentence
var str2 = str1.replace(reg, replacement);
Logger.log(str2);
// replace string str1 by string str2
text.replaceText(str1, str2);
}
the code almost worked in the sense that the correct result is shown in the log file as follows:
[15-10-22 22:37:03:562 EDT] capitalize sentences. this is one example with ONE blank space after the period. here is another example with TWO blank spaces after the period. this is yet another example with MORE THAN THREE blank spaces.
[15-10-22 22:37:03:562 EDT] capitalize sentences. This is one example with ONE blank space after the period. Here is another example with TWO blank spaces after the period. This is yet another example with MORE THAN THREE blank spaces.
the 1st line above is the original paragraph without capitalized sentences; the 2nd line below is the transformed paragraph with capitalized sentences, regardless of the number of blank spaces after the period.
the problem was that i could not replace the original paragraph in the google doc with the transformed paragraph using the code:
// replace string str1 by string str2
text.replaceText(str1, str2);
i suspect that i made an error in the arguments of the method "replaceText".
any help to point out my errors would be appreciated. thank you.
in a flash of inspiration, i ALMOST solved the problem using the following code:
text.replaceText(".*", str2);
my inspiration actually came from reading about the method "replaceText".
the above code worked when i had only ONE paragraph in the google doc.
but when i had two paragraphs in the google doc, then the code gave a duplicate of the document, i.e., a 2nd exact copy of the two paragraphs just below the original two paragraphs (with correct capitalization of the sentences, including the beginning of the 2nd paragraph, but not the beginning of the 1st paragraph).
when i had 3 paragraphs, then i had 3 copies of these 3 paragraphs, such as shown below:
capitalize sentences. this is one example with ONE blank space after the period. here is another example with TWO blank spaces after the period. this is yet another example with MORE THAN THREE blank spaces.
capitalize sentences. this is one example with ONE blank space after the period. here is another example with TWO blank spaces after the period. this is yet another example with MORE THAN THREE blank spaces.
capitalize sentences. this is one example with ONE blank space after the period. here is another example with TWO blank spaces after the period. this is yet another example with MORE THAN THREE blank spaces.
then after running the script, i got 3 copies of these 3 paragraphs (with correct capitalization of the sentences, including the beginning of the 2nd and 3rd paragraphs), as shown below:
capitalize sentences. This is one example with ONE blank space after the period. Here is another example with TWO blank spaces after the period. This is yet another example with MORE THAN THREE blank spaces.
Capitalize sentences. This is one example with ONE blank space after the period. Here is another example with TWO blank spaces after the period. This is yet another example with MORE THAN THREE blank spaces.
Capitalize sentences. This is one example with ONE blank space after the period. Here is another example with TWO blank spaces after the period. This is yet another example with MORE THAN THREE blank spaces.
capitalize sentences. This is one example with ONE blank space after the period. Here is another example with TWO blank spaces after the period. This is yet another example with MORE THAN THREE blank spaces.
Capitalize sentences. This is one example with ONE blank space after the period. Here is another example with TWO blank spaces after the period. This is yet another example with MORE THAN THREE blank spaces.
Capitalize sentences. This is one example with ONE blank space after the period. Here is another example with TWO blank spaces after the period. This is yet another example with MORE THAN THREE blank spaces.
capitalize sentences. This is one example with ONE blank space after the period. Here is another example with TWO blank spaces after the period. This is yet another example with MORE THAN THREE blank spaces.
Capitalize sentences. This is one example with ONE blank space after the period. Here is another example with TWO blank spaces after the period. This is yet another example with MORE THAN THREE blank spaces.
Capitalize sentences. This is one example with ONE blank space after the period. Here is another example with TWO blank spaces after the period. This is yet another example with MORE THAN THREE blank spaces.
so there is still something wrong in the new code... which almost worked if i could get rid of the extra copies of the document.
returning to the original code
text.replaceText(str1, str2);
i suspect that there was something wrong with using the variable "str1" in the 1st argument of method "replaceText". it is hoped some experts could explain the error in my original code.
i combine the above answers from Washington Guedes and from Robin Gertenbach here that led to the following working script:
function cap6() {
var body = DocumentApp.getActiveDocument().getBody();
var text = body.editAsText();
// define variable str1
var str1 = text.getText();
// define function "replacement" to change the matched pattern to uppercase
function replacement(match) { return match.toUpperCase(); }
// period followed by any number of blank spaces (1,2,3, etc.)
// var reg = /\.(\s*\s)[a-z]/g;
// or replace \s*\s by \s+
var reg = /\.(\s+)[a-z]/g;
// capitalize sentence
var str2 = str1.replace(reg, replacement);
// replace the entire text by string str2
text.setText(str2);
}
on the other hand, the above script would wipe out all existing formatting such as links, boldface, italics, underline in a google doc.
so my next question would be how could i modify the script so it would run on a selected (highlighted) paragraph instead of the whole google doc to avoid the script to wipe out existing formatting.
The duplication issue that you have is coming from the line breaks which are not matched by the dot operator in RE2 (Googles Regular expression engine) if you don't include the s flag.
You therefore have a number of matches equal to the number of paragraphs.
You don't need to use a resource intensive replace method though, you can just use text.setText(str2); instead of text.replaceText(".*", str2);
to change the script so that it would run only on the selected text (e.g., a paragraph) to avoid wiping out the existing formatting in other paragraphs in a google doc, i was inspired by the code i found in Class Range.
i also improve on the regular expression in the variable "reg" so that the beginning of a line or paragraph would also be capitalized:
var reg = /(^|\.)(\s*)[a-z]/g;
below is a script that would capitalize the sentences in a selected text (just run the script cap7, which calls the script cap8):
function cap7() {
// script to capitalize the beginning of a paragraph and the sentences within.
// highlight a number of paragraphs, then run cap7, which calls cap8.
// get the selected text inside a google doc
var selection = DocumentApp.getActiveDocument().getSelection();
if (selection) {
var elements = selection.getRangeElements();
for (var i = 0; i < elements.length; i++) {
var element = elements[i];
// Only modify elements that can be edited as text; skip images and other non-text elements.
if (element.getElement().editAsText) {
var text = element.getElement().editAsText();
// capitalize the sentences inside the selected text
cap8(text);
}
}
}
}
function cap8(text) {
// define variable str1
var str1 = text.getText();
// Logger.log(str1);
// define function "replacement" to change the matched pattern to uppercase
function replacement(match) { return match.toUpperCase(); }
// beginning of a line or period, followed by zero or more blank spaces
var reg = /(^|\.)(\s*)[a-z]/g;
// capitalize sentence; replace regular expression "reg" by the output of function "replacement"
var str2 = str1.replace(reg, replacement);
// Logger.log(str2);
// replace whole text by str2
text.setText(str2); // WORKING
return text;
}
see also my question in the post google doc script, capitalize sentences without removing other attributes.

Qt: QLineEdit , how to let the text in two lines instead of a long one

suppose I have a line edit and my window is in fixed size , and I wanted the line edit to display a text , but since the width is not big to see all the text I must drag my mouse left or right to read it all ,
how can I change it so instead of showing the text line this:
End of the width of the line edit:
text text text text text text text text text text text
so look at the italics part , to see the text " the italics one " i must drag the mouse right so I can see it and if I want to get back to the start I drag it to the left.
I want: read it or show it line this:
text text text text text text "end of the line here"
"start of the new line:"text text

how to a match text given an input value and add indented lines

I have the following sample text file. I specify a input value that I want to search for, in this case the word "car", then I would like to add the matched line "this is a car" and all the lines below it that is indented with two spaces, to a list.
How do I search the text for ("this is a" + my input value)
How would I got about adding only the indented lines after making a match to the list?
This is a sample of what the text file would look like:
this is a car
it is red
it has big wheels
manual transmission
this is a dog
it is brown
and long fur
I am thinking it would look something like this in pseudo-code
def action(self, filename, input):
with open(filename, 'rb') as f:
text = f.readlines()
output = []
for lines in text:
if ("this is a" + input) in lines:
i = lines.strip()
output.append(i)
goto next line
while there is a single space
i = lines.strip()
output.append(i)
Then if I do a print of output I should see the following:
this is a car
it is red
it has big wheels
manual transmission
When you go through for lines in text, have a flag that says whether you're currently looking for the starting text (this is a car) or for the following text (lines beginning with spaces).
In pseudocode:
looking_for_indents = False
for line in text:
if ("this is a " + input) in line:
print line
looking_for_indents = True
continue
if looking_for_indents:
if line.startswith(' '):
print line
else
# that's all of them, stop looking
looking_for_indents = False
Side comments:
input is a builtin function in Python; naming your argument 'input' is bad practise
lines.strip() gets rid of start/end spaces, it can't help if you're looking for them
readlines() returns a list of strings, for iterates string by string. for lines in text implies lines is plural but it's not.