UNPKG

discord-markdown-parser

Version:

Parse discord-style markdown into an abstract syntax tree.

36 lines (35 loc) 1.32 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.slashCommand = void 0; const simple_markdown_1 = __importDefault(require("../../simple-markdown")); const regex_1 = require("../../utils/regex"); exports.slashCommand = { order: simple_markdown_1.default.defaultRules.strong.order, match: (source) => regex_1.SlashCommandRegex.exec(source), parse: function (capture) { // Commands can come in three variants: // 1. /command // 2. /command subcommand // 3. /command subcommand-group subcommand const commandParts = capture[1].split(' '); const returnValue = { fullName: capture[1], name: commandParts[0], subcommand: null, subcommandGroup: null, id: capture[2], }; // length of 2 means no subcommand group if (commandParts.length == 2) { returnValue.subcommand = commandParts[1]; } if (commandParts.length === 3) { returnValue.subcommandGroup = commandParts[1]; returnValue.subcommand = commandParts[2]; } return returnValue; }, };