In emacs, you can use meta-q "fill-paragraph" and in vim you can do gq - reformat paragraph (gggqG to fill the entire buffer)
Is there a similar key binding in sublime text?
Example:
Before fill-paragraph:
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam
After fill-paragraph:
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad
minim veniam
New Answer
OK, so I misunderstood your original question - as I now understand it, MetaQ-"fill-paragraph" rearranges paragraphs into lines of approximately-equal lengths. There isn't a function that matches this exactly in Sublime, but you can (re)wrap lines quite easily. You can set the ruler in your Preferences.sublime-settings file, using the "wrap_width" setting. Then, using AltQ on Windows/Linux, or ⌘AltQ on OS X, you can wrap selected text to that width (it defaults to 78 characters if "wrap_width" is set to 0). If you want to wrap to other (pre-selected) widths, go to Edit -> Wrap and there are a number of other options. To set a preferred width outside of what is in your preferences, open Preferences -> Key Bindings - User and add the following:
[
// wrap lines at 25 characters
{ "keys": ["ctrl+alt+shift+w"], "command": "wrap_lines", "args": {"width": 25} }
]
You can obviously change the 25 to whatever value suits you. If you have no custom key bindings so far, copy and paste the entire contents above into the file. If you already have some key bindings, omit the outer square brackets, and remember to place a comma at the end of the line if it's not the final entry in the file. Good luck!
Related
I'm trying to achieve a censored text look in SwiftUI. I've been placing a text and it's copy inside a ZStack and added a .background(Color.black) modifier to the front one. This works fine with single line texts. However, it doesn't look so good with multiline texts, as it results in a single black rectangle. Any ideas on how to achieve the look below with rather long, multiline texts?
For the sake of completeness, here's the simple code:
HStack{
Spacer()
.frame(width: 50)
ZStack {
Text("Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et")
.font(.system(.title2, design: .serif))
.foregroundColor(.blue)
.multilineTextAlignment(.trailing)
Text("Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et")
.font(.system(.title2, design: .serif))
.multilineTextAlignment(.trailing)
.background(Color.black)
}
}
As always, any help would be greatly appreciated!
If you’re targeting iOS 14, you could use the redacted(reason:) view modifier, which they added for widgets but works everywhere:
Text("View 0")
.redacted(reason: .placeholder)
I'd need to add the Chapter title in the page's heading of PDF files generated with Asciidoctor-toPDF.
Here is the set of Properties I'm using at the beginning of my doc:
= Book title
:notitle:
:toc: left
:toclevels: 8
:sectnums:
:sectnumlevels: 8
:source-highlighter: coderay
:icons: font
:chapter-label:
:header_recto_content_center: '{section-title}'
Is there any property I am missing or which conflicts with the Header generation?
A few theme-related attributes exist. But header is not one of them unfortunately.
So to style the header of a PDF one must resort to a custom style in YAML format.
Style
For this example the file is named style.yml and placed in our working directory.
extends: default #1
header:
height: 15mm #2
recto: &header #3
center-content: '-- {section-or-chapter-title} --' #4
verso: *header #5
Extends the default asciidoctor-pdf theme with your customized code.
Define the height of the header or the content will not show; also explained here.
Create a YAML anchor to the whole content of recto.
The use of {section-or-chapter-title} is explained and shown at the end of the post.
Reference the content from &header. In plain make verso behave the same as recto.
Document
The content of the adoc file is as shown below. The file is aptly named book.adoc and placed in the same directory as style.yml.
= Book title
:notitle:
:toc: left
:toclevels: 8
:sectnums:
:sectnumlevels: 8
:source-highlighter: coderay
:icons: font
:chapter-label:
== Chapter One
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy
eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam
voluptua.
== Chapter Two
=== Section One
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy
eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam
voluptua.
Conversion
PDF conversion is done using the pdf-stylesdir and pdf-style attributes.
asciidoctor-pdf -a pdf-stylesdir=. -a pdf-style=style.yml -d book book.adoc
Result
Chapter one looks then as shown in the screenshot. As there is no section header the chapter is used to populate the header.
Chapter two having both a chapter and a section defined is displaying the section title in the header.
This question already has answers here:
RegEx match open tags except XHTML self-contained tags
(35 answers)
Closed 6 years ago.
This post was edited and submitted for review 15 days ago.
I want to remove every html tag with awk from this regex: /[<.*.>]/ if said regex is found in any field. I've been trying to make it work with sub or substr, I am unable to find the correct logic for this.
Input text:
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation<br/><div style="margin-top:6px">< b>veniam:< /b>< /div> <br/><div style="margin-top:6px">< b>Confort:< /b></div>Comenzi volan; Cruise-control; Servodirectie; <br/>
Output:
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitationveniam: Confort:Comenzi volan; Cruise-control; Servodirectie;
If you're not really parsing HTML but instead just want to remove everything between each <...> pair in a text file, then that'd be this with GNU awk for multi-char RS:
$ awk -v RS='<[^>]+>' -v ORS= '1' file
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitationveniam: Confort:Comenzi volan; Cruise-control; Servodirectie;
I'm using cheerio (cheeriojs) to scrape content from a site which has the following HTML layout.
<div class="foo"></div>
<p></p>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
<br><br>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
<br><br>
</p>
I'm able to reach this content using the each function in the docs (here) by traversing the DOM looking for ".foo" class like so.
$('.foo').each(function(i, el){
//Do something...
$(this).next().next().text()
}
From here I'm able to simply convert this content to a string, and retrieve as I wish, however the text comes back in one unformatted long string. (i.e. a long essay of paragraphs without spacing between the respective paragraphs). Is there a way, trick I could retrieve the content whilst keeping the formatted content?
I've attempted the following;
`var fruits = [];
$('.foo').each(function(i, el){
fruits[i] = $(this).next().next().text();
}`
As a way to get the current tag and push it to an array, however this isn't much different from my earlier code. I'm assuming this would be possible if the <br> tags had some id or classes, however they don't. Is there a way I can directly target these (<br>) as a way to get the text, and retrieve it in proper format (i.e. with spacing between paragraphs). At this junction, I must ask those who are more familiar and experience with cheerio if what I'm trying to do in this particular cash is even feasible with cheerio? I'm open to pursuing other route, and would welcome recommendation for modules/libraries that could help make this an easier task.
To recap: I want to retrieve all text between the second <p> tags, maintaining format and spacing as seen on rendered HTML.
Thanks in advance.
If you ask for .text() it will strip formatting. If you ask for .html() it'll return all the content, preserving all the tags.
So change this:
fruits[i] = $(this).next().next().text();
To this:
fruits[i] = $(this).next().next().html();
I am trying to write a script that gets input from a user and returns the input in a formatted area. I have been using the string range function however it obviously cuts the the input at the range that I give. Is there any way to do a look around at the specified range to find the next space character and cut the input at that location?
For example, if I have the input of:
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris
My current string range function formats the input with \r\n as such:
Lorem ipsum dolor sit amet, consectetur a
dipisicing elit, sed do eiusmod tempor in
cididunt ut labore et dolore magna aliqua
. Ut enim ad minim veniam, quis nostrud e
xercitation ullamco laboris
As you can see on line 1 the adipisicing line 2 incididunt words have been cut off. I am looking for a way to look for the closest space to that location. So for line 1 it would have been before the a on line 2 it would have been before the i. …In some cases it may be after the word.
Is that clear what I am looking for? Any assistance would be great!
The string range operation is pretty stupid; it doesn't know anything about the string it is splitting other than that it contains characters. To get smarter splitting, your best bet is probably an intelligently chosen regular expression:
set s "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod\
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis\
nostrud exercitation ullamco laboris."
# Up to 40 characters, from word-start, to word-start or end-of-string
set RE {\m.{1,40}(?:\m|\Z)}
# Extract the split-up list of "lines" and print them as lines
puts [join [regexp -all -inline $RE $s] "\n"]
This produces this output for me:
Lorem ipsum dolor sit amet, consectetur
adipisicing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna
aliqua. Ut enim ad minim veniam, quis
nostrud exercitation ullamco laboris.
Implementing full justification by inserting spaces is left as an exercise for the reader (because it's really quite a lot harder than greedy line splitting!)
The textutil::adjust module in tcllib is what you need:
package require textutil::adjust
set line "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris"
set formatted [textutil::adjust::adjust $line -length 41]
puts $formatted
Lorem ipsum dolor sit amet, consectetur
adipisicing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna
aliqua. Ut enim ad minim veniam, quis
nostrud exercitation ullamco laboris