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() {
266 enumList: slashCommandReturnHelper.enumList({ allowObject: true }),266 enumList: slashCommandReturnHelper.enumList({ allowObject: true }),
267 forceEnum: true,267 forceEnum: true,
268 }),268 }),
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 }),
269 ],277 ],
270 unnamedArgumentList: [278 unnamedArgumentList: [
271 new SlashCommandArgument(279 new SlashCommandArgument(
@@ -328,6 +336,14 @@ export function initDefaultSlashCommands() {
328 enumList: slashCommandReturnHelper.enumList({ allowObject: true }),336 enumList: slashCommandReturnHelper.enumList({ allowObject: true }),
329 forceEnum: true,337 forceEnum: true,
330 }),338 }),
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 }),
331 ],347 ],
332 unnamedArgumentList: [348 unnamedArgumentList: [
333 new SlashCommandArgument(349 new SlashCommandArgument(
@@ -392,6 +408,14 @@ export function initDefaultSlashCommands() {
392 enumList: slashCommandReturnHelper.enumList({ allowObject: true }),408 enumList: slashCommandReturnHelper.enumList({ allowObject: true }),
393 forceEnum: true,409 forceEnum: true,
394 }),410 }),
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 }),
395 ],419 ],
396 unnamedArgumentList: [420 unnamedArgumentList: [
397 new SlashCommandArgument(421 new SlashCommandArgument(
@@ -617,6 +641,14 @@ export function initDefaultSlashCommands() {
617 enumList: slashCommandReturnHelper.enumList({ allowObject: true }),641 enumList: slashCommandReturnHelper.enumList({ allowObject: true }),
618 forceEnum: true,642 forceEnum: true,
619 }),643 }),
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 }),
620 ],652 ],
621 unnamedArgumentList: [653 unnamedArgumentList: [
622 new SlashCommandArgument(654 new SlashCommandArgument(
@@ -1013,6 +1045,14 @@ export function initDefaultSlashCommands() {
1013 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.',1045 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.',
1014 typeList: [ARGUMENT_TYPE.CLOSURE],1046 typeList: [ARGUMENT_TYPE.CLOSURE],
1015 }),1047 }),
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 }),
1016 ],1056 ],
1017 unnamedArgumentList: [1057 unnamedArgumentList: [
1018 new SlashCommandArgument(1058 new SlashCommandArgument(
public/scripts/slash-commands/SlashCommand.js+1 -1
@@ -266,7 +266,7 @@ export class SlashCommand {
266 rawQuotes.classList.add('rawQuotes');266 rawQuotes.classList.add('rawQuotes');
267 rawQuotes.classList.add('fa-solid');267 rawQuotes.classList.add('fa-solid');
268 rawQuotes.classList.add('fa-quote-left');268 rawQuotes.classList.add('fa-quote-left');
269 rawQuotes.title = t`Does not alter quoted literal unnamed arguments`;269 rawQuotes.title = t`Does not alter quoted literal unnamed arguments. Pass raw=false argument to override.`;
270 head.append(rawQuotes);270 head.append(rawQuotes);
271 }271 }
272 }272 }
public/scripts/slash-commands/SlashCommandParser.js+4 -2
@@ -1,6 +1,6 @@
1import { hljs } from '../../lib.js';1import { hljs } from '../../lib.js';
2import { power_user } from '../power-user.js';2import { power_user } from '../power-user.js';
3import { isTrueBoolean, uuidv4 } from '../utils.js';3import { isFalseBoolean, isTrueBoolean, uuidv4 } from '../utils.js';
4import { SlashCommand } from './SlashCommand.js';4import { SlashCommand } from './SlashCommand.js';
5import { ARGUMENT_TYPE, SlashCommandArgument } from './SlashCommandArgument.js';5import { ARGUMENT_TYPE, SlashCommandArgument } from './SlashCommandArgument.js';
6import { SlashCommandClosure } from './SlashCommandClosure.js';6import { SlashCommandClosure } from './SlashCommandClosure.js';
@@ -975,7 +975,9 @@ export class SlashCommandParser {
975 cmd.startUnnamedArgs = this.index - (/\s(\s*)$/s.exec(this.behind)?.[1]?.length ?? 0);975 cmd.startUnnamedArgs = this.index - (/\s(\s*)$/s.exec(this.behind)?.[1]?.length ?? 0);
976 cmd.endUnnamedArgs = this.index;976 cmd.endUnnamedArgs = this.index;
977 if (this.testUnnamedArgument()) {977 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);
979 cmd.endUnnamedArgs = this.index;981 cmd.endUnnamedArgs = this.index;
980 if (cmd.name == 'let') {982 if (cmd.name == 'let') {
981 const keyArg = cmd.namedArgumentList.find(it=>it.name == 'key');983 const keyArg = cmd.namedArgumentList.find(it=>it.name == 'key');