-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathignore.ts
34 lines (32 loc) · 1.14 KB
/
ignore.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { Placeholder, PlaceholderCategory, PlaceholderType } from "../types";
/**
* Directive to ignore all content within the directive. Allows placeholders and directives to run without influencing the output.
*
* Syntax: `{{ignore:...}}`, where `...` is the content to ignore.
*/
const IgnoreDirective: Placeholder = {
name: "ignore",
regex: /{{(ignore|IGNORE):[^}]*?}}/g,
apply: async () => {
return { result: "" };
},
constant: false,
fn: async (content: unknown) => {
if (typeof content === "function") {
return (
await IgnoreDirective.apply(
`{{ignore:${await Promise.resolve(content())}}}`
)
).result;
}
return (await IgnoreDirective.apply(`{{ignore:${content}}}`)).result
},
example: '{{ignore:{{jxa:Application("Safari").activate()}}}}',
description:
"Directive to ignore all content within the directive. Allows placeholders and directives to run without influencing the output.",
hintRepresentation: "{{ignore:...}}",
fullRepresentation: "Ignore",
type: PlaceholderType.StaticDirective,
categories: [PlaceholderCategory.Meta],
};
export default IgnoreDirective;