mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-27 12:07:19 +00:00
Merge pull request #702 from pmario/701-split-emphasis
splited emphasis.js into several modules to have fine grained control with rules pragma
This commit is contained in:
commit
ae469c3f87
@ -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
|
||||
}];
|
||||
};
|
||||
|
||||
})();
|
50
core/modules/parsers/wikiparser/rules/emphasis/bold.js
Normal file
50
core/modules/parsers/wikiparser/rules/emphasis/bold.js
Normal 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
|
||||
}];
|
||||
};
|
||||
|
||||
})();
|
50
core/modules/parsers/wikiparser/rules/emphasis/italic.js
Normal file
50
core/modules/parsers/wikiparser/rules/emphasis/italic.js
Normal 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
|
||||
}];
|
||||
};
|
||||
|
||||
})();
|
@ -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
|
||||
}];
|
||||
};
|
||||
|
||||
})();
|
50
core/modules/parsers/wikiparser/rules/emphasis/subscript.js
Normal file
50
core/modules/parsers/wikiparser/rules/emphasis/subscript.js
Normal 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
|
||||
}];
|
||||
};
|
||||
|
||||
})();
|
@ -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
|
||||
}];
|
||||
};
|
||||
|
||||
})();
|
50
core/modules/parsers/wikiparser/rules/emphasis/underscore.js
Normal file
50
core/modules/parsers/wikiparser/rules/emphasis/underscore.js
Normal 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
|
||||
}];
|
||||
};
|
||||
|
||||
})();
|
Loading…
Reference in New Issue
Block a user