mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-09-18 10:19:44 +00:00
d338a54370
This is a half-way through a big refactoring of the parsing and rendering infrastructure. The main change is to separate the parse and render trees, which makes the code a lot cleaner. The new parser isn't yet functional enough to replace the existing parser so for the moment you have to manually invoke it with `$tw.testNewParser()` in your browser console. I really ought to use branches for this kind of thing...
53 lines
1.2 KiB
JavaScript
53 lines
1.2 KiB
JavaScript
/*\
|
|
title: $:/core/modules/parsers/wikiparser/rules/run/entity.js
|
|
type: application/javascript
|
|
module-type: wikirunrule
|
|
|
|
Wiki text run rule for HTML entities. For example:
|
|
|
|
{{{
|
|
This is a copyright symbol: ©
|
|
}}}
|
|
|
|
\*/
|
|
(function(){
|
|
|
|
/*jslint node: true, browser: true */
|
|
/*global $tw: false */
|
|
"use strict";
|
|
|
|
var EntityRule = function(parser,startPos) {
|
|
// Save state
|
|
this.parser = parser;
|
|
// Regexp to match
|
|
this.reMatch = /(&#?[a-zA-Z0-9]{2,8};)/mg;
|
|
// Get the first match
|
|
this.matchIndex = startPos-1;
|
|
this.findNextMatch(startPos);
|
|
};
|
|
|
|
EntityRule.prototype.findNextMatch = function(startPos) {
|
|
if(this.matchIndex !== undefined && startPos > this.matchIndex) {
|
|
this.reMatch.lastIndex = startPos;
|
|
this.match = this.reMatch.exec(this.parser.source);
|
|
this.matchIndex = this.match ? this.match.index : undefined;
|
|
}
|
|
return this.matchIndex;
|
|
};
|
|
|
|
/*
|
|
Parse the most recent match
|
|
*/
|
|
EntityRule.prototype.parse = function() {
|
|
// Get all the details of the match
|
|
var entityString = this.match[1];
|
|
// Move past the macro call
|
|
this.parser.pos = this.reMatch.lastIndex;
|
|
// Return the entity
|
|
return [{type: "entity", entity: this.match[0]}];
|
|
};
|
|
|
|
exports.EntityRule = EntityRule;
|
|
|
|
})();
|