Prevent line break between short words - html

How to make automatically prevention of line breaks between short words consisting of less than 4 characters?
For example this piece of
text is
formatted not ideally
For example this piece of text
is formatted ideally

I think what you want is this: word-break:keep-all; it prevents words from breaking between letters.

Related

How to make ClosedXML to not break words?

I am constructing an Excel document using ClosedXML.
I fill the cells with text. When the text is long, it breaks it into several lines in the middle of the word.
How can I make it break into lines only between the words, only on the white spaces?
For example: The word Establishment is broken into 2 and the column width is not changed. I don't want it to break words in two but only in between words and if necessary to increase column width.
Try this code (c#):
ws.Cells().Style.Alignment.SetWrapText(true);
where ws is the worksheet.

HTML tag or technique like <wbr> but for a line break?

I often find I wish to control how a sentence breaks/wraps, e.g.:
Hello there Mr Nemesis X, welcome to the interwebs!
If the viewport is narrow, I would like it to wrap after the comma, so the two logical lines are together:
i.e. GOOD: Only if the viewport is too narrow to show the whole screen
Hello there Mr Nemesis X, |<----- viewport width
welcome to the interwebs!
BAD:
Hello there Mr Nemesis X, welcome to the |<----- viewport width
interwebs!
At the moment I place the two sentences in two <span>s, and use flex to ensure they wrap together, what a mission for something I often do. I learnt about <wbr>, which sounds like it could work if I replace all the spaces with say , but its not what it was defined for. Theres <br>, but that always breaks. So I am looking for something like a "line break", say <lbr> (doesnt exist), which if the line needs to wrap, it says hey, heres a good place to break the line.
You maybe can use \n after the coma.
The way your code is breaking right now is accurate to a break. The <wbr> is used to break a long word up hence why you would need to add that HTML entity to break up your lines.
For what I think you want, going for that specific design aesthetic, breaking at a comma, you would need to pre-process your strings before they get written, and as the view-port updates as to add breaks where you deem necessary.
You can use a <br> html tag to break a line!
Inserting the line break tag after the comma.
Or you can use the /n after the comma.

Prevent numbers from breaking on 1000 separator

There's a table in a HTML file. The word-break CSS attribute indicates that long words have to break inside that table. I want only long texts (and not numbers) to break. I have some numbers, which have 1000 separators (every three digits, there's a comma). Those numbers break, too.
Is there any way to prevent those numbers from breaking ?
Use <span style="white-space: nowrap;">Content</span>. Alternatively, wrap your numbers inside a <nobr>-tag, note that this tag is not a standard though!

inline code as a "word" in sublime text

Is it possible to make sublime text consider all code within backticks to be a single word? I am including inline code in a markdown document, and it keeps breaking when I wrap a paragraph and inserts a newline in the midst of a code chunk. For example
This is the text I am writing and `r this_is_some_code`
If the line is long, and a newline falls between `r and the final backtick, then the code doesn't work correctly. Is it possible to make that whole region be considered a single word? then it would not wrap at the ruler at all.

Best practices: displaying text that was input via multi-line text box

I have a multi-line text box. When users simply type away, the text box wraps the text, and it's saved as a single line. It's also possible that users may enter line breaks, for example when entering a "bulleted" lists like:
Here are some suggestions:
- fix this
- remove that
- and another thing
Now, the problem occurs when I try to display the value of this field. In order to preserve the formatting, I currently wrap the presentation in <pre> - this works to preserve user-supplied breaks, but when there's a lot of text saved as a single line, it displays the whole text block as single line, resulting in horizontal scrolling being needed to see everything.
Is there a graceful way to handle both of these cases?
The easiest way of dealing with this is turning all line breaks \n into <br> line breaks. In PHP for example, this is done using the nl2br() function.
If you want something a bit more fancy - like the list you quote getting converted into an actual HTML <ul> for example - you could consider a simple "language" like Markdown that SO uses. It comes with natural, simple rules like
# Heading 1
## Heading 2
### Heading 3
* Unordered List item
* Unordered List item
1. Numbered List item
2. Numbered List item
etc....
You can use the php function nl2br() It transforms line breaks into elements
Convert newline characters to <br /> tags explicitly, and let the browser word-wrap the text normally. That preserves the breaks the visitor entered, without harming other paragraphs.
You could replace line breaks with HTML line breaks.
Replace "\r\n" or "\n" (depending on the browser and platform, check first for longer one) with <br/>.
I would normally replace all CR/LF with LF, and then replace all LF with <br />. You can then render this text inside any HTML container you want and let it flow naturally.