Add new "\import" pragma

logging-improvements
Jermolene 2018-09-28 16:01:32 +01:00
rodzic f61a61c060
commit fe85845c3c
3 zmienionych plików z 66 dodań i 3 usunięć

Wyświetl plik

@ -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: []
}];
};
})();

Wyświetl plik

@ -1,5 +1,5 @@
created: 20150219175930000
modified: 20170712154519026
modified: 20180928145730028
tags: Concepts
title: Pragma
type: text/vnd.tiddlywiki
@ -16,3 +16,5 @@ The following pragmas are available:
: for adjusting the set of rules used to parse the text
;`\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
;`\import <filter-expression>`
: <<.from-version "5.1.18">> for importing macro definitions from tiddlers identified by a filter expression

Wyświetl plik

@ -1,9 +1,9 @@
caption: importvariables
created: 20140612142500000
modified: 20140612175900970
modified: 20180928150043777
tags: Widgets
title: ImportVariablesWidget
type: text/vnd.tiddlywiki
caption: importvariables
! Introduction
@ -31,3 +31,11 @@ So-called global macros are implemented within the main page template ([[$:/core
...
</$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]
```