Add rawQuotes to override with named arg (#4032)

36dfbd4cbeace517ca47563b1d3b6864d741abbf

Cohee <18619528+Cohee1207@users.noreply.github.com>

Signed
3 files changed, +45 -3Ignore whitespace
public/scripts/slash-commands.js+40 -0
@@ -266,6 +266,14 @@ export function initDefaultSlashCommands() {
266266 enumList: slashCommandReturnHelper.enumList({ allowObject: true }),
267267 forceEnum: true,
268268 }),
269+ SlashCommandNamedArgument.fromProps({
270+ name: 'raw',
271+ description: 'If true, does not alter quoted literal unnamed arguments',
272+ typeList: [ARGUMENT_TYPE.BOOLEAN],
273+ defaultValue: 'true',
274+ enumProvider: commonEnumProviders.boolean('trueFalse'),
275+ isRequired: false,
276+ }),
269277 ],
270278 unnamedArgumentList: [
271279 new SlashCommandArgument(
@@ -328,6 +336,14 @@ export function initDefaultSlashCommands() {
328336 enumList: slashCommandReturnHelper.enumList({ allowObject: true }),
329337 forceEnum: true,
330338 }),
339+ SlashCommandNamedArgument.fromProps({
340+ name: 'raw',
341+ description: 'If true, does not alter quoted literal unnamed arguments',
342+ typeList: [ARGUMENT_TYPE.BOOLEAN],
343+ defaultValue: 'true',
344+ enumProvider: commonEnumProviders.boolean('trueFalse'),
345+ isRequired: false,
346+ }),
331347 ],
332348 unnamedArgumentList: [
333349 new SlashCommandArgument(
@@ -392,6 +408,14 @@ export function initDefaultSlashCommands() {
392408 enumList: slashCommandReturnHelper.enumList({ allowObject: true }),
393409 forceEnum: true,
394410 }),
411+ SlashCommandNamedArgument.fromProps({
412+ name: 'raw',
413+ description: 'If true, does not alter quoted literal unnamed arguments',
414+ typeList: [ARGUMENT_TYPE.BOOLEAN],
415+ defaultValue: 'true',
416+ enumProvider: commonEnumProviders.boolean('trueFalse'),
417+ isRequired: false,
418+ }),
395419 ],
396420 unnamedArgumentList: [
397421 new SlashCommandArgument(
@@ -617,6 +641,14 @@ export function initDefaultSlashCommands() {
617641 enumList: slashCommandReturnHelper.enumList({ allowObject: true }),
618642 forceEnum: true,
619643 }),
644+ SlashCommandNamedArgument.fromProps({
645+ name: 'raw',
646+ description: 'If true, does not alter quoted literal unnamed arguments',
647+ typeList: [ARGUMENT_TYPE.BOOLEAN],
648+ defaultValue: 'true',
649+ enumProvider: commonEnumProviders.boolean('trueFalse'),
650+ isRequired: false,
651+ }),
620652 ],
621653 unnamedArgumentList: [
622654 new SlashCommandArgument(
@@ -1013,6 +1045,14 @@ export function initDefaultSlashCommands() {
10131045 description: 'a closure to call when the toast is clicked. This executed closure receives scope as provided in the script. Careful about possible side effects when manipulating variables and more.',
10141046 typeList: [ARGUMENT_TYPE.CLOSURE],
10151047 }),
1048+ SlashCommandNamedArgument.fromProps({
1049+ name: 'raw',
1050+ description: 'If true, does not alter quoted literal unnamed arguments',
1051+ typeList: [ARGUMENT_TYPE.BOOLEAN],
1052+ defaultValue: 'true',
1053+ enumProvider: commonEnumProviders.boolean('trueFalse'),
1054+ isRequired: false,
1055+ }),
10161056 ],
10171057 unnamedArgumentList: [
10181058 new SlashCommandArgument(
public/scripts/slash-commands/SlashCommand.js+1 -1
@@ -266,7 +266,7 @@ export class SlashCommand {
266266 rawQuotes.classList.add('rawQuotes');
267267 rawQuotes.classList.add('fa-solid');
268268 rawQuotes.classList.add('fa-quote-left');
269269 rawQuotes.title = t`Does not alter quoted literal unnamed arguments. Pass raw=false argument to override.`;
270270 head.append(rawQuotes);
271271 }
272272 }
public/scripts/slash-commands/SlashCommandParser.js+4 -2
@@ -1,6 +1,6 @@
11import { hljs } from '../../lib.js';
22import { power_user } from '../power-user.js';
33import { isFalseBoolean, isTrueBoolean, uuidv4 } from '../utils.js';
44import { SlashCommand } from './SlashCommand.js';
55import { ARGUMENT_TYPE, SlashCommandArgument } from './SlashCommandArgument.js';
66import { SlashCommandClosure } from './SlashCommandClosure.js';
@@ -975,7 +975,9 @@ export class SlashCommandParser {
975975 cmd.startUnnamedArgs = this.index - (/\s(\s*)$/s.exec(this.behind)?.[1]?.length ?? 0);
976976 cmd.endUnnamedArgs = this.index;
977977 if (this.testUnnamedArgument()) {
978- cmd.unnamedArgumentList = this.parseUnnamedArgument(cmd.command?.unnamedArgumentList?.length && cmd?.command?.splitUnnamedArgument, cmd?.command?.splitUnnamedArgumentCount, cmd?.command?.rawQuotes);
978+ const rawQuotesArg = cmd?.namedArgumentList?.find(a => a.name === 'raw');
979+ const rawQuotes = cmd?.command?.rawQuotes && rawQuotesArg ? !isFalseBoolean(rawQuotesArg?.value?.toString()) : cmd?.command?.rawQuotes;
980+ cmd.unnamedArgumentList = this.parseUnnamedArgument(cmd.command?.unnamedArgumentList?.length && cmd?.command?.splitUnnamedArgument, cmd?.command?.splitUnnamedArgumentCount, rawQuotes);
979981 cmd.endUnnamedArgs = this.index;
980982 if (cmd.name == 'let') {
981983 const keyArg = cmd.namedArgumentList.find(it=>it.name == 'key');