Replies: 20 comments 5 replies
-
That's not how the TW parser tests for headings. See: |
Beta Was this translation helpful? Give feedback.
-
Thank you, I welcome your contribution! Unfortunately I know little JS. but this is a nice filter if it can accept different rules!
does this means I can pass Also as @pmario said, in Tiddlywiki we have
Yes, this is absolutely useful! Thank you |
Beta Was this translation helpful? Give feedback.
-
@pmario Thank you! I have changed the expressions of header checking.
@kookma Yes, It is possible to split tiddler with HTML tags, but there are some problems:
* Hello <div>
World
</div>!
So, I think there are some questions for us to discuss before adding this important rule. I also have another question. How does the plugin work? If I remove some blank lines and trim returned text (for example, Thanks all. Updated js code: JS Code/*\
title: $:/core/modules/filters/sectionsplit.js
type: application/javascript
module-type: filteroperator
creator: Gk0WK(nmg_wk @yeah.net)
Split sections of wikitext
\*/
(function() {
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
/*
Export our filter function
*/
exports.sectionsplit = function(source, operator, options) {
var splitOptions = {};
operator.operand.split('+').forEach(option => {
splitOptions[option] = true;
})
var results = [];
source(function(tiddler, title) {
var section = [];
title.split('\n').forEach(line => {
var newSection = false;
if ((splitOptions.all || splitOptions.h1) && /^!(\.[\w\-]+)?\s+[^\n]+$/.test(line)) {
newSection = true;
} else if ((splitOptions.all || splitOptions.h2) && /^!!(\.[\w\-]+)?\s+[^\n]+$/.test(line)) {
newSection = true;
} else if ((splitOptions.all || splitOptions.h3) && /^!!!(\.[\w\-]+)?\s+[^\n]+$/.test(line)) {
newSection = true;
} else if ((splitOptions.all || splitOptions.h4) && /^!!!!(\.[\w\-]+)?\s+[^\n]+$/.test(line)) {
newSection = true;
} else if ((splitOptions.all || splitOptions.h5) && /^!!!!!(\.[\w\-]+)?\s+[^\n]+$/.test(line)) {
newSection = true;
} else if ((splitOptions.all || splitOptions.h6) && /^!!!!!!(\.[\w\-]+)?\s+[^\n]+$/.test(line)) {
newSection = true;
} else if ((splitOptions.all || splitOptions.hr) && /^---+$/.test(line)) {
newSection = true;
} else if ((splitOptions.all || splitOptions.blank) && /^\s*$/.test(line)) {
newSection = true;
}
if (newSection && section.length > 0) {
results.push(section.join('\n').trim());
section = [];
}
section.push(line);
});
results.push(section.join('\n').trim());
});
return results;
};
})(); |
Beta Was this translation helpful? Give feedback.
-
@Gk0Wk thank you! I think for now
Next
but not any tag! |
Beta Was this translation helpful? Give feedback.
-
Hi @kookma ! I suddenly had a better idea to use TiddlyWiki's internal syntax parser to generate a document parse instead of writing one myself. This approach should allow for easier and more flexible segmentation (including the features mentioned above). I'll try this approach when I have time. |
Beta Was this translation helpful? Give feedback.
-
That would be great! I appreciate if you could give me a short working example! |
Beta Was this translation helpful? Give feedback.
-
@kookma Hi. I'm sorry to inform you that the TiddlyWiki core parser does not parse results with substring location information, which makes the syntax tree unusable for splitting sections. I think a better way is still to write a separate syntax parser. As it happens, I am implementing such a parser in my TW5-CodeMirror-Enhanced project, and if I finish a simple parser I will try to use it in BTW, I encountered some problems in using case 1:
case 2: ``` ! a ``` |
Beta Was this translation helpful? Give feedback.
-
Lovely, I am sure the
Yes, I am aware of this and will add this in documentation! That is why I raised the definition of tiddlers in Talk Tiddlywiki! Section Editor best works for plain tiddler!
do you have a workaround for this? In documentation I recommend to use |
Beta Was this translation helpful? Give feedback.
-
@Gk0Wk - now we have TiddlyWiki/TiddlyWiki5#4977 merged! |
Beta Was this translation helpful? Give feedback.
-
@kookma Sure, we can. I've done some experimentation and even without this updated parser, the text can be properly sectioned. The question is, how do I get this information to you? I think you need information that includes at least substrings, start and end position information, and the type of section (e.g. title or paragraph), but the filter only returns a number of strings, which is confusing to me. |
Beta Was this translation helpful? Give feedback.
-
@kookma It doesn't matter, I'm busy too. lol I modified the code of the filter according to your suggestion and now it works properly as follows.
This filter takes the text of the tiddler and splits the text according to certain rules. if the rule is empty it means that all rules are used. The currently supported rules are as follows.
Usage: Separate the rule names with
And the filter will return all substrings that are split. Note: The first substring returned by the filter is always the parameter part at the beginning of the tiddler (consisting of I have applied for a PR, which contains the latest filter scripts. |
Beta Was this translation helpful? Give feedback.
-
Thank you @Marxsal. There are some issues and there is missing code to include this in the UI I highly welcome your contribution and help! |
Beta Was this translation helpful? Give feedback.
-
No! but it is a good improvement. |
Beta Was this translation helpful? Give feedback.
-
Is this proceeding, it would be a great feature in the next release? |
Beta Was this translation helpful? Give feedback.
-
No, May be @Gk0Wk wants to implement this. |
Beta Was this translation helpful? Give feedback.
-
Of course a custom filter operator can be delivered as a package or plugin?
|
Beta Was this translation helpful? Give feedback.
-
I'm thinking that the approach used in the first Post, once expanded, might be more compatible between versions of TW? |
Beta Was this translation helpful? Give feedback.
-
A new feature is soon to be merged, which will map the start and end positions in the text for each section of the complete Wiki syntax tree. Therefore, this should be feasible in the future.
|
Beta Was this translation helpful? Give feedback.
-
Hi @Gk0Wk |
Beta Was this translation helpful? Give feedback.
-
It seems that my feature has not been merged yet (in v5.3.3); I am continuing to wait for the release of a new version. I have already rewritten part of the core and implemented a demo of a block editor, which you can test here: https://gk0wk.github.io/TiddlySeq/#TestForSectionEditor |
Beta Was this translation helpful? Give feedback.
-
Hello! Earlier in the TiddlyWiki Talk, I mentioned that I would like to be able to segment tiddlers not only based on first and second-level headers, but also in a more flexible way. After that, I tried to write a custom filter to achieve this.
First, add a new tiddler to define the new filter:
This toddler also has:
type
:application/javascript
module-type
field:filteroperator
title
:$:/core/modules/filters/sectionsplit.js
Then, change the filter expression in line 11 of source/section/macros/main.tid to
[<sourceText>sectionsplit[h1+h2+h3]!is[blank]regexp<nonWhitespace>]
.Then
TW-Section
can split toddler byh1
,h2
andh3
. You can change it to[h1+h2+h3+h4]
and so on to take more split rules. Now this filter support:h1
~h6
hr
blank
, means blank lineall
, means all aboveIf you think this filter is useful, I can add more rules to it. 😄
Beta Was this translation helpful? Give feedback.
All reactions