I'm having trouble figuring out how to modify my input text in order to get strwrap to start a new line at a given place without an extra line in between (a paragraph break).
My desired output:
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Vivamus malesuada ante eget lacus aliquam aliquet. Morbi a
nulla in tortor rutrum pulvinar.
Duis auctor condimentum magna ac commodo. Phasellus quis
elementum purus, at ornare magna. Quisque sit amet vehicula
risus. Suspendisse et et scelerisque velit:
item #1
item #2
item #3
I can use \n to get the paragraph break, which works fine, but how do I get a new line without the paragraph break, as in the list of items at the bottom? When I use \r...
txt <- "Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Vivamus malesuada ante eget lacus aliquam aliquet. Morbi a nulla
in tortor rutrum pulvinar.
\n
Duis auctor condimentum magna ac commodo. Phasellus quis elementum purus,
at ornare magna. Quisque sit amet vehicula risus. Suspendisse et
scelerisque velit:
\r
item #1
item #2
item #3"
writeLines(strwrap(txt, width=60))
... I get an unexpected result: a line break but with an extra space indent and some juxtaposition and deletion of text:
#Lorem ipsum dolor sit amet, consectetur adipiscing elit.
#Vivamus malesuada ante eget lacus aliquam aliquet. Morbi a
#nulla in tortor rutrum pulvinar.
#
#Duis auctor condimentum magna ac commodo. Phasellus quis
#elementum purus, at ornare magna. Quisque sit amet vehicula
# item #1 item #2se et scelerisque velit:
#item #3
What do I need to replace /r with in order to get a single line break, like between "velit:" and "item #1" in the desired output above? I've read the strwrap documentation and worked through its example, but haven't found the answer. Thanks for your help.
On the off-change that someone else finds this question in the future, I'll share the solution I used here. As Wiktor points out above, strwrap does not have this functionality. What I ended up doing was simply a workaround that edits the text after it goes through strwrap.
I add an arbitrary character sequence to the beginning of each line in the input which I want to start with a carriage return. Below I use "/r" for this. I send the input through strwrap, add two empty lines to the end, and then parse each line of the output, deleting "/r" and removing the empty preceding line (paragraph break). Here's the code:
txt <- "Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Vivamus malesuada ante eget lacus aliquam aliquet. Morbi a nulla
in tortor rutrum pulvinar.
\n
Duis auctor condimentum magna ac commodo. Phasellus quis elementum purus,
at ornare magna. Quisque sit amet vehicula risus. Suspendisse et
scelerisque velit:
\n\r item #1
\n\r item #2
\n\r item #3"
sink("output.txt")
lines <- append(strwrap(txt, width=100), c("",""), after = length(lines))
invisible(lapply(seq_along(lines), function(index) {
if (index != 1) { #skip first line
if (!grepl("\r ", lines[index])) {
writeLines(gsub("\r ", "", lines[index-1]))
}
}
}))
sink()
This produces a .txt file with the output text formatted as desired, where the list of items at the bottom is separated by carriage returns/newlines but paragraph breaks marked in the input with just "/n" are treated normally.
Related
How can I do page numbering in QTextEdit?
sourceTextEdit = new QTextEdit();
QString lorem="Lorem ipsum tellus, eros ipsum lectus justo malesuada massa enim"
" urna ipsum adipiscing in elementum porttitor arcu quisque "
"curabitur justo sit eros orci. Rutrum, sit nec cursus et malesuada"
" diam odio proin at tempus non.";
QTextCursor cursor = sourceTextEdit->textCursor();
cursor.insertText(lorem);
textDocument = sourceTextEdit->document();
QTextDocumentWriter writer;
writer.setFormat("odf");
writer.setFileName("report.odt");
writer.write(textDocument);
I want the report.odt file to have page numbering. How to do it?
I'm having a long string where I would like to remove consecutive words with uppercase (2+ in a row) and if a punctation follows the last uppercase word, that as well.
But at the same time I would like to keep single uppercase words and uppercase words that are part of a "mixed" word (see reprex).
I struggle to implement the consecutive word group in reprex.
string <- "Lorem ipsum DOLOR SIT AMET? consectetuer adipiscing elit. Morbi gravida libero NEC velit. Morbi scelerisque luctus velit. ETIAM-123 dui sem, fermentum vitae, SAGITTIS ID? malesuada in, quam. Proin mattis lacinia justo. Vestibulum facilisis auctor urna. Aliquam IN LOREM SIT amet leo accumsan"
#remove all consecutive UPPERCASE words including punctation (--> DOLOR SIT AMET?), but not single uppercase words (--> NEC) or "mixed" words with uppercase and digits (--> ETIAM-123)
#this doesn't work:
string %>%
stringr::str_remove_all("\\b[:upper:]+\\b")
#> [1] "Lorem ipsum ? consectetuer adipiscing elit. Morbi gravida libero velit. Morbi scelerisque luctus velit. -123 dui sem, fermentum vitae, ? malesuada in, quam. Proin mattis lacinia justo. Vestibulum facilisis auctor urna. Aliquam amet leo accumsan"
Created on 2020-05-30 by the reprex package (v0.3.0)
Any hints are appreciated :)
You may use
string <- "Lorem ipsum DOLOR SIT AMET? consectetuer adipiscing elit. Morbi gravida libero NEC velit. Morbi scelerisque luctus velit. ETIAM-123 dui sem, fermentum vitae, SAGITTIS ID? malesuada in, quam. Proin mattis lacinia justo. Vestibulum facilisis auctor urna. Aliquam IN LOREM SIT amet leo accumsan"
gsub("\\s*\\b\\p{Lu}{2,}(?:\\s+\\p{Lu}{2,})+\\b[\\p{P}\\p{S}]*", "", string, perl=TRUE)
Output:
[1] "Lorem ipsum consectetuer adipiscing elit. Morbi gravida libero NEC velit. Morbi scelerisque luctus velit. ETIAM-123 dui sem, fermentum vitae, malesuada in, quam. Proin mattis lacinia justo. Vestibulum facilisis auctor urna. Aliquam amet leo accumsan"
See the R demo and the regex demo.
Details
\s* - 0 or more whitespaces
\b - word boundary
\p{Lu}{2,} - two or more capital letters
(?:\s+\p{Lu}{2,})+ - 1 or more occurrences of 1+ whitespaces followed with 2 or more uppercase letters
\b - a word boundary
[\p{P}\p{S}]* - any 0 or more symbols or punctuation
Perhaps this?
stringr::str_remove_all(string, "([[:upper:]]+ )+[[:upper:]]+( |[:punct:])*")
#> [1] "Lorem ipsum consectetuer adipiscing elit. Morbi gravida libero NEC velit. Morbi scelerisque luctus velit. ETIAM-123 dui sem, fermentum vitae, malesuada in, quam. Proin mattis lacinia justo. Vestibulum facilisis auctor urna. Aliquam amet leo accumsan"
Created on 2020-05-30 by the reprex package (v0.3.0)
I have this line of code here in my view
I have this string #Model.inventory.overview and it has — in it.
When I try to use it so it will display the special html character it shows up as the text —
#Html.Raw(Model.inventory.overview)
and
#MvcHtmlString.Create(Model.inventory.overview)
This is what #Model.inventory.overview is
Lorem ipsum dolor sit—amet, consectetur adipiscing elit.
Mauris eget feugiat nibh. Fusce rhoncus ex et nunc fringilla, ut
fermentum tortor volutpat. Praesent mollis efficitur magna auctor
sollicitudin. Morbi pulvinar, justo ut efficitur rutrum, dui metus
varius magna, vitae molestie leo elit vel turpis. Nullam quis ipsum
nec erat maximus dictum sit amet sed ligula. Vestibulum tincidunt
dolor non—justo accumsan, eu euismod neque rutrum. Donec in
lacinia est.
I have also tried the following:
#Html.Raw(HttpUtility.HtmlDecode(#model.ContentBody));
Still not working.
#Html.Raw(Html.Encode(Model.inventory.overview)) was the solution after all.
I looked at W3C Html ASCII characters list and had a suspicion — wasn't "exactly" a ASCII character, so I found this site soon after. Glad I was helpful.
I'll try and explain this challenge... I have three divs, ordered for mobile first in a bootstrap WordPress theme.
[1] NAV
[2] CONTENT
[3] SIDEBAR
This code, works fine:
<div class="container">
<div class="row">
<div class="col-md-4"><p>NAV</p></div>
<div class="col-md-6 col-md-pull-right" ><p>MAIN CONTENT : Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam et diam et erat imperdiet scelerisque ac a leo. Etiam eu ultrices tortor, a aliquet felis. Morbi sit amet placerat mi. Nulla feugiat id sem non faucibus. Nunc tortor turpis, faucibus non nisi sit amet, bibendum tincidunt arcu. Duis id risus porttitor, porttitor massa eget, elementum ligula. Proin ullamcorper, lacus quis porta luctus, dolor enim hendrerit massa, varius gravida est ipsum quis elit. Quisque ex felis, commodo a placerat non, egestas eu turpis. Praesent sit amet lobortis tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus porta nibh non erat suscipit, et rhoncus mauris finibus. In hac habitasse platea dictumst. Quisque quam mauris, sagittis ut orci eget, tempor sollicitudin nunc. Mauris consequat ex quis dolor viverra, ac dictum eros dapibus.</p></div>
<div class="col-md-4 col-md-pull"><p>SIDEBAR</p></div>
</div>
</div>
However, on full desktop view, the sidebar displays after the main content finishes, and I need it to display directly beneath the left hand side nav - i.e.
[1 ------ NAV -------] [2------------------CONTENT -----------------]
[3 ----SIDEBAR----] [2------------CONTENT CONTINUED-----]
------------------------- [2------------CONTENT CONTINUED-----]
Instead, it displays like this.
[1 ------ NAV -------] [2------------------CONTENT -----------------]
________________[2------------CONTENT CONTINUED-----]
________________[2------------CONTENT CONTINUED-----]
[3 ----SIDEBAR----]
I don't usually do advanced CSS like this, and have been let down by my contractor, if anybody could help, and at least let me know if this is possible or not that would be much appreciated.
Also this is my first post here, so apologies if this isn't in standard format etc.
Regards
Simon
Test this JS Fiddle in Chrome or Safari on Lion and Mountain Lion.
What should be displayed is a box that scrolls. Once you start scrolling, the bar should appear, and disappear once again when you stop scrolling. In Lion and Mountain Lion, it doesn't. Anyone know of a fix to show the scrollbars?
HTML:
<div id="box">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus facilisis scelerisque aliquam. Nulla consequat justo malesuada mi imperdiet sodales. Morbi rhoncus, diam nec egestas sagittis, ipsum eros sollicitudin urna, quis ornare erat nisl scelerisque eros. Nulla eleifend posuere tempus. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum in diam commodo sapien mollis cursus. Integer vitae lacus augue. Proin a velit augue. Quisque at mi augue, a sagittis metus. Aenean id bibendum nunc. Nulla quis eros odio. Sed non leo diam, et sollicitudin leo. Cras ut nibh diam, a mattis felis. Proin lectus massa, fermentum sit amet aliquet id, posuere a dui. Morbi vulputate elit elit. Proin in mi turpis.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus facilisis scelerisque aliquam. Nulla consequat justo malesuada mi imperdiet sodales. Morbi rhoncus, diam nec egestas sagittis, ipsum eros sollicitudin urna, quis ornare erat nisl scelerisque eros. Nulla eleifend posuere tempus. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum in diam commodo sapien mollis cursus. Integer vitae lacus augue. Proin a velit augue. Quisque at mi augue, a sagittis metus. Aenean id bibendum nunc. Nulla quis eros odio. Sed non leo diam, et sollicitudin leo. Cras ut nibh diam, a mattis felis. Proin lectus massa, fermentum sit amet aliquet id, posuere a dui. Morbi vulputate elit elit. Proin in mi turpis.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus facilisis scelerisque aliquam. Nulla consequat justo malesuada mi imperdiet sodales. Morbi rhoncus, diam nec egestas sagittis, ipsum eros sollicitudin urna, quis ornare erat nisl scelerisque eros. Nulla eleifend posuere tempus. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum in diam commodo sapien mollis cursus. Integer vitae lacus augue. Proin a velit augue. Quisque at mi augue, a sagittis metus. Aenean id bibendum nunc. Nulla quis eros odio. Sed non leo diam, et sollicitudin leo. Cras ut nibh diam, a mattis felis. Proin lectus massa, fermentum sit amet aliquet id, posuere a dui. Morbi vulputate elit elit. Proin in mi turpis.</p>
</div>
CSS:
#box {
height: 300px;
overflow: auto;
margin: 10px;
}
This problem is "real" in that previous posters have shown a real difference in appearance in Apple's Mountain Lion operating system.
But the scroll behavior still works, in other examples I see on the internet and on the "Test this" link of the opening post.
The problem is that the default user setup in Mountain Lion causes the scroll bars to be hidden so the user does not see them. And the default "natural" scroll wheel or track pad (Magic Pad) direction is opposite of older systems or PC's. These two aspects lead to confusion.
With the default settings, the scrolling region will scroll if the mouse arrow is over the block (even though the scroll bars are not present), and will appear if one moves in the proper direction. The default "natural" (as Apple calls it) direction is that the scroll wheel or the track pad moves the object itself in the "natural" direction (as opposed to the window moving on the object). There is a setting on the Mac to reverse this, but that will make the Mac's direction opposite of the direction on Apple's touch tablets.
The real problem is the confusion to the user caused by the hiding of the scroll bars, so they don't realize that they CAN move the area with a scroll wheel if mouse cursor is over. And furthermore the user must have a track pad or scroll wheel for it to even work, but that is needed for the most part to even navigate the Mountain Lion operating system itself.
The user can change the Mac's setting in the Personal General setting to "Show scroll bars: Always". But that is of little help to the CSS or website developer.
I suggest we complain to Apple about this. Main alternative is just not use the feature of scrollable area in a window of a website.
Here is a jQuery plugIn that does what you need.
http://naeka.github.com/jquery-scrollbar/
you'll need
<script type="text/javascript" src="jquery-1.6.2.min.js"></script>
<script type="text/javascript" src="jquery-ui-1.8.16.custom.min.js"></script>
<script type="text/javascript" src="jquery.scrollbar.min.js"></script>
<script type="text/javascript" src="demo.js"></script>
Use classes <div id="page"> <div class="scrollBox"><div id="scroll1"><p class="left">
Example: http://jsfiddle.net/pullapooh/3aGDK/
Seems to work for me on linux mint, how about trying:
overflow:scroll;