mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-06-24 22:33:16 +00:00
Add new "\import" pragma
This commit is contained in:
parent
f61a61c060
commit
fe85845c3c
53
core/modules/parsers/wikiparser/rules/import.js
Normal file
53
core/modules/parsers/wikiparser/rules/import.js
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
/*\
|
||||||
|
title: $:/core/modules/parsers/wikiparser/rules/import.js
|
||||||
|
type: application/javascript
|
||||||
|
module-type: wikirule
|
||||||
|
|
||||||
|
Wiki pragma rule for importing variable definitions
|
||||||
|
|
||||||
|
```
|
||||||
|
\import [[$:/core/ui/PageMacros]] [all[shadows+tiddlers]tag[$:/tags/Macro]!has[draft.of]]
|
||||||
|
```
|
||||||
|
|
||||||
|
\*/
|
||||||
|
(function(){
|
||||||
|
|
||||||
|
/*jslint node: true, browser: true */
|
||||||
|
/*global $tw: false */
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
exports.name = "import";
|
||||||
|
exports.types = {pragma: true};
|
||||||
|
|
||||||
|
/*
|
||||||
|
Instantiate parse rule
|
||||||
|
*/
|
||||||
|
exports.init = function(parser) {
|
||||||
|
this.parser = parser;
|
||||||
|
// Regexp to match
|
||||||
|
this.matchRegExp = /^\\import[^\S\n]/mg;
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
Parse the most recent match
|
||||||
|
*/
|
||||||
|
exports.parse = function() {
|
||||||
|
var self = this;
|
||||||
|
// Move past the pragma invocation
|
||||||
|
this.parser.pos = this.matchRegExp.lastIndex;
|
||||||
|
// Parse the filter terminated by a line break
|
||||||
|
var reMatch = /(.*)(\r?\n)|$/mg;
|
||||||
|
reMatch.lastIndex = this.parser.pos;
|
||||||
|
var match = reMatch.exec(this.parser.source);
|
||||||
|
this.parser.pos = reMatch.lastIndex;
|
||||||
|
// Parse tree nodes to return
|
||||||
|
return [{
|
||||||
|
type: "importvariables",
|
||||||
|
attributes: {
|
||||||
|
filter: {type: "string", value: match[1]}
|
||||||
|
},
|
||||||
|
children: []
|
||||||
|
}];
|
||||||
|
};
|
||||||
|
|
||||||
|
})();
|
|
@ -1,5 +1,5 @@
|
||||||
created: 20150219175930000
|
created: 20150219175930000
|
||||||
modified: 20170712154519026
|
modified: 20180928145730028
|
||||||
tags: Concepts
|
tags: Concepts
|
||||||
title: Pragma
|
title: Pragma
|
||||||
type: text/vnd.tiddlywiki
|
type: text/vnd.tiddlywiki
|
||||||
|
@ -16,3 +16,5 @@ The following pragmas are available:
|
||||||
: for adjusting the set of rules used to parse the text
|
: for adjusting the set of rules used to parse the text
|
||||||
;`\whitespace trim` or `\whitespace notrim`
|
;`\whitespace trim` or `\whitespace notrim`
|
||||||
: <<.from-version "5.1.15">> Control whether whitespace is trimmed from the start and end of text runs (the default is ''notrim''). This setting can be useful when the whitespace generated by linebreaks disturbs formatting
|
: <<.from-version "5.1.15">> Control whether whitespace is trimmed from the start and end of text runs (the default is ''notrim''). This setting can be useful when the whitespace generated by linebreaks disturbs formatting
|
||||||
|
;`\import <filter-expression>`
|
||||||
|
: <<.from-version "5.1.18">> for importing macro definitions from tiddlers identified by a filter expression
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
|
caption: importvariables
|
||||||
created: 20140612142500000
|
created: 20140612142500000
|
||||||
modified: 20140612175900970
|
modified: 20180928150043777
|
||||||
tags: Widgets
|
tags: Widgets
|
||||||
title: ImportVariablesWidget
|
title: ImportVariablesWidget
|
||||||
type: text/vnd.tiddlywiki
|
type: text/vnd.tiddlywiki
|
||||||
caption: importvariables
|
|
||||||
|
|
||||||
! Introduction
|
! Introduction
|
||||||
|
|
||||||
|
@ -31,3 +31,11 @@ So-called global macros are implemented within the main page template ([[$:/core
|
||||||
...
|
...
|
||||||
</$importvariables>
|
</$importvariables>
|
||||||
```
|
```
|
||||||
|
|
||||||
|
! `\import` Pragma
|
||||||
|
|
||||||
|
<<.from-version "5.1.18">> The `\import` [[pragma|Pragma]] is an alternative syntax for using the ImportVariablesWidget. For example, the previous example could be expressed as:
|
||||||
|
|
||||||
|
```
|
||||||
|
\import [[$:/core/ui/PageMacros]] [all[shadows+tiddlers]tag[$:/tags/Macro]!has[draft.of]
|
||||||
|
```
|
Loading…
Reference in New Issue
Block a user