1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-30 05:19:57 +00:00

Block Quotes - fix parsing error with spaces before reEndString (#8186)

* fix parsing error with spaces before reEndString, update docs to clarify block mode inside block quotes.

* additional advanced example

* oops, convert spaces back to tabs.

* reset indentation

* final tabs

* missed some

* wikitext classes are appended to other leading wikitext, no need to skip whitespace here.
This commit is contained in:
Joshua Fontany 2024-05-15 04:25:02 -07:00 committed by GitHub
parent 0b475628de
commit f1299120a6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 44 additions and 33 deletions

View File

@ -3,30 +3,7 @@ title: $:/core/modules/parsers/wikiparser/rules/quoteblock.js
type: application/javascript type: application/javascript
module-type: wikirule module-type: wikirule
Wiki text rule for quote blocks. For example: Wiki text rule for quote blocks.
```
<<<.optionalClass(es) optional cited from
a quote
<<<
<<<.optionalClass(es)
a quote
<<< optional cited from
```
Quotes can be quoted by putting more <s
```
<<<
Quote Level 1
<<<<
QuoteLevel 2
<<<<
<<<
```
\*/ \*/
(function(){ (function(){
@ -47,16 +24,15 @@ exports.init = function(parser) {
exports.parse = function() { exports.parse = function() {
var classes = ["tc-quote"]; var classes = ["tc-quote"];
// Get all the details of the match // Get all the details of the match
var reEndString = "^" + this.match[1] + "(?!<)"; var reEndString = "^\\s*" + this.match[1] + "(?!<)";
// Move past the <s // Move past the <s
this.parser.pos = this.matchRegExp.lastIndex; this.parser.pos = this.matchRegExp.lastIndex;
// Parse any classes, whitespace and then the optional cite itself // Parse any classes, whitespace and then the optional cite itself
classes.push.apply(classes, this.parser.parseClasses()); classes.push.apply(classes, this.parser.parseClasses());
this.parser.skipWhitespace({treatNewlinesAsNonWhitespace: true}); this.parser.skipWhitespace({treatNewlinesAsNonWhitespace: true});
var cite = this.parser.parseInlineRun(/(\r?\n)/mg); var cite = this.parser.parseInlineRun(/(\r?\n)/mg);
// before handling the cite, parse the body of the quote // before handling the cite, parse the body of the quote
var tree= this.parser.parseBlocks(reEndString); var tree = this.parser.parseBlocks(reEndString);
// If we got a cite, put it before the text // If we got a cite, put it before the text
if(cite.length > 0) { if(cite.length > 0) {
tree.unshift({ tree.unshift({

View File

@ -1,6 +1,6 @@
caption: Block Quotes caption: Block Quotes
created: 20131206154636572 created: 20131206154636572
modified: 20170417165145317 modified: 20240512000910702
tags: WikiText tags: WikiText
title: Block Quotes in WikiText title: Block Quotes in WikiText
type: text/vnd.tiddlywiki type: text/vnd.tiddlywiki
@ -72,3 +72,34 @@ You can also mix block quotes with other list items. For example:
**> Another quote **> Another quote
* List Three * List Three
">> ">>
! Advanced Wikitext and Block Quotes
You can also mix block quotes with paragraphs and other block wikitext. Be mindful of block mode - if other quoted content follows a paragraph, end it with a blank line. The final paragraph in the quote does not need to end with a blank line. If using indentation, make sure __not to indent the blank lines__. The parser will interpret this as additional inline content and not return to block mode. For example:
<<wikitext-example src:'<<< Mixing Block Quotes with Inline Wikitext
A paragraph appears before other //wikitext//, which needs to end with a blank line.
* List One
** List Two
**> A quote
"""
A poem
with line beaks
needs to have
a blank line after
the final quotes
if followed
by other content
"""
<<<< Deep Block Quote
A paragraph before other //wikitext//, which ends with a blank line.
! A Header
Another paragraph, which needs to end with a blank line.
!! Sub Header
A final paragraph, which __does not__ need to end with a blank line as the Block Quote ends.
<<<<
<<<
'>>

View File

@ -1,9 +1,9 @@
caption: Hard Linebreaks
created: 20131214165710101 created: 20131214165710101
modified: 20131214170106553 modified: 20240512001649319
tags: WikiText tags: WikiText
title: Hard Linebreaks in WikiText title: Hard Linebreaks in WikiText
type: text/vnd.tiddlywiki type: text/vnd.tiddlywiki
caption: Hard Linebreaks
The usual handling of [[paragraphs in wikitext|Paragraphs in WikiText]] causes single line breaks to be ignored, and double linebreaks to be interpreted as the end of a paragraph. The usual handling of [[paragraphs in wikitext|Paragraphs in WikiText]] causes single line breaks to be ignored, and double linebreaks to be interpreted as the end of a paragraph.
@ -15,4 +15,8 @@ and this is a new line
while this is yet another line while this is yet another line
and this is the final one and this is the final one
apart from this one apart from this one
"""'>> """
'>>
<<.tip 'Note: <strong>Hard Linebreaks in ~WikiText</strong> require an extra blank line after the trailing `"""` before the parser will return to [[block mode|Block Mode WikiText]].'>>.

View File

@ -1,6 +1,6 @@
caption: block parser mode caption: block parser mode
created: 20220110234234616 created: 20220110234234616
modified: 20220122182842032 modified: 20240512001555383
tags: [[WikiText Parser Modes]] tags: [[WikiText Parser Modes]]
title: Block Mode WikiText title: Block Mode WikiText
type: text/vnd.tiddlywiki type: text/vnd.tiddlywiki
@ -28,7 +28,7 @@ Common characteristics of such block mode WikiText:
The above WikiText types are only recognised in ''block mode''. However, the text <<.em enclosed>> by most of them will be parsed in ''inline mode'' ([[Block Quotes in WikiText]] and [[Styles and Classes in WikiText]] are the two exceptions in which the parser will continue in ''block mode''). While in ''inline mode'' the parser may encounter something which moves it to ''block mode'' (see [[WikiText parser mode transitions]]). The above WikiText types are only recognised in ''block mode''. However, the text <<.em enclosed>> by most of them will be parsed in ''inline mode'' ([[Block Quotes in WikiText]] and [[Styles and Classes in WikiText]] are the two exceptions in which the parser will continue in ''block mode''). While in ''inline mode'' the parser may encounter something which moves it to ''block mode'' (see [[WikiText parser mode transitions]]).
At the end of the terminating line, the parser will return to ''block mode''. At the end of the terminating line, the parser will return to ''block mode''.
<<.tip 'Note: [[Hard Linebreaks in WikiText]] require an extra blank line after the trailing `"""` before the parser will return to <b>block mode</b>'>>. <<.tip 'Note: [[Hard Linebreaks in WikiText]] require an extra blank line after the trailing `"""` before the parser will return to <strong>block mode</strong>.'>>
If the punctuation for the above types of WikiText is encountered while the parser is in ''inline mode'', it will be //ignored// and output as-is. If the punctuation for the above types of WikiText is encountered while the parser is in ''inline mode'', it will be //ignored// and output as-is.