mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-09-09 13:59:41 +00:00
b43d4a33d6
Ok, I think I've got it now. The following matches all... 1. starting with a literal `$:` 2. then any number of character not a whitespace, `<` or `|` 3. closing with anything that is, again, not a whitespace, `<` or `|` Test here... http://tbdemo.tiddlyspot.com/#Autolink%20System%20Tiddlers
45 lines
920 B
JavaScript
45 lines
920 B
JavaScript
/*\
|
|
title: $:/core/modules/parsers/wikiparser/rules/syslink.js
|
|
type: application/javascript
|
|
module-type: wikirule
|
|
|
|
Wiki text inline rule for system tiddler links.
|
|
Can be suppressed preceding them with `~`.
|
|
\*/
|
|
(function(){
|
|
|
|
/*jslint node: true, browser: true */
|
|
/*global $tw: false */
|
|
"use strict";
|
|
|
|
exports.name = "syslink";
|
|
exports.types = {inline: true};
|
|
|
|
exports.init = function(parser) {
|
|
this.parser = parser;
|
|
// Regexp to match
|
|
this.matchRegExp = /~?\$:[^\s<|]+(?:[^\s<|])/mg;
|
|
};
|
|
|
|
exports.parse = function() {
|
|
var match = this.match[0];
|
|
// Move past the match
|
|
this.parser.pos = this.matchRegExp.lastIndex;
|
|
// Create the link unless it is suppressed
|
|
if(match.substr(0,1) === "~") {
|
|
return [{type: "text", text: match.substr(1)}];
|
|
} else {
|
|
return [{
|
|
type: "link",
|
|
attributes: {
|
|
to: {type: "string", value: match}
|
|
},
|
|
children: [{
|
|
type: "text",
|
|
text: match
|
|
}]
|
|
}];
|
|
}
|
|
};
|
|
|
|
})(); |