Rendering hard line breaks from any field

81 views
Skip to first unread message

Reece Shaw

unread,
Apr 24, 2019, 10:09:28 PM4/24/19
to TiddlyWiki
Hey all,

I'm working on a macro currently that displays the contents of a field as markdown text that "Picks up" hard line breaks.

From the documentation on hard line breaks, the site shows that you can enclose text with triple quotes for it to capture:

"""
Some
short lines
together
"""


This renders as "Some short lines together" as expected. In my case I'm utilizing an $edit-text widget to edit a field that is NOT the text field so that the data can all be retained in a single tiddler. From the $edit-text my "skill" field can be edited with hard line breaks but I still have to wrap the selection with triple quotes to get it to render as I want. 

Is there any way to pass the need for the triple quotes into a macro? I would like to not have to perform this manual edit when attempting to get line breaks as I expect. Ideally I would like to call <<con-display "skill">> and have the text render with the hard line breaks from any field, instead of quoting out every field. Is this possible?

I've tried a few variations on placing the quotes outside/inside the wikify and I have yet to figure it out.

\define con-display-block($field$)
<$wikify type="text/x-markdown" output="html" mode="block">

{{!!$field$}}

</$wikify>
\end



Thanks,

-Reece

Jeremy Ruston

unread,
Apr 26, 2019, 1:08:38 PM4/26/19
to tiddl...@googlegroups.com
Hi Reece

I'm working on a macro currently that displays the contents of a field as markdown text that "Picks up" hard line breaks.

From the documentation on hard line breaks, the site shows that you can enclose text with triple quotes for it to capture:

"""
Some
short lines
together
"""



The hard line break support in TW5 is implemented as a parser rule that replaces line breaks with <br> tags. So the above example is exactly equivalent to typing:

Some<br/>
short lines<br/>
together

This renders as "Some short lines together" as expected. In my case I'm utilizing an $edit-text widget to edit a field that is NOT the text field so that the data can all be retained in a single tiddler. From the $edit-text my "skill" field can be edited with hard line breaks but I still have to wrap the selection with triple quotes to get it to render as I want. 

Is there any way to pass the need for the triple quotes into a macro? I would like to not have to perform this manual edit when attempting to get line breaks as I expect. Ideally I would like to call <<con-display "skill">> and have the text render with the hard line breaks from any field, instead of quoting out every field. Is this possible?

I've tried a few variations on placing the quotes outside/inside the wikify and I have yet to figure it out.

Here’s one way of approaching it. Given a toddler “New Tiddler” containing the text above (without the triple double quotes):

<$wikify name="output" output="html" text={{{ [[New Tiddler]get[text]addprefix["""]addsuffix["""]] }}}>
<<output>>
</$wikify>

The disadvantage of this approach is that by using the wikify widget we “flatten” the contents of the field to plain HTML. So you won’t be able to include TW features that don’t exist in HTML (eg reveal or list widgets).

Best wishes

Jeremy.



\define con-display-block($field$)
<$wikify type="text/x-markdown" output="html" mode="block">

{{!!$field$}}

</$wikify>
\end



Thanks,

-Reece

--
You received this message because you are subscribed to the Google Groups "TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+...@googlegroups.com.
To post to this group, send email to tiddl...@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywiki.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/b8574cab-6469-417c-976a-3a09e2279162%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reece Shaw

unread,
Apr 26, 2019, 1:59:49 PM4/26/19
to tiddl...@googlegroups.com
Ah! That makes sense. I'll continue to pass with the triple quotations in the field. Thanks Jeremy! 

-Reece

You received this message because you are subscribed to a topic in the Google Groups "TiddlyWiki" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/tiddlywiki/jTFOIlN8A-E/unsubscribe.
To unsubscribe from this group and all its topics, send an email to tiddlywiki+...@googlegroups.com.

To post to this group, send email to tiddl...@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywiki.
Reply all
Reply to author
Forward
0 new messages