1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-09-30 16:00:46 +00:00

splited emphasis.js into several modules to have fine grained control with wikification rules eg: rules except bold ... This fixes #701

This commit is contained in:
Mario Pietsch 2014-07-24 17:43:03 +02:00
parent 9424001054
commit 7aa6c7c06d
7 changed files with 300 additions and 79 deletions

View File

@ -1,79 +0,0 @@
/*\
title: $:/core/modules/parsers/wikiparser/rules/emphasis.js
type: application/javascript
module-type: wikirule
Wiki text inline rule for emphasis. For example:
```
This is ''bold'' text
This is //italic// text
This is __underlined__ text
This is ^^superscript^^ text
This is ,,subscript,, text
This is ~~strikethrough~~ text
```
\*/
(function(){
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
exports.name = "emphasis";
exports.types = {inline: true};
exports.init = function(parser) {
this.parser = parser;
// Regexp to match
this.matchRegExp = /''|\/\/|__|\^\^|,,|~~/mg;
};
exports.parse = function() {
// Move past the match
this.parser.pos = this.matchRegExp.lastIndex;
// Figure out which element and closing regexp to use
var tag,reEnd;
switch(this.match[0]) {
case "''": // Bold
tag = "strong";
reEnd = /''/mg;
break;
case "//": // Italics
tag = "em";
reEnd = /\/\//mg;
break;
case "__": // Underline
tag = "u";
reEnd = /__/mg;
break;
case "^^": // Superscript
tag = "sup";
reEnd = /\^\^/mg;
break;
case ",,": // Subscript
tag = "sub";
reEnd = /,,/mg;
break;
case "~~": // Strikethrough
tag = "strike";
reEnd = /~~/mg;
break;
}
// Parse the run including the terminator
var tree = this.parser.parseInlineRun(reEnd,{eatTerminator: true});
// Return the classed span
return [{
type: "element",
tag: tag,
children: tree
}];
};
})();

View File

@ -0,0 +1,50 @@
/*\
title: $:/core/modules/parsers/wikiparser/rules/emphasis/bold.js
type: application/javascript
module-type: wikirule
Wiki text inline rule for emphasis - bold. For example:
```
This is ''bold'' text
```
This wikiparser can be modified using the rules eg:
```
\rules except bold
\rules only bold
```
\*/
(function(){
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
exports.name = "bold";
exports.types = {inline: true};
exports.init = function(parser) {
this.parser = parser;
// Regexp to match
this.matchRegExp = /''/mg;
};
exports.parse = function() {
// Move past the match
this.parser.pos = this.matchRegExp.lastIndex;
// Parse the run including the terminator
var tree = this.parser.parseInlineRun(/''/mg,{eatTerminator: true});
// Return the classed span
return [{
type: "element",
tag: "strong",
children: tree
}];
};
})();

View File

@ -0,0 +1,50 @@
/*\
title: $:/core/modules/parsers/wikiparser/rules/emphasis/italic.js
type: application/javascript
module-type: wikirule
Wiki text inline rule for emphasis - italic. For example:
```
This is //italic// text
```
This wikiparser can be modified using the rules eg:
```
\rules except italic
\rules only italic
```
\*/
(function(){
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
exports.name = "italic";
exports.types = {inline: true};
exports.init = function(parser) {
this.parser = parser;
// Regexp to match
this.matchRegExp = /\/\//mg;
};
exports.parse = function() {
// Move past the match
this.parser.pos = this.matchRegExp.lastIndex;
// Parse the run including the terminator
var tree = this.parser.parseInlineRun(/\/\//mg,{eatTerminator: true});
// Return the classed span
return [{
type: "element",
tag: "em",
children: tree
}];
};
})();

View File

@ -0,0 +1,50 @@
/*\
title: $:/core/modules/parsers/wikiparser/rules/emphasis/strikethrough.js
type: application/javascript
module-type: wikirule
Wiki text inline rule for emphasis - strikethrough. For example:
```
This is ~~strikethrough~~ text
```
This wikiparser can be modified using the rules eg:
```
\rules except strikethrough
\rules only strikethrough
```
\*/
(function(){
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
exports.name = "strikethrough";
exports.types = {inline: true};
exports.init = function(parser) {
this.parser = parser;
// Regexp to match
this.matchRegExp = /~~/mg;
};
exports.parse = function() {
// Move past the match
this.parser.pos = this.matchRegExp.lastIndex;
// Parse the run including the terminator
var tree = this.parser.parseInlineRun(/~~/mg,{eatTerminator: true});
// Return the classed span
return [{
type: "element",
tag: "strike",
children: tree
}];
};
})();

View File

@ -0,0 +1,50 @@
/*\
title: $:/core/modules/parsers/wikiparser/rules/emphasis/subscript.js
type: application/javascript
module-type: wikirule
Wiki text inline rule for emphasis - subscript. For example:
```
This is ,,subscript,, text
```
This wikiparser can be modified using the rules eg:
```
\rules except subscript
\rules only subscript
```
\*/
(function(){
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
exports.name = "subscript";
exports.types = {inline: true};
exports.init = function(parser) {
this.parser = parser;
// Regexp to match
this.matchRegExp = /,,/mg;
};
exports.parse = function() {
// Move past the match
this.parser.pos = this.matchRegExp.lastIndex;
// Parse the run including the terminator
var tree = this.parser.parseInlineRun(/,,/mg,{eatTerminator: true});
// Return the classed span
return [{
type: "element",
tag: "sub",
children: tree
}];
};
})();

View File

@ -0,0 +1,50 @@
/*\
title: $:/core/modules/parsers/wikiparser/rules/emphasis/superscript.js
type: application/javascript
module-type: wikirule
Wiki text inline rule for emphasis - superscript. For example:
```
This is ^^superscript^^ text
```
This wikiparser can be modified using the rules eg:
```
\rules except superscript
\rules only superscript
```
\*/
(function(){
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
exports.name = "superscript";
exports.types = {inline: true};
exports.init = function(parser) {
this.parser = parser;
// Regexp to match
this.matchRegExp = /\^\^/mg;
};
exports.parse = function() {
// Move past the match
this.parser.pos = this.matchRegExp.lastIndex;
// Parse the run including the terminator
var tree = this.parser.parseInlineRun(/\^\^/mg,{eatTerminator: true});
// Return the classed span
return [{
type: "element",
tag: "sup",
children: tree
}];
};
})();

View File

@ -0,0 +1,50 @@
/*\
title: $:/core/modules/parsers/wikiparser/rules/emphasis/underscore.js
type: application/javascript
module-type: wikirule
Wiki text inline rule for emphasis - underscore. For example:
```
This is __underscore__ text
```
This wikiparser can be modified using the rules eg:
```
\rules except underscore
\rules only underscore
```
\*/
(function(){
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
exports.name = "underscore";
exports.types = {inline: true};
exports.init = function(parser) {
this.parser = parser;
// Regexp to match
this.matchRegExp = /__/mg;
};
exports.parse = function() {
// Move past the match
this.parser.pos = this.matchRegExp.lastIndex;
// Parse the run including the terminator
var tree = this.parser.parseInlineRun(/__/mg,{eatTerminator: true});
// Return the classed span
return [{
type: "element",
tag: "u",
children: tree
}];
};
})();