@itrocks/template 0.0.33 → 0.0.34
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/template.d.ts +2 -1
- package/cjs/template.js +9 -2
- package/esm/template.d.ts +2 -1
- package/esm/template.js +9 -2
- package/package.json +1 -1
package/cjs/template.d.ts
CHANGED
@@ -28,6 +28,7 @@ export declare class Template {
|
|
28
28
|
inLiteral: boolean;
|
29
29
|
}[];
|
30
30
|
target: string;
|
31
|
+
targetReplace: string;
|
31
32
|
targetStack: string[];
|
32
33
|
doLiteral: boolean;
|
33
34
|
inLiteral: boolean;
|
@@ -92,7 +93,7 @@ export declare class Template {
|
|
92
93
|
target: string;
|
93
94
|
targetStack: string[];
|
94
95
|
};
|
95
|
-
include(path: string, data: any): Promise<
|
96
|
+
include(path: string, data: any): Promise<string>;
|
96
97
|
isContextClean(): boolean;
|
97
98
|
literalTarget(index: number, isTitle?: boolean): void;
|
98
99
|
parseBuffer(buffer: string): Promise<string>;
|
package/cjs/template.js
CHANGED
@@ -23,6 +23,7 @@ class Template {
|
|
23
23
|
tagName = '';
|
24
24
|
tagStack = [];
|
25
25
|
target = '';
|
26
|
+
targetReplace = '';
|
26
27
|
targetStack = [];
|
27
28
|
// literal
|
28
29
|
doLiteral = false;
|
@@ -174,6 +175,12 @@ class Template {
|
|
174
175
|
this.headLinks.push(...template.headLinks);
|
175
176
|
const beginPosition = parsed.indexOf('<!--BEGIN-->');
|
176
177
|
const endPosition = parsed.indexOf('<!--END-->');
|
178
|
+
if ((beginPosition === -1) && (parsed[1] === '!') && parsed.startsWith('<!DOCTYPE html>')) {
|
179
|
+
if (this.targetReplace === '') {
|
180
|
+
this.targetReplace = parsed;
|
181
|
+
}
|
182
|
+
return '';
|
183
|
+
}
|
177
184
|
return (beginPosition > -1)
|
178
185
|
? parsed.slice(beginPosition + 12, (endPosition > -1) ? endPosition : parsed.length)
|
179
186
|
: parsed;
|
@@ -230,7 +237,7 @@ class Template {
|
|
230
237
|
+ this.headTitle
|
231
238
|
+ this.target.slice(this.target.indexOf('</title>', position));
|
232
239
|
}
|
233
|
-
return this.target;
|
240
|
+
return (this.targetReplace !== '') ? this.targetReplace : this.target;
|
234
241
|
}
|
235
242
|
async parseExpression(data, open, close, finalClose = '') {
|
236
243
|
const indexOut = this.index;
|
@@ -815,7 +822,7 @@ class Template {
|
|
815
822
|
this.start = this.index;
|
816
823
|
}
|
817
824
|
startsExpression(char, open = '{', close = '}') {
|
818
|
-
return RegExp(
|
825
|
+
return RegExp(`[a-z0-9"'*./?` + open + close + this.prefixes + ']', 'i').test(char);
|
819
826
|
}
|
820
827
|
trimEndLine(string) {
|
821
828
|
let index = string.length;
|
package/esm/template.d.ts
CHANGED
@@ -28,6 +28,7 @@ export declare class Template {
|
|
28
28
|
inLiteral: boolean;
|
29
29
|
}[];
|
30
30
|
target: string;
|
31
|
+
targetReplace: string;
|
31
32
|
targetStack: string[];
|
32
33
|
doLiteral: boolean;
|
33
34
|
inLiteral: boolean;
|
@@ -92,7 +93,7 @@ export declare class Template {
|
|
92
93
|
target: string;
|
93
94
|
targetStack: string[];
|
94
95
|
};
|
95
|
-
include(path: string, data: any): Promise<
|
96
|
+
include(path: string, data: any): Promise<string>;
|
96
97
|
isContextClean(): boolean;
|
97
98
|
literalTarget(index: number, isTitle?: boolean): void;
|
98
99
|
parseBuffer(buffer: string): Promise<string>;
|
package/esm/template.js
CHANGED
@@ -20,6 +20,7 @@ export class Template {
|
|
20
20
|
tagName = '';
|
21
21
|
tagStack = [];
|
22
22
|
target = '';
|
23
|
+
targetReplace = '';
|
23
24
|
targetStack = [];
|
24
25
|
// literal
|
25
26
|
doLiteral = false;
|
@@ -171,6 +172,12 @@ export class Template {
|
|
171
172
|
this.headLinks.push(...template.headLinks);
|
172
173
|
const beginPosition = parsed.indexOf('<!--BEGIN-->');
|
173
174
|
const endPosition = parsed.indexOf('<!--END-->');
|
175
|
+
if ((beginPosition === -1) && (parsed[1] === '!') && parsed.startsWith('<!DOCTYPE html>')) {
|
176
|
+
if (this.targetReplace === '') {
|
177
|
+
this.targetReplace = parsed;
|
178
|
+
}
|
179
|
+
return '';
|
180
|
+
}
|
174
181
|
return (beginPosition > -1)
|
175
182
|
? parsed.slice(beginPosition + 12, (endPosition > -1) ? endPosition : parsed.length)
|
176
183
|
: parsed;
|
@@ -227,7 +234,7 @@ export class Template {
|
|
227
234
|
+ this.headTitle
|
228
235
|
+ this.target.slice(this.target.indexOf('</title>', position));
|
229
236
|
}
|
230
|
-
return this.target;
|
237
|
+
return (this.targetReplace !== '') ? this.targetReplace : this.target;
|
231
238
|
}
|
232
239
|
async parseExpression(data, open, close, finalClose = '') {
|
233
240
|
const indexOut = this.index;
|
@@ -812,7 +819,7 @@ export class Template {
|
|
812
819
|
this.start = this.index;
|
813
820
|
}
|
814
821
|
startsExpression(char, open = '{', close = '}') {
|
815
|
-
return RegExp(
|
822
|
+
return RegExp(`[a-z0-9"'*./?` + open + close + this.prefixes + ']', 'i').test(char);
|
816
823
|
}
|
817
824
|
trimEndLine(string) {
|
818
825
|
let index = string.length;
|
package/package.json
CHANGED