add escapes to formatters
This commit is contained in:
parent
767b431022
commit
0523a79b4a
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@squeebot/core",
|
"name": "@squeebot/core",
|
||||||
"version": "3.6.0-1",
|
"version": "3.6.1",
|
||||||
"description": "Squeebot v3 core for the execution environment",
|
"description": "Squeebot v3 core for the execution environment",
|
||||||
"main": "lib/index.js",
|
"main": "lib/index.js",
|
||||||
"types": "lib/index.d.ts",
|
"types": "lib/index.d.ts",
|
||||||
|
@ -123,6 +123,9 @@ export class Formatter {
|
|||||||
*/
|
*/
|
||||||
public colorEscape = '';
|
public colorEscape = '';
|
||||||
|
|
||||||
|
/** Replacements for string escape function */
|
||||||
|
public escapeReplacements: [RegExp, string, string][] = [];
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
/**
|
/**
|
||||||
* @deprecated Use feature flags
|
* @deprecated Use feature flags
|
||||||
@ -167,10 +170,27 @@ export class Formatter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Strip any extraneous tags/info.
|
||||||
|
* @param msg Message
|
||||||
|
* @returns Stripped message
|
||||||
|
*/
|
||||||
public strip(msg: string): string {
|
public strip(msg: string): string {
|
||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Escape any extraneous tags/info.
|
||||||
|
* @param msg Message
|
||||||
|
* @returns Escaped message
|
||||||
|
*/
|
||||||
|
public escape(msg: string): string {
|
||||||
|
return this.escapeReplacements.reduce(
|
||||||
|
(str, replacement) => str.replace(replacement[0], replacement[1]),
|
||||||
|
msg
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Object compositor.
|
* Object compositor.
|
||||||
*
|
*
|
||||||
@ -284,6 +304,14 @@ export class HTMLFormatter extends Formatter {
|
|||||||
multicode: {start: '<pre><code>', end: '</code></pre>'},
|
multicode: {start: '<pre><code>', end: '</code></pre>'},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
public escapeReplacements: [RegExp, string, string][] = [
|
||||||
|
[/&/g, '&', 'ampersand'],
|
||||||
|
[/</g, '<', 'angle brackets'],
|
||||||
|
[/>/g, '>', 'angle brackets'],
|
||||||
|
[/"/g, '"', 'quotes'],
|
||||||
|
[/'/g, ''', 'single quates'],
|
||||||
|
];
|
||||||
|
|
||||||
constructor(flags?: ProtocolFeatureFlag[]) {
|
constructor(flags?: ProtocolFeatureFlag[]) {
|
||||||
super(true, true, flags);
|
super(true, true, flags);
|
||||||
}
|
}
|
||||||
@ -323,6 +351,20 @@ export class MarkdownFormatter extends Formatter {
|
|||||||
multicode: {start: '```', end: '```'},
|
multicode: {start: '```', end: '```'},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
public escapeReplacements: [RegExp, string, string][] = [
|
||||||
|
[/\*/g, '\\*', 'asterisks'],
|
||||||
|
[/#/g, '\\#', 'number signs'],
|
||||||
|
[/\//g, '\\/', 'slashes'],
|
||||||
|
[/\(/g, '\\(', 'parentheses'],
|
||||||
|
[/\)/g, '\\)', 'parentheses'],
|
||||||
|
[/\[/g, '\\[', 'square brackets'],
|
||||||
|
[/\]/g, '\\]', 'square brackets'],
|
||||||
|
[/</g, '<', 'angle brackets'],
|
||||||
|
[/>/g, '>', 'angle brackets'],
|
||||||
|
[/_/g, '\\_', 'underscores'],
|
||||||
|
[/`/g, '\\`', 'codeblocks']
|
||||||
|
];
|
||||||
|
|
||||||
constructor(flags?: ProtocolFeatureFlag[]) {
|
constructor(flags?: ProtocolFeatureFlag[]) {
|
||||||
super(true, false, flags);
|
super(true, false, flags);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user