1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-06-25 23:03:15 +00:00

Add better control over whether tiddlers are transcluded in block or inline mode

This commit is contained in:
Jermolene 2014-02-12 17:59:28 +00:00
parent f67e216b3a
commit ecad2bf7a8
3 changed files with 50 additions and 4 deletions

View File

@ -41,6 +41,7 @@ TranscludeWidget.prototype.execute = function() {
this.transcludeTitle = this.getAttribute("tiddler",this.getVariable("currentTiddler"));
this.transcludeField = this.getAttribute("field");
this.transcludeIndex = this.getAttribute("index");
this.transcludeMode = this.getAttribute("mode");
// Check for recursion
var recursionMarker = this.makeRecursionMarker();;
if(this.parentWidget && this.parentWidget.hasVariable("transclusion",recursionMarker)) {
@ -50,11 +51,17 @@ TranscludeWidget.prototype.execute = function() {
// Set context variables for recursion detection
this.setVariable("transclusion",recursionMarker);
// Parse the text reference
var parseAsInline = !this.parseTreeNode.isBlock;
if(this.transcludeMode === "inline") {
parseAsInline = true;
} else if(this.transcludeMode === "block") {
parseAsInline = false;
}
var parser = this.wiki.parseTextReference(
this.transcludeTitle,
this.transcludeField,
this.transcludeIndex,
{parseAsInline: !this.parseTreeNode.isBlock}),
{parseAsInline: parseAsInline}),
parseTreeNodes = parser ? parser.tree : [];
// Construct the child widgets
this.makeChildWidgets(parseTreeNodes);

View File

@ -1,7 +1,8 @@
created: 201308241425
modified: 201310301349
created: 20130824142500000
modified: 20140212175900970
tags: widget
title: TranscludeWidget
type: text/vnd.tiddlywiki
! Introduction
@ -16,6 +17,44 @@ The TranscludeWidget dynamically imports content from another tiddler.
|class |CSS classes to added to the generated elements |
|style |CSS styles to be added to the generated elements |
|tooltip |Tooltip to be added to the generated elements |
|mode |Override the default parsing mode for the transcluded text to "block" or "inline" |
The TranscludeWidget ignores any contained content.
! Parsing modes
TiddlyWiki parses text in two modes:
* ''inline'' mode recognises character formatting such as emphasis, links
* ''block'' mode recognises all the ''inline'' formatting, and adds block formatting such as tables, headings and lists
Usually, the mode is determined by whether the transclude widget itself has been parsed in block or inline mode. This can be overridden with the `mode` attribute.
For example, consider tiddler "A" with this content:
```
# Item one
#<$transclude tiddler="B"/>
# Item two
```
And a tiddler "B" with this content:
```
# Item one - a
# Item one - b
```
The result will be something like this:
# Item one
# # Item one - a # Item one - b
# Item two
This can be fixed by amending tiddler "A":
```
# Item one
#<$transclude tiddler="B" mode="block"/>
# Item two
```

File diff suppressed because one or more lines are too long