From 5e96b4c4771a35edb47a9942445d05db0b17c9fd Mon Sep 17 00:00:00 2001 From: Mayuran Visakan Date: Wed, 30 Aug 2023 22:11:32 +0100 Subject: [PATCH] Temp delete --- src/External/ExecuteCode/CodeBlockArgs.ts | 54 ----------------------- src/external/executeCode/CodeBlockArgs.ts | 54 ----------------------- 2 files changed, 108 deletions(-) delete mode 100644 src/External/ExecuteCode/CodeBlockArgs.ts delete mode 100644 src/external/executeCode/CodeBlockArgs.ts diff --git a/src/External/ExecuteCode/CodeBlockArgs.ts b/src/External/ExecuteCode/CodeBlockArgs.ts deleted file mode 100644 index f3bb50f..0000000 --- a/src/External/ExecuteCode/CodeBlockArgs.ts +++ /dev/null @@ -1,54 +0,0 @@ -import {Notice} from "obsidian"; -import * as JSON5 from "json5"; - -export type ExportType = "pre" | "post"; - -/** - * Arguments for code blocks, specified next to the language identifier as JSON - * @example ```python {"export": "pre"} - * @example ```cpp {"ignoreExport": ["post"]} - */ -export interface CodeBlockArgs { - label?: string; - import?: string | string[]; - export?: ExportType | ExportType[]; - ignore?: (ExportType | "global")[] | ExportType | "global" | "all"; -} - -/** - * Get code block args given the first line of the code block. - * - * @param firstLineOfCode The first line of a code block that contains the language name. - * @returns The arguments from the first line of the code block. - */ -export function getArgs(firstLineOfCode: string): CodeBlockArgs { - // No args specified - if (!firstLineOfCode.contains("{") && !firstLineOfCode.contains("}")) - return {}; - try { - let args = firstLineOfCode.substring(firstLineOfCode.indexOf("{") + 1).trim(); - // Transform custom syntax to JSON5 - args = args.replace(/=/g, ":"); - // Handle unnamed export arg - pre / post at the beginning of the args without any arg name - const exports: ExportType[] = []; - const handleUnnamedExport = (exportName: ExportType) => { - let i = args.indexOf(exportName); - while (i !== -1) { - const nextChar = args[i + exportName.length]; - if (nextChar !== "\"" && nextChar !== "'") { - // Remove from args string - args = args.substring(0, i) + args.substring(i + exportName.length + (nextChar === "}" ? 0 : 1)); - exports.push(exportName); - } - i = args.indexOf(exportName, i + 1); - } - }; - handleUnnamedExport("pre"); - handleUnnamedExport("post"); - args = `{export: ['${exports.join("', '")}'], ${args}`; - return JSON5.parse(args); - } catch (err) { - new Notice(`Failed to parse code block arguments from line:\n${firstLineOfCode}\n\nFailed with error:\n${err}`); - return {}; - } -} diff --git a/src/external/executeCode/CodeBlockArgs.ts b/src/external/executeCode/CodeBlockArgs.ts deleted file mode 100644 index f3bb50f..0000000 --- a/src/external/executeCode/CodeBlockArgs.ts +++ /dev/null @@ -1,54 +0,0 @@ -import {Notice} from "obsidian"; -import * as JSON5 from "json5"; - -export type ExportType = "pre" | "post"; - -/** - * Arguments for code blocks, specified next to the language identifier as JSON - * @example ```python {"export": "pre"} - * @example ```cpp {"ignoreExport": ["post"]} - */ -export interface CodeBlockArgs { - label?: string; - import?: string | string[]; - export?: ExportType | ExportType[]; - ignore?: (ExportType | "global")[] | ExportType | "global" | "all"; -} - -/** - * Get code block args given the first line of the code block. - * - * @param firstLineOfCode The first line of a code block that contains the language name. - * @returns The arguments from the first line of the code block. - */ -export function getArgs(firstLineOfCode: string): CodeBlockArgs { - // No args specified - if (!firstLineOfCode.contains("{") && !firstLineOfCode.contains("}")) - return {}; - try { - let args = firstLineOfCode.substring(firstLineOfCode.indexOf("{") + 1).trim(); - // Transform custom syntax to JSON5 - args = args.replace(/=/g, ":"); - // Handle unnamed export arg - pre / post at the beginning of the args without any arg name - const exports: ExportType[] = []; - const handleUnnamedExport = (exportName: ExportType) => { - let i = args.indexOf(exportName); - while (i !== -1) { - const nextChar = args[i + exportName.length]; - if (nextChar !== "\"" && nextChar !== "'") { - // Remove from args string - args = args.substring(0, i) + args.substring(i + exportName.length + (nextChar === "}" ? 0 : 1)); - exports.push(exportName); - } - i = args.indexOf(exportName, i + 1); - } - }; - handleUnnamedExport("pre"); - handleUnnamedExport("post"); - args = `{export: ['${exports.join("', '")}'], ${args}`; - return JSON5.parse(args); - } catch (err) { - new Notice(`Failed to parse code block arguments from line:\n${firstLineOfCode}\n\nFailed with error:\n${err}`); - return {}; - } -}