TonyM
First of all:
/*\
title: $:/core/modules/parsers/wikiparser/rules/list.js
type: application/javascript
module-type: wikirule
Wiki text block rule for lists. For example:
```
* This is an unordered list
* It has two items
# This is a numbered list
## With a subitem
# And a third item
; This is a term that is being defined
: This is the definition of that term
```
Note that lists can be nested arbitrarily:
```
#** One
#* Two
#** Three
#**** Four
#**# Five
#**## Six
## Seven
### Eight
## Nine
```
A CSS class can be applied to a list item as follows:
```
* List item one
*.active List item two has the class `active`
* List item three
```
\*/
(function(){
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
exports.name = "list";
exports.types = {block: true};
exports.init = function(parser) {
this.parser = parser;
// Regexp to match
this.matchRegExp = /([\*#;:>\.]+)|([ ]{2,}$)/mg; // Cd.K dot, double
blank
};
var listTypes = {
"*": {listTag: "ul", itemTag: "li"},
"#": {listTag: "ol", itemTag: "li"},
";": {listTag: "dl", itemTag: "dt"},
":": {listTag: "dl", itemTag: "dd"},
">": {listTag: "blockquote", itemTag: "p"},
".": {listTag: "p", itemTag: "p"}, // Cd.K dot
" ": {listTag: "p", itemTag: "p"} // Cd.K blank
};
/*
Parse the most recent match
*/
exports.parse = function() {
// Array of parse tree nodes for the previous row of the list
var listStack = [];
// Cycle through the items in the list
while(true) {
// Match the list marker
var reMatch = /([\*#;:>\.]+)|([ ]{2,}$)/mg; // Cd.K dot, double
blank
reMatch.lastIndex = this.parser.pos;
var match = reMatch.exec(this.parser.source);
if(!match || match.index !== this.parser.pos) {
break;
}
// Check whether the list type of the top level matches
var listInfo = listTypes[match[0].charAt(0)];
// Cd.K
if (match[0].charAt(0) == ".") {
console.log("Cd.K wikparser/rules/list.js 87 found leading '.'
case")
}
if (match[0].charAt(0) == " ") {
console.log("Cd.K wikparser/rules/list.js 90 found trailing
blank case")
}
if(listStack.length > 0 && listStack[0].tag !== listInfo.listTag) {
break;
}
// Move past the list marker
this.parser.pos = match.index + match[0].length;
// Walk through the list markers for the current row
for(var t=0; t<match[0].length; t++) {
listInfo = listTypes[match[0].charAt(t)];
// Remove any stacked up element if we can't re-use it because
the list type doesn't match
if(listStack.length > t && listStack[t].tag !== listInfo.listTag
) {
listStack.splice(t,listStack.length - t);
}
// Construct the list element or reuse the previous one at this
level
if(listStack.length <= t) {
var listElement = {type: "element", tag: listInfo.listTag,
children: [
{type: "element", tag: listInfo.itemTag, children: []}
]};
// Link this list element into the last child item of the
parent list item
if(t) {
var prevListItem = listStack[t-1].children[listStack[t-1
].children.length-1];
prevListItem.children.push(listElement);
}
// Save this element in the stack
listStack[t] = listElement;
} else if(t === (match[0].length - 1)) {
listStack[t].children.push({type: "element", tag: listInfo.
itemTag, children: []});
}
}
if(listStack.length > match[0].length) {
listStack.splice(match[0].length,listStack.length - match[0].
length);
}
// Process the body of the list item into the last list item
var lastListChildren = listStack[listStack.length-1].children,
lastListItem = lastListChildren[lastListChildren.length-1],
classes = this.parser.parseClasses();
this.parser.skipWhitespace({treatNewlinesAsNonWhitespace: true});
var tree = this.parser.parseInlineRun(/(\r?\n)/mg);
lastListItem.children.push.apply(lastListItem.children,tree);
if(classes.length > 0) {
$tw.utils.addClassToParseTreeNode(lastListItem,classes.join(" "
));
}
// Consume any whitespace following the list item
this.parser.skipWhitespace();
}
// Return the root element of the list
return [listStack[0]];
};
})();
.
I marked all my modifications with `Cd.K`.
I am now in the process of turning this change above into a plugin named
"linebreak".
My use case:
I write flow text and want a line break inside the paragraph at the cursor
position and now just insert `blank blank Enter` instead of `<br/> Enter`.
To make leading points:
You can use the TiddlyWiki CodeMirror Editor plugin. This editor has a
column mode, so you select the column before your text with `alt` and mouse
dragging.
vertical or block selection in codemirror
<https://stackoverflow.com/questions/14232383/vertical-or-block-selection-in-codemirror>
On Wednesday, September 25, 2019 at 2:20:57 AM UTC+2, TonyM wrote:
>
> Cd.K
>
> Great work, do share (in time). I do not understand your used case for
>
>> But I think it's better to have a new rule `linebreak` that reacts on
>> leading point or trailing 2 or more spaces. For each trigger I want to
>> append a different style, because I use `<br/>` to reduce the line spacing.
>
>
> I was able to make a toolbar button to add period to selected lines but it
> seems to demand adding a space after the period, which is not a problem,
> just less impactful.
>
> <$action-sendmessage $message="tm-edit-text-operation" $param="prefix-lines"
> character="." count="1" />
>
> I would also like a button that removes the period.
>
>
> Regards
>
> Tony
>
>
>
>
--
You received this message because you are subscribed to the Google Groups
"TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/tiddlywiki/614caa22-fd05-4ffa-9d19-d3b3a94dc763%40googlegroups.com.