1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-12-24 17:10:29 +00:00

Use double linebreaks to indicate content of a widget or html element should be parsed in block mode

Fixes #82.

The old behaviour was to parse the content of a widget or html element
in block mode if the opening tag was followed by a line break. The new
behaviour requires two line breaks.

This makes it possible to include linebreaks more liberally within
wikitext, although care must still be taken to only use double line
breaks when the block mode behaviour is desired.

The code change here is very simple, just a single line change in
html.js. Most of the other changes are to convert various single line
breaks into double line breaks.
This commit is contained in:
Jermolene 2014-02-20 21:42:31 +00:00
parent 8f9d88f25b
commit 06a0d21734
17 changed files with 99 additions and 15 deletions

View File

@ -47,8 +47,8 @@ exports.parse = function() {
this.nextTag = null;
// Advance the parser position to past the tag
this.parser.pos = tag.end;
// Check for a following linebreak
var hasLineBreak = !tag.isSelfClosing && !!this.parseTokenRegExp(this.parser.source,this.parser.pos,/(\r?\n)/g);
// Check for an immediately following double linebreak
var hasLineBreak = !tag.isSelfClosing && !!this.parseTokenRegExp(this.parser.source,this.parser.pos,/(\r?\n\r?\n)/g);
// Set whether we're in block mode
tag.isBlock = this.is.block || hasLineBreak;
// Parse the body if we need to

View File

@ -3,6 +3,8 @@ title: $:/core/ui/AlertTemplate
<div class="tw-alert"><div class="tw-alert-toolbar"><$button message="tw-delete-tiddler" class="btn-invisible">{{$:/core/images/delete-button}}</$button></div><div class="tw-alert-subtitle"><$view field="component"/> - <$view field="modified" format="date" template="0hh:0mm:0ss DD MM YYYY"/> <$reveal type="nomatch" state="!!count" text=""><span class="tw-alert-highlight">(count: <$view field="count"/>)</span></$reveal></div>
<div class="tw-alert-body">
<$transclude/>
</div>
</div>

View File

@ -3,13 +3,19 @@ tags: $:/tags/ControlPanel/Appearance
caption: {{$:/language/ControlPanel/Appearance/Palette/Caption}}
\define lingo-base() $:/language/ControlPanel/Appearance/Palette/
{{$:/snippets/paletteswitcher}}
<$reveal type="nomatch" state="$:/state/ShowPaletteEditor" text="yes">
<$button set="$:/state/ShowPaletteEditor" setTo="yes"><<lingo ShowEditor/Caption>></$button>
</$reveal>
<$reveal type="match" state="$:/state/ShowPaletteEditor" text="yes">
<$button set="$:/state/ShowPaletteEditor" setTo="no"><<lingo HideEditor/Caption>></$button>
{{$:/snippets/paletteeditor}}
</$reveal>
<$reveal type="match" state="$:/state/ShowPaletteEditor" text="yes">
<$button set="$:/state/ShowPaletteEditor" setTo="no"><<lingo HideEditor/Caption>></$button>
{{$:/snippets/paletteeditor}}
</$reveal>

View File

@ -3,17 +3,28 @@ tags: $:/tags/EditTemplate
\define lingo-base() $:/language/EditTemplate/
<$reveal state="$:/ShowEditPreview" type="match" text="yes">
<em class="tw-edit"><<lingo Body/Hint>></em> <$button type="set" set="$:/ShowEditPreview" setTo="no"><<lingo Body/Preview/Button/Hide>></$button>
<div class="tw-tiddler-preview">
<div class="tw-tiddler-preview-preview">
<$transclude />
</div>
<div class="tw-tiddler-preview-edit">
<$edit field="text" class="tw-edit-texteditor" placeholder={{$:/language/EditTemplate/Body/Placeholder}}/>
</div>
</div>
</$reveal>
<$reveal state="$:/ShowEditPreview" type="nomatch" text="yes">
<em class="tw-edit"><<lingo Body/Hint>></em> <$button type="set" set="$:/ShowEditPreview" setTo="yes"><<lingo Body/Preview/Button/Show>></$button>
<$edit field="text" class="tw-edit-texteditor" placeholder={{$:/language/EditTemplate/Body/Placeholder}}/>
</$reveal>

View File

@ -3,7 +3,11 @@ tags: $:/tags/MoreSideBar
caption: {{$:/language/SideBar/Tags/Caption}}
<$list filter="[tags[]sort[title]]">
<$transclude tiddler="$:/core/ui/TagTemplate"/> <small class="tw-menu-list-count"><$count filter="[is[current]tagging[]]"/></small>
</$list>
----
{{$:/core/ui/UntaggedTemplate}} <small class="tw-menu-list-count"><$count filter="[untagged[]!is[system]] -[tags[]]"/></small>

View File

@ -10,11 +10,12 @@ title: $:/core/ui/PageMacros
<div class="tw-tab-buttons"><$list filter="$tabsList$" variable="currentTab"><$button set=<<qualify "$state$">> setTo=<<currentTab>> default="$default$" selectedClass="tw-tab-selected"><$transclude tiddler=<<currentTab>> field="caption"><$macrocall $name="currentTab" $type="text/plain" $output="text/plain"/></$transclude> </$button>
</$list>
</div>
<div class="tw-tab-divider">
</div>
<div class="tw-tab-divider"/>
<div class="tw-tab-content">
<$list filter="$tabsList$" variable="currentTab">
<$reveal type="match" state=<<qualify "$state$">> text=<<currentTab>> default="$default$">
<$transclude tiddler=<<currentTab>>/>
</$reveal>
</$list>

View File

@ -2,11 +2,14 @@ title: $:/core/ui/PageTemplate/sidebar
tags: $:/tags/PageTemplate
<header class="sidebar-header">
<div class="titlebar">{{SiteTitle}}</div>
<div class="tw-subtitle">{{SiteSubtitle}}</div>
<div class="tw-page-controls">
<$list filter="[is[shadow]!has[draft.of]tag[$:/tags/PageControls]] [!is[shadow]!has[draft.of]tag[$:/tags/PageControls]] +[tag[$:/tags/PageControls]]" variable="listItem"><$transclude tiddler=<<listItem>>/></$list>
</div>
{{$:/core/ui/SideBarLists}}

View File

@ -3,6 +3,9 @@ tags: $:/tags/SideBar
caption: {{$:/language/SideBar/Open/Caption}}
<$list filter="[list[$:/StoryList]]" history="$:/HistoryList" storyview="pop">
<$button message="tw-close-tiddler" class="btn-invisible btn-mini">&times;</$button> <$link to={{!!title}}><$view field="title"/></$link>
</$list>
<$button message="tw-close-all-tiddlers" class="btn-invisible btn-mini">close all</$button>

View File

@ -3,8 +3,15 @@ title: $:/core/ui/TagTemplate
\define tag-styles()
background-color:$(backgroundColor)$;
\end
<span class="tw-tag-list-item"><$set name="backgroundColor" value={{!!color}}><$button popup=<<qualify "$:/state/tagpopup">> class="btn-invisible tw-tag-label" style=<<tag-styles>>><$transclude tiddler={{!!icon}}/> <$view field="title" format="text" /></$button></$set>
<span class="tw-tag-list-item">
<$set name="backgroundColor" value={{!!color}}>
<$button popup=<<qualify "$:/state/tagpopup">> class="btn-invisible tw-tag-label" style=<<tag-styles>>>
<$transclude tiddler={{!!icon}}/> <$view field="title" format="text" />
</$button>
</$set>
<$reveal state=<<qualify "$:/state/tagpopup">> type="popup" position="below" animate="yes"><div class="tw-drop-down"><$transclude tiddler="$:/core/ui/ListItemTemplate"/>
<hr>
<$list filter="[is[current]tagging[]]" template="$:/core/ui/ListItemTemplate"/>
</div></$reveal></span>
</div>
</$reveal>
</span>

View File

@ -2,5 +2,7 @@ title: $:/core/ui/ViewTemplate/body
tags: $:/tags/ViewTemplate
<div class="body">
<$transclude />
</div>

View File

@ -83,16 +83,26 @@ describe("WikiText parser tests", function() {
[ { type : 'element', tag : 'p', children : [ { type : 'element', tag : 'div', isBlock : false, attributes : { attribute : { type : 'indirect', name : 'attribute', textReference : 'Tiddler Title!!field', start : 4, end : 39 } }, children : [ { type : 'text', text : 'some text' } ], start : 0, end : 40 } ] } ]
);
expect(parse("<div attribute={{TiddlerTitle!!field}}>\nsome text</div>")).toEqual(
expect(parse("<div attribute={{TiddlerTitle!!field}}>\n\nsome text</div>")).toEqual(
[ { type : 'element', start : 0, attributes : { attribute : { start : 4, name : 'attribute', type : 'indirect', textReference : 'TiddlerTitle!!field', end : 38 } }, tag : 'div', end : 39, isBlock : true, children : [ { type : 'element', tag : 'p', children : [ { type : 'text', text : 'some text' } ] } ] } ]
);
expect(parse("<div><div attribute={{TiddlerTitle!!field}}>\nsome text</div></div>")).toEqual(
expect(parse("<div><div attribute={{TiddlerTitle!!field}}>\n\nsome text</div></div>")).toEqual(
[ { type : 'element', tag : 'p', children : [ { type : 'element', start : 0, attributes : { }, tag : 'div', end : 5, isBlock : false, children : [ { type : 'element', start : 5, attributes : { attribute : { start : 9, name : 'attribute', type : 'indirect', textReference : 'TiddlerTitle!!field', end : 43 } }, tag : 'div', end : 44, isBlock : true, children : [ { type : 'element', tag : 'p', children : [ { type : 'text', text : 'some text' } ] } ] } ] } ] } ]
);
expect(parse("<div><div attribute={{TiddlerTitle!!field}}>\n\n!some heading</div></div>")).toEqual(
[ { type : 'element', tag : 'p', children : [ { type : 'element', start : 0, attributes : { }, tag : 'div', end : 5, isBlock : false, children : [ { type : 'element', start : 5, attributes : { attribute : { start : 9, name : 'attribute', type : 'indirect', textReference : 'TiddlerTitle!!field', end : 43 } }, tag : 'div', end : 44, isBlock : true, children : [ { type : 'element', tag : 'h1', attributes : { class : { type : 'string', value : '' } }, children : [ { type : 'text', text : 'some heading</div></div>' } ] } ] } ] } ] } ]
);
expect(parse("<div><div attribute={{TiddlerTitle!!field}}>\n!some heading</div></div>")).toEqual(
[ { type : 'element', tag : 'p', children : [ { type : 'element', start : 0, attributes : { }, tag : 'div', end : 5, isBlock : false, children : [ { type : 'element', start : 5, attributes : { attribute : { start : 9, name : 'attribute', type : 'indirect', textReference : 'TiddlerTitle!!field', end : 43 } }, tag : 'div', end : 44, isBlock : false, children : [ { type : 'text', text : '\n!some heading' } ] } ] } ] } ]
);
});
it("should parse macro definitions", function() {

View File

@ -11,6 +11,7 @@ This is version <<version>> of ~TiddlyWiki, a major reboot designed [[for the ne
//~TiddlyWiki is a free, open source project that depends on [[your love and support|HelpingTiddlyWiki]] for its survival//.
<div class="tw-message-box">
<a class="tw-message-icon" href="http://tiddlywiki.com/" target="_blank">{{TiddlyWiki Classic.png}}</a>
!! TiddlyWikiClassic - http://classic.tiddlywiki.com

View File

@ -6,11 +6,17 @@ type: text/vnd.tiddlywiki
Here are the details of recent releases of TiddlyWiki5. See [[TiddlyWiki5 Versioning]] for details of how releases are named.
<$list filter="[tag[releasenote]!sort[created]]">
<div>
<h1><$link to={{!!title}}><$view field="title"/></$link></h1>
<div>''Release date: <$view field="released" format="date" template="DDth MMM YYYY at 0hh:0mm">TBA</$view>''</div>
<div>
<$transclude/>
</div>
</div>
</$list>

View File

@ -7,6 +7,7 @@ type: text/vnd.tiddlywiki
There are several methods for upgrading an existing TiddlyWiki version 5 document to a new release. There is a [[different procedure|Upgrading TiddlyWiki on Node.js]] for upgrading [[TiddlyWiki on Node.js]].
<div class="tw-message-box">
<a class="tw-message-icon" href="http://tiddlywiki.com/" target="_blank">{{TiddlyWiki Classic.png}}</a>
!! Upgrading from TiddlyWikiClassic

View File

@ -19,5 +19,7 @@ The history list also maintains the field ''current-tiddler'' that contains the
Which renders the same as the "Open" sidebar tab, with the addition of a tick against the tiddler that was last navigated to.
<$list filter="[list[$:/StoryList]]" history="$:/HistoryList" storyview="pop">
<$button message="tw-close-tiddler" class="btn-invisible btn-mini">&times;</$button> <$link to={{!!title}}><$view field="title"/> <$reveal type="match" state="$:/HistoryList!!current-tiddler" text=<<currentTiddler>>>&#x2713;</$reveal></$link>
</$list>

View File

@ -1,5 +1,5 @@
created: 20131205160816081
modified: 20131205160828313
modified: 20140220203440064
tags: wikitext
title: HTML in WikiText
type: text/vnd.tiddlywiki
@ -13,6 +13,8 @@ This is my nice and simple block of text. HelloThere
</article>
```
! Attributes
Attributes in HTML tags can be specified as a transclusion or a macro invocation. For example, here the value of the `href` attribute will be set to the value of the tiddler MyLinkDestination:
```
@ -24,3 +26,8 @@ Here an attribute is specified as a macro invocation:
```
<a href=<<MyMacro "Brian">>>link</a>
```
! Content Parsing
The content of an HTML element will be parsed in inline mode unless the opening tag is followed by two linebreaks. (Inline mode means that block mode formatting such as tables, lists and headings is not recognised).

View File

@ -1,10 +1,28 @@
created: 20131205160840915
modified: 20131205161336125
modified: 20140220203320110
tags: wikitext
title: Widgets in WikiText
type: text/vnd.tiddlywiki
Widgets provide rich functionality within WikiText.
Widgets provide rich functionality within WikiText. They have the same syntax as [[HTML elements|HTML in WikiText]], but the tag name always starts with `$`. For example:
```
<$button message="tw-close-tiddler">Close Me!</$button>
```
Note that widgets inherit all the features of [[HTML in WikiText]]:
* Widget attributes can be specified as:
** Unquoted strings (that cannot contain spaces)
** Strings quoted with single or double quotes
** Macro invocations (eg `attr=<<myMacro>>`)
** Transclusions (eg, `attr={{MyTiddler!!field}}`)
* The content of a widget is parsed in inline mode unless the opening tag is followed by two linebreaks, which forces block mode
** 'Inline mode' means that 'block mode' parse rules like headings, tables and lists are not recognised
See [[HTML in WikiText]] for more details.
The available widgets include:
<$list filter="[tag[widget]sort[title]]"/>