mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-08-04 12:58:01 +00:00
feat: add example
This commit is contained in:
parent
ab2b79ef80
commit
602e5eacd5
@ -1,4 +1,5 @@
|
|||||||
/*\
|
// @ts-check
|
||||||
|
/**
|
||||||
title: $:/core/modules/parsers/wikiparser/rules/codeblock.js
|
title: $:/core/modules/parsers/wikiparser/rules/codeblock.js
|
||||||
type: application/javascript
|
type: application/javascript
|
||||||
module-type: wikirule
|
module-type: wikirule
|
||||||
@ -11,7 +12,28 @@ Wiki text rule for code blocks. For example:
|
|||||||
```
|
```
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@module $:/core/modules/parsers/wikiparser/rules/codeblock.js
|
||||||
|
|
||||||
\*/
|
\*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents the `codeblock` rule.
|
||||||
|
*
|
||||||
|
* @typedef {Object} CodeblockNode
|
||||||
|
* @property {string} type - The type of the widget, which is "codeblock".
|
||||||
|
* @property {Object} attributes - The attributes of the codeblock.
|
||||||
|
* @property {Object} attributes.code - The code attribute object.
|
||||||
|
* @property {string} attributes.code.type - The type of the code attribute, which is "string".
|
||||||
|
* @property {string} attributes.code.value - The actual code content within the code block.
|
||||||
|
* @property {number} attributes.code.start - The start position of the code in the source text.
|
||||||
|
* @property {number} attributes.code.end - The end position of the code in the source text.
|
||||||
|
* @property {Object} attributes.language - The language attribute object.
|
||||||
|
* @property {string} attributes.language.type - The type of the language attribute, which is "string".
|
||||||
|
* @property {string} attributes.language.value - The language specified after the triple backticks, if any.
|
||||||
|
* @property {number} attributes.language.start - The start position of the language string in the source text.
|
||||||
|
* @property {number} attributes.language.end - The end position of the language string in the source text.
|
||||||
|
*/
|
||||||
|
|
||||||
(function(){
|
(function(){
|
||||||
|
|
||||||
/*jslint node: true, browser: true */
|
/*jslint node: true, browser: true */
|
||||||
@ -21,12 +43,22 @@ Wiki text rule for code blocks. For example:
|
|||||||
exports.name = "codeblock";
|
exports.name = "codeblock";
|
||||||
exports.types = {block: true};
|
exports.types = {block: true};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initializes the codeblock rule with the given parser.
|
||||||
|
*
|
||||||
|
* @param {Object} parser - The parser object that manages the state of the parsing process.
|
||||||
|
*/
|
||||||
exports.init = function(parser) {
|
exports.init = function(parser) {
|
||||||
this.parser = parser;
|
this.parser = parser;
|
||||||
// Regexp to match and get language if defined
|
// Regexp to match and get language if defined
|
||||||
this.matchRegExp = /```([\w-]*)\r?\n/mg;
|
this.matchRegExp = /```([\w-]*)\r?\n/mg;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses the code block and returns an array of `codeblock` widgets.
|
||||||
|
*
|
||||||
|
* @returns {CodeblockNode[]} An array containing a single codeblock widget object.
|
||||||
|
*/
|
||||||
exports.parse = function() {
|
exports.parse = function() {
|
||||||
var reEnd = /(\r?\n```$)/mg;
|
var reEnd = /(\r?\n```$)/mg;
|
||||||
var languageStart = this.parser.pos + 3,
|
var languageStart = this.parser.pos + 3,
|
||||||
|
15
core/modules/parsers/wikiparser/try.js
Normal file
15
core/modules/parsers/wikiparser/try.js
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
// @ts-check
|
||||||
|
/**
|
||||||
|
* @typedef {import('./rules/codeblock').CodeblockNode} CodeblockNode
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A function that processes a code block.
|
||||||
|
*
|
||||||
|
* @param {CodeblockNode[]} codeblocks - An array of codeblock rules.
|
||||||
|
*/
|
||||||
|
function processCodeblocks(codeblocks) {
|
||||||
|
codeblocks.forEach(function(cb) {
|
||||||
|
console.log(cb.attributes.code.value);
|
||||||
|
});
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user