Adds support for indenting pragmas with whitespace (#7185)

* feat: first pass at allowing pragmas to be indented

* Added documentation
This commit is contained in:
Saq Imtiaz 2023-01-08 14:17:01 +01:00 committed by GitHub
parent 7b7063a7b2
commit dd6e00687b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 117 additions and 7 deletions

View File

@ -25,7 +25,7 @@ Instantiate parse rule
exports.init = function(parser) {
this.parser = parser;
// Regexp to match
this.matchRegExp = /^\\import[^\S\n]/mg;
this.matchRegExp = /\\import[^\S\n]/mg;
};
/*

View File

@ -27,7 +27,7 @@ Instantiate parse rule
exports.init = function(parser) {
this.parser = parser;
// Regexp to match
this.matchRegExp = /^\\define\s+([^(\s]+)\(\s*([^)]*)\)(\s*\r?\n)?/mg;
this.matchRegExp = /\\define\s+([^(\s]+)\(\s*([^)]*)\)(\s*\r?\n)?/mg;
};
/*
@ -58,7 +58,7 @@ exports.parse = function() {
var reEnd;
if(this.match[3]) {
// If so, the end of the body is marked with \end
reEnd = new RegExp("(\\r?\\n\\\\end[^\\S\\n\\r]*(?:" + $tw.utils.escapeRegExp(this.match[1]) + ")?(?:$|\\r?\\n))","mg");
reEnd = new RegExp("(\\r?\\n\\s*\\\\end[^\\S\\n\\r]*(?:" + $tw.utils.escapeRegExp(this.match[1]) + ")?(?:$|\\r?\\n))","mg");
} else {
// Otherwise, the end of the definition is marked by the end of the line
reEnd = /($|\r?\n)/mg;

View File

@ -26,7 +26,7 @@ Instantiate parse rule
exports.init = function(parser) {
this.parser = parser;
// Regexp to match
this.matchRegExp = /^\\parsermode[^\S\n]/mg;
this.matchRegExp = /\\parsermode[^\S\n]/mg;
};
/*

View File

@ -26,7 +26,7 @@ Instantiate parse rule
exports.init = function(parser) {
this.parser = parser;
// Regexp to match
this.matchRegExp = /^\\rules[^\S\n]/mg;
this.matchRegExp = /\\rules[^\S\n]/mg;
};
/*

View File

@ -26,7 +26,7 @@ Instantiate parse rule
exports.init = function(parser) {
this.parser = parser;
// Regexp to match
this.matchRegExp = /^\\whitespace[^\S\n]/mg;
this.matchRegExp = /\\whitespace[^\S\n]/mg;
};
/*

View File

@ -0,0 +1,36 @@
title: Macros/NestedMacros-indented
description: Nested Macros-indented
type: text/vnd.tiddlywiki-multiple
tags: [[$:/tags/wiki-test-spec]]
title: Output
\whitespace trim
\define outer()
\whitespace trim
\define middle()
\whitespace trim
\define inner()
\whitespace trim
Jaguar
\end inner
<<inner>>
\end middle
<<middle>>
\end outer
<<outer>>
+
title: ExpectedResult
<p>Jaguar</p>

View File

@ -0,0 +1,36 @@
title: Macros/NestedMacros-indented2
description: Nested Macros-indented with spaces
type: text/vnd.tiddlywiki-multiple
tags: [[$:/tags/wiki-test-spec]]
title: Output
\whitespace trim
\define outer()
\whitespace trim
\define middle()
\whitespace trim
\define inner()
\whitespace trim
Jaguar
\end inner
<<inner>>
\end middle
<<middle>>
\end outer
<<outer>>
+
title: ExpectedResult
<p>Jaguar</p>

View File

@ -0,0 +1,36 @@
title: Pragmas/Parsermode-indented
description: parsermode pragma
type: text/vnd.tiddlywiki-multiple
tags: [[$:/tags/wiki-test-spec]]
title: Output
{{AlwaysInline}}
{{AlwaysBlock}}
{{AlwaysInline}}{{AlwaysBlock}}
+
title: AlwaysInline
\parsermode inline
! Not Heading
Text with ''bold''
+
title: AlwaysBlock
\parsermode block
! Heading
Text with ''bold''
+
title: ExpectedResult
! Not Heading
Text with <strong>bold</strong><h1 class="">Heading</h1><p>Text with <strong>bold</strong></p><p>! Not Heading
Text with <strong>bold</strong><h1 class="">Heading</h1><p>Text with <strong>bold</strong></p>
</p>

View File

@ -1,5 +1,5 @@
created: 20150219175930000
modified: 20220122182842041
modified: 20230107165037493
tags: Concepts [[WikiText Parser Modes]]
title: Pragma
type: text/vnd.tiddlywiki
@ -7,6 +7,8 @@ type: text/vnd.tiddlywiki
A <<.def pragma>> is a special component of WikiText that provides control over the way the remaining text is parsed.
Pragmas occupy lines that start with `\`. They can only appear at the start of the text, but blank lines are allowed between them. If a pragma line appears in the main body of the text, it is treated as if it was ordinary text.
<<.from-version "5.2.6">> Pragmas can have preceding optional whitespace characters.
The following pragmas are available: