From a905e824926c85866253178a82e281716302bd8a Mon Sep 17 00:00:00 2001 From: Dragory <2606411+Dragory@users.noreply.github.com> Date: Sun, 29 Sep 2019 15:55:17 +0300 Subject: [PATCH] Add usageGuide/configurationGuide to PluginInfo, make trimPluginDescription dynamic Previously trimPluginDescription was hardcoded to trim 6 spaces from the beginning of every line. Now the function looks at the last non- empty line and uses its indentation to determine how many spaces to trim from the other lines. --- src/plugins/ZeppelinPlugin.ts | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/plugins/ZeppelinPlugin.ts b/src/plugins/ZeppelinPlugin.ts index 2c891503..e0123c4b 100644 --- a/src/plugins/ZeppelinPlugin.ts +++ b/src/plugins/ZeppelinPlugin.ts @@ -23,21 +23,31 @@ import { mergeConfig } from "knub/dist/configUtils"; const SLOW_RESOLVE_THRESHOLD = 1500; +/** + * Wrapper for the string type that indicates the text will be parsed as Markdown later + */ +type TMarkdown = string; + export interface PluginInfo { prettyName: string; - description?: string; + description?: TMarkdown; + usageGuide?: TMarkdown; + configurationGuide?: TMarkdown; } export interface CommandInfo { - description?: string; - basicUsage?: string; + description?: TMarkdown; + basicUsage?: TMarkdown; parameterDescriptions?: { - [key: string]: string; + [key: string]: TMarkdown; }; } export function trimPluginDescription(str) { - return trimIndents(trimEmptyStartEndLines(str), 6); + const emptyLinesTrimmed = trimEmptyStartEndLines(str); + const lines = emptyLinesTrimmed.split("\n"); + const lastLineIndentation = (lines[lines.length - 1].match(/^ +/g) || [""])[0].length; + return trimIndents(emptyLinesTrimmed, lastLineIndentation); } export class ZeppelinPlugin extends Plugin {