mirror of
https://github.com/TiddlyWiki/TiddlyWiki5.git
synced 2026-04-27 16:34:43 +00:00
commit5687d9f44bAuthor: Gk0Wk <nmg_wk@yeah.net> Date: Wed Dec 6 11:33:43 2023 +0800 Fix for html parser commitdf0a1b184eAuthor: Gk0Wk <nmg_wk@yeah.net> Date: Wed Dec 6 02:47:47 2023 +0800 Fix HTML AST node boundary parsing in WikiText commitac8dda0a1aAuthor: Gk0Wk <nmg_wk@yeah.net> Date: Sat Dec 2 13:02:52 2023 +0800 update test-wikitext-parser.js, change for-const-of -to .utils.each, add more range attributes commite2b9a4ed57Author: Gk0Wk <nmg_wk@yeah.net> Date: Wed Nov 29 22:35:39 2023 +0800 Add more start-end range attributes for AST commitd3e62ec56aAuthor: Gk0Wk <nmg_wk@yeah.net> Date: Wed Nov 29 20:45:00 2023 +0800 Add rule attribute for WikiText AST nodes commit4200495055Author: Gk0Wk <nmg_wk@yeah.net> Date: Wed Nov 29 15:48:38 2023 +0800 Add start and end properties to AST nodes for list, codeblock, and all other elements
59 lines
1.2 KiB
JavaScript
59 lines
1.2 KiB
JavaScript
/*\
|
|
title: $:/core/modules/parsers/wikiparser/rules/codeinline.js
|
|
type: application/javascript
|
|
module-type: wikirule
|
|
|
|
Wiki text inline rule for code runs. For example:
|
|
|
|
```
|
|
This is a `code run`.
|
|
This is another ``code run``
|
|
```
|
|
|
|
\*/
|
|
(function(){
|
|
|
|
/*jslint node: true, browser: true */
|
|
/*global $tw: false */
|
|
"use strict";
|
|
|
|
exports.name = "codeinline";
|
|
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;
|
|
var reEnd = new RegExp(this.match[1], "mg");
|
|
// Look for the end marker
|
|
reEnd.lastIndex = this.parser.pos;
|
|
var match = reEnd.exec(this.parser.source),
|
|
text,
|
|
start = this.parser.pos;
|
|
// Process the text
|
|
if(match) {
|
|
text = this.parser.source.substring(this.parser.pos,match.index);
|
|
this.parser.pos = match.index + match[0].length;
|
|
} else {
|
|
text = this.parser.source.substr(this.parser.pos);
|
|
this.parser.pos = this.parser.sourceLength;
|
|
}
|
|
return [{
|
|
type: "element",
|
|
tag: "code",
|
|
children: [{
|
|
type: "text",
|
|
text: text,
|
|
start: start,
|
|
end: this.parser.pos
|
|
}]
|
|
}];
|
|
};
|
|
|
|
})();
|