[TW5] tip: preserving linebreaks

140 views
Skip to first unread message

Rustem

unread,
Aug 2, 2017, 8:57:47 PM8/2/17
to TiddlyWiki
This comes up now and again as a major gripe with TW5 - people want their linebreaks to stay.
I discovered this recently, and have not encountered any downside so far: use (new in HTML5) <article> tag, and style it as

article {
    white
-space: pre-wrap;
}

The text inside the tag will have linebreaks as you entered them. All other formatting inside <article>…</article> works as usual, as far as I can see.

Note, this won't let you have linebreaks inside list bullets and such.

--R.

JWHoneycutt

unread,
Aug 3, 2017, 10:06:25 PM8/3/17
to TiddlyWiki

Hi Rustem,

I tried to use your solution, since I spend way too much time adding formatting to imported text. I don't have it working yet. This is what I tried:


I copied your text into the middle of a tiddler with lots of text

article {
    white
-space: pre-wrap;

The stuff I want to preserve linebreaks on is here

}


and I moved the last curly bracket to the end of the text I would like to handle differently

Before someone says this - I know I can use the line feed - triple double quotes """ at the beginning and end of preserved linebreaks, but I will have a series of them throughout a text and when I delete one (because I paraphrase the text as I study it), they get unmatched and I spend too much time chasing formatting.

I also tried changing what you gave to:

<$article>
white-space: pre-wrap;
The stuff I want to preserve linebreaks on is here
</$article>

I need just a little more direction...

Thanks

JWHoneycutt

Eric Shulman

unread,
Aug 3, 2017, 11:51:37 PM8/3/17
to TiddlyWiki
On Thursday, August 3, 2017 at 7:06:25 PM UTC-7, JWHoneycutt wrote:
I copied your text into the middle of a tiddler with lots of text
article {
    white
-space: pre-wrap;

The stuff I want to preserve linebreaks on is here

}

and I moved the last curly bracket to the end of the text I would like to handle differently

That's not how it works.

1) put the CSS into a stylesheet tiddler, e.g., [[MyStyles]], tagged with $:/tags/Stylesheet, containing
article { white-space: pre-wrap; }

2) In your content tiddler, wrap your text with:
<article>
  text goes here
</article>

note: "article" is a new HTML entity... thus, it is NOT a TW widget, and does not use the "$" prefix

let me know how it goes...

enjoy
-e
Eric Shulman
TiddlyTools.com: "Small Tools for Big Ideas" (tm)
InsideTiddlyWiki: The Missing Manuals


Mat

unread,
Aug 4, 2017, 6:17:30 PM8/4/17
to TiddlyWiki
JWHoneycutt - thank you.

Is there a particular reason to use <article> instead of <div>?

<:-)
Reply all
Reply to author
Forward
0 new messages