1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-07-17 09:24:30 +00:00
TiddlyWiki5/core/modules/parsers/wikiparser/rules/block/heading.js
Jeremy Ruston 31b283ef36 Refactoring implementation of wiki parse rules
And some documentation.
2012-12-14 13:31:47 +00:00

43 lines
869 B
JavaScript

/*\
title: $:/core/modules/parsers/wikiparser/rules/block/heading.js
type: application/javascript
module-type: wikiblockrule
Wiki text block rule for headings
\*/
(function(){
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
exports.name = "heading";
exports.init = function() {
// Regexp to match
this.matchRegExp = /(!{1,6})/mg;
};
/*
Parse the most recent match
*/
exports.parse = function() {
// Get all the details of the match
var headingLevel = this.match[1].length;
// Move past the !s
this.parser.pos = this.matchRegExp.lastIndex;
// Parse the heading
var classedRun = this.parser.parseClassedRun(/(\r?\n)/mg);
// Return the heading
return [{
type: "element",
tag: "h" + this.match[1].length,
attributes: {
"class": {type: "string", value: classedRun["class"]}
},
children: classedRun.tree
}];
};
})();