mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-02-27 08:20:32 +00:00
Merge branch 'master' of https://github.com/Jermolene/TiddlyWiki5 into zh
This commit is contained in:
commit
fb07992fa8
@ -218,6 +218,7 @@ exports.parseAttribute = function(source,pos) {
|
|||||||
// Define our regexps
|
// Define our regexps
|
||||||
var reAttributeName = /([^\/\s>"'=]+)/g,
|
var reAttributeName = /([^\/\s>"'=]+)/g,
|
||||||
reUnquotedAttribute = /([^\/\s<>"'=]+)/g,
|
reUnquotedAttribute = /([^\/\s<>"'=]+)/g,
|
||||||
|
reFilteredValue = /\{\{\{(.+?)\}\}\}/g,
|
||||||
reIndirectValue = /\{\{([^\}]+)\}\}/g;
|
reIndirectValue = /\{\{([^\}]+)\}\}/g;
|
||||||
// Skip whitespace
|
// Skip whitespace
|
||||||
pos = $tw.utils.skipWhiteSpace(source,pos);
|
pos = $tw.utils.skipWhiteSpace(source,pos);
|
||||||
@ -243,29 +244,37 @@ exports.parseAttribute = function(source,pos) {
|
|||||||
node.type = "string";
|
node.type = "string";
|
||||||
node.value = stringLiteral.value;
|
node.value = stringLiteral.value;
|
||||||
} else {
|
} else {
|
||||||
// Look for an indirect value
|
// Look for a filtered value
|
||||||
var indirectValue = $tw.utils.parseTokenRegExp(source,pos,reIndirectValue);
|
var filteredValue = $tw.utils.parseTokenRegExp(source,pos,reFilteredValue);
|
||||||
if(indirectValue) {
|
if(filteredValue) {
|
||||||
pos = indirectValue.end;
|
pos = filteredValue.end;
|
||||||
node.type = "indirect";
|
node.type = "filtered";
|
||||||
node.textReference = indirectValue.match[1];
|
node.filter = filteredValue.match[1];
|
||||||
} else {
|
} else {
|
||||||
// Look for a unquoted value
|
// Look for an indirect value
|
||||||
var unquotedValue = $tw.utils.parseTokenRegExp(source,pos,reUnquotedAttribute);
|
var indirectValue = $tw.utils.parseTokenRegExp(source,pos,reIndirectValue);
|
||||||
if(unquotedValue) {
|
if(indirectValue) {
|
||||||
pos = unquotedValue.end;
|
pos = indirectValue.end;
|
||||||
node.type = "string";
|
node.type = "indirect";
|
||||||
node.value = unquotedValue.match[1];
|
node.textReference = indirectValue.match[1];
|
||||||
} else {
|
} else {
|
||||||
// Look for a macro invocation value
|
// Look for a unquoted value
|
||||||
var macroInvocation = $tw.utils.parseMacroInvocation(source,pos);
|
var unquotedValue = $tw.utils.parseTokenRegExp(source,pos,reUnquotedAttribute);
|
||||||
if(macroInvocation) {
|
if(unquotedValue) {
|
||||||
pos = macroInvocation.end;
|
pos = unquotedValue.end;
|
||||||
node.type = "macro";
|
|
||||||
node.value = macroInvocation;
|
|
||||||
} else {
|
|
||||||
node.type = "string";
|
node.type = "string";
|
||||||
node.value = "true";
|
node.value = unquotedValue.match[1];
|
||||||
|
} else {
|
||||||
|
// Look for a macro invocation value
|
||||||
|
var macroInvocation = $tw.utils.parseMacroInvocation(source,pos);
|
||||||
|
if(macroInvocation) {
|
||||||
|
pos = macroInvocation.end;
|
||||||
|
node.type = "macro";
|
||||||
|
node.value = macroInvocation;
|
||||||
|
} else {
|
||||||
|
node.type = "string";
|
||||||
|
node.value = "true";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
81
core/modules/widgets/action-createtiddler.js
Normal file
81
core/modules/widgets/action-createtiddler.js
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
/*\
|
||||||
|
title: $:/core/modules/widgets/action-createtiddler.js
|
||||||
|
type: application/javascript
|
||||||
|
module-type: widget
|
||||||
|
|
||||||
|
Action widget to create a new tiddler with a unique name and specified fields.
|
||||||
|
|
||||||
|
\*/
|
||||||
|
(function(){
|
||||||
|
|
||||||
|
/*jslint node: true, browser: true */
|
||||||
|
/*global $tw: false */
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
var Widget = require("$:/core/modules/widgets/widget.js").widget;
|
||||||
|
|
||||||
|
var CreateTiddlerWidget = function(parseTreeNode,options) {
|
||||||
|
this.initialise(parseTreeNode,options);
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
Inherit from the base widget class
|
||||||
|
*/
|
||||||
|
CreateTiddlerWidget.prototype = new Widget();
|
||||||
|
|
||||||
|
/*
|
||||||
|
Render this widget into the DOM
|
||||||
|
*/
|
||||||
|
CreateTiddlerWidget.prototype.render = function(parent,nextSibling) {
|
||||||
|
this.computeAttributes();
|
||||||
|
this.execute();
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
Compute the internal state of the widget
|
||||||
|
*/
|
||||||
|
CreateTiddlerWidget.prototype.execute = function() {
|
||||||
|
this.actionBaseTitle = this.getAttribute("$basetitle");
|
||||||
|
this.actionSaveTitle = this.getAttribute("$savetitle");
|
||||||
|
this.actionTimestamp = this.getAttribute("$timestamp","yes") === "yes";
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
Refresh the widget by ensuring our attributes are up to date
|
||||||
|
*/
|
||||||
|
CreateTiddlerWidget.prototype.refresh = function(changedTiddlers) {
|
||||||
|
var changedAttributes = this.computeAttributes();
|
||||||
|
if($tw.utils.count(changedAttributes) > 0) {
|
||||||
|
this.refreshSelf();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return this.refreshChildren(changedTiddlers);
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
Invoke the action associated with this widget
|
||||||
|
*/
|
||||||
|
CreateTiddlerWidget.prototype.invokeAction = function(triggeringWidget,event) {
|
||||||
|
var title = this.wiki.generateNewTitle(this.actionBaseTitle),
|
||||||
|
fields = {},
|
||||||
|
creationFields,
|
||||||
|
modificationFields;
|
||||||
|
$tw.utils.each(this.attributes,function(attribute,name) {
|
||||||
|
if(name.charAt(0) !== "$") {
|
||||||
|
fields[name] = attribute;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if(this.actionTimestamp) {
|
||||||
|
creationFields = this.wiki.getCreationFields();
|
||||||
|
modificationFields = this.wiki.getModificationFields();
|
||||||
|
}
|
||||||
|
var tiddler = this.wiki.addTiddler(new $tw.Tiddler(creationFields,fields,modificationFields,{title: title}));
|
||||||
|
if(this.actionSaveTitle) {
|
||||||
|
this.wiki.setTextReference(this.actionSaveTitle,title,this.getVariable("currentTiddler"));
|
||||||
|
}
|
||||||
|
return true; // Action was invoked
|
||||||
|
};
|
||||||
|
|
||||||
|
exports["action-createtiddler"] = CreateTiddlerWidget;
|
||||||
|
|
||||||
|
})();
|
@ -222,7 +222,9 @@ Widget.prototype.computeAttributes = function() {
|
|||||||
self = this,
|
self = this,
|
||||||
value;
|
value;
|
||||||
$tw.utils.each(this.parseTreeNode.attributes,function(attribute,name) {
|
$tw.utils.each(this.parseTreeNode.attributes,function(attribute,name) {
|
||||||
if(attribute.type === "indirect") {
|
if(attribute.type === "filtered") {
|
||||||
|
value = self.wiki.filterTiddlers(attribute.filter,self)[0] || "";
|
||||||
|
} else if(attribute.type === "indirect") {
|
||||||
value = self.wiki.getTextReference(attribute.textReference,"",self.getVariable("currentTiddler"));
|
value = self.wiki.getTextReference(attribute.textReference,"",self.getVariable("currentTiddler"));
|
||||||
} else if(attribute.type === "macro") {
|
} else if(attribute.type === "macro") {
|
||||||
value = self.getVariable(attribute.value.name,{params: attribute.value.params});
|
value = self.getVariable(attribute.value.name,{params: attribute.value.params});
|
||||||
|
@ -0,0 +1,30 @@
|
|||||||
|
caption: action-createtiddler
|
||||||
|
created: 20161020152745942
|
||||||
|
modified: 20161020155119177
|
||||||
|
tags: Widgets ActionWidgets
|
||||||
|
title: ActionCreateTiddlerWidget
|
||||||
|
type: text/vnd.tiddlywiki
|
||||||
|
|
||||||
|
! Introduction
|
||||||
|
|
||||||
|
The ''action-createtiddler'' widget is an [[action widget|ActionWidgets]] that creates new tiddlers. ActionWidgets are used within triggering widgets such as the ButtonWidget.
|
||||||
|
|
||||||
|
There are several differences from the [[tm-new-tiddler message|WidgetMessage: tm-new-tiddler]]:
|
||||||
|
|
||||||
|
* The new tiddler is not automatically displayed in the [[story river|StoryRiver]]
|
||||||
|
* The title of the new tiddler is made available for subsequent operations
|
||||||
|
|
||||||
|
! Content and Attributes
|
||||||
|
|
||||||
|
The ''action-createtiddler'' widget is invisible. Any content within it is ignored.
|
||||||
|
|
||||||
|
|!Attribute |!Description |
|
||||||
|
|$basetitle |The initial title that will be attempted. If a tiddler with that title already exists, then a numerical counter is added to the title and incremented until it is unique|
|
||||||
|
|$savetitle |A text reference identifying a field or index into which the title of the newly created tiddler will be stored after it is created |
|
||||||
|
|$timestamp |Specifies whether the timestamp(s) of the target tiddler will be updated (''modified'' and ''modifier'', plus ''created'' and ''creator'' for newly created tiddlers). Can be "yes" (the default) or "no" |
|
||||||
|
|//{any attributes not starting with $}// |Each attribute name specifies a field to be created in the new tiddler |
|
||||||
|
|
||||||
|
! Examples
|
||||||
|
|
||||||
|
<$macrocall $name='wikitext-example-without-html'
|
||||||
|
src={{ActionCreateTiddlerWidget Example}}/>
|
@ -0,0 +1,12 @@
|
|||||||
|
created: 20161020153426686
|
||||||
|
modified: 20161020155142990
|
||||||
|
tags: ActionCreateTiddlerWidget
|
||||||
|
title: ActionCreateTiddlerWidget Example
|
||||||
|
type: text/vnd.tiddlywiki
|
||||||
|
|
||||||
|
New button caption: <$edit-text tiddler="$:/state/new-button-caption" tag="input" default=""/>
|
||||||
|
|
||||||
|
<$button>
|
||||||
|
<$action-createtiddler $basetitle="Homemade Button" tags="$:/tags/PageControls" text={{$:/state/new-button-caption}}/>
|
||||||
|
Create non-functional page control button
|
||||||
|
</$button>
|
@ -1,6 +1,6 @@
|
|||||||
caption: HTML
|
caption: HTML
|
||||||
created: 20131205160816081
|
created: 20131205160816081
|
||||||
modified: 20160622112259272
|
modified: 20161021102422842
|
||||||
tags: WikiText
|
tags: WikiText
|
||||||
title: HTML in WikiText
|
title: HTML in WikiText
|
||||||
type: text/vnd.tiddlywiki
|
type: text/vnd.tiddlywiki
|
||||||
@ -14,25 +14,29 @@ This is my nice and simple block of text. HelloThere
|
|||||||
</article>
|
</article>
|
||||||
```
|
```
|
||||||
|
|
||||||
|
[[Widgets share the same syntax as HTML tags|Widgets in WikiText]], and so the following information applies to them, too.
|
||||||
|
|
||||||
! Content Parsing
|
! Content Parsing
|
||||||
|
|
||||||
The content of an HTML element will be parsed in inline mode unless the opening tag is followed by two linebreaks, in which case it is parsed in block mode. (Inline mode means that block mode formatting such as tables, lists and headings is not recognised).
|
The content of an HTML element will be parsed in inline mode unless the opening tag is followed by two linebreaks, in which case it will be parsed in block mode. (Inline mode means that block mode formatting such as tables, lists and headings is not recognised).
|
||||||
|
|
||||||
! Attributes
|
! Attributes
|
||||||
|
|
||||||
Attributes in HTML tags can be specified as a literal, 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:
|
In an extension of conventional HTML syntax, attributes of elements/widgets can be specified in several different ways:
|
||||||
|
|
||||||
```
|
* a literal string
|
||||||
<a href={{MyLinkDestination}} rel="noopener noreferrer">link</a>
|
* a transclusion of a TextReference
|
||||||
```
|
* a transclusion of a [[macro/variable|Macros in WikiText]]
|
||||||
|
* as the result of a [[Filter Expression]]
|
||||||
|
|
||||||
Note that the link should have the `rel` attribute set to `noopener noreferrer` to maintain privacy of the URLs of private TiddlyWiki's (eg on Dropbox). See https://mathiasbynens.github.io/rel-noopener/ for more information.
|
!! Literal Attribute Values
|
||||||
|
|
||||||
Here an attribute is specified as a macro invocation:
|
Literal attribute values can use several different styles of quoting:
|
||||||
|
|
||||||
```
|
* Single quotes (eg `attr='value'`)
|
||||||
<a href=<<MyMacro "Brian">> rel="noopener noreferrer">link</a>
|
* Double quotes (eg `attr="value"`)
|
||||||
```
|
* Tripe double quotes (eg `attr="""value"""`)
|
||||||
|
* No quoting is necessary for values that do not contain spaces (eg `attr=value`)
|
||||||
|
|
||||||
Literal attribute values can include line breaks. For example:
|
Literal attribute values can include line breaks. For example:
|
||||||
|
|
||||||
@ -43,7 +47,7 @@ Rodentville,
|
|||||||
Ratland."/>
|
Ratland."/>
|
||||||
```
|
```
|
||||||
|
|
||||||
By using triple-double quotes you can specify attribute values that include single double quotes. For example:
|
By using triple-double quotes you can specify attribute values that contain single double quotes. For example:
|
||||||
|
|
||||||
```
|
```
|
||||||
<div data-address="""Mouse House,
|
<div data-address="""Mouse House,
|
||||||
@ -51,3 +55,34 @@ By using triple-double quotes you can specify attribute values that include sing
|
|||||||
Rodentville,
|
Rodentville,
|
||||||
Ratland."""/>
|
Ratland."""/>
|
||||||
```
|
```
|
||||||
|
|
||||||
|
!! Transcluded Attribute Values
|
||||||
|
|
||||||
|
Transcluded attribute values are indicated with double curly braces around a TextReference. For example:
|
||||||
|
|
||||||
|
```
|
||||||
|
attr={{tiddler}}
|
||||||
|
attr={{!!field}}
|
||||||
|
attr={{tiddler!!field}}
|
||||||
|
```
|
||||||
|
|
||||||
|
!! Variable Attribute Values
|
||||||
|
|
||||||
|
Variable attribute values are indicated with double angle brackets around a [[macro invocation|Macro Calls in WikiText]]. For example:
|
||||||
|
|
||||||
|
```
|
||||||
|
<div title=<<MyMacro "Brian">>>
|
||||||
|
...
|
||||||
|
</div>
|
||||||
|
```
|
||||||
|
|
||||||
|
!! Filtered Attribute Values
|
||||||
|
|
||||||
|
Filtered attribute values are indicated with triple curly braces around a [[Filter Expression]]. The value will be the first item in the resulting list, or the empty string if the list is empty.
|
||||||
|
|
||||||
|
This example shows how to add a prefix to a value:
|
||||||
|
|
||||||
|
```
|
||||||
|
<$text text={{{ [<currentTiddler>]addPrefix[$:/myprefix/]] }}}>
|
||||||
|
```
|
||||||
|
|
||||||
|
@ -0,0 +1,17 @@
|
|||||||
|
created: 20161021101834041
|
||||||
|
modified: 20161021102041147
|
||||||
|
tags: [[HTML in WikiText]]
|
||||||
|
title: HTML Links in WikiText
|
||||||
|
type: text/vnd.tiddlywiki
|
||||||
|
|
||||||
|
It is often useful to be able to create HTML links to external resources. For example, here the value of the `href` attribute will be set to the value of the tiddler MyLinkDestination:
|
||||||
|
|
||||||
|
```
|
||||||
|
<a href={{MyLinkDestination}}>link</a>
|
||||||
|
```
|
||||||
|
|
||||||
|
However, there is an unexpected security issue that means that most of the time the link should have the `rel` attribute set to `noopener noreferrer` to maintain privacy of the URLs of private TiddlyWiki's (eg on Dropbox). See https://mathiasbynens.github.io/rel-noopener/ for more information.
|
||||||
|
|
||||||
|
```
|
||||||
|
<a href={{MyLinkDestination}} rel="noopener noreferrer">link</a>
|
||||||
|
```
|
@ -1,9 +1,9 @@
|
|||||||
|
caption: Widgets
|
||||||
created: 20131205160840915
|
created: 20131205160840915
|
||||||
modified: 20140619111725471
|
modified: 20161020210726813
|
||||||
tags: WikiText
|
tags: WikiText
|
||||||
title: Widgets in WikiText
|
title: Widgets in WikiText
|
||||||
type: text/vnd.tiddlywiki
|
type: text/vnd.tiddlywiki
|
||||||
caption: Widgets
|
|
||||||
|
|
||||||
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:
|
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:
|
||||||
|
|
||||||
@ -19,6 +19,7 @@ Note that widgets inherit all the features of [[HTML in WikiText]]:
|
|||||||
** Strings quoted with triple-double quotes
|
** Strings quoted with triple-double quotes
|
||||||
** Macro invocations (eg `attr=<<myMacro>>`)
|
** Macro invocations (eg `attr=<<myMacro>>`)
|
||||||
** Transclusions (eg, `attr={{MyTiddler!!field}}`)
|
** Transclusions (eg, `attr={{MyTiddler!!field}}`)
|
||||||
|
** Filtered transclusions (eg, `attr={{{ [filter[op]] }}}`)
|
||||||
* The content of a widget is parsed in inline mode unless the opening tag is followed by two linebreaks, which forces block mode
|
* 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
|
** 'Inline mode' means that 'block mode' parse rules like headings, tables and lists are not recognised
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user