From 8c7725dc3c01a73bf56a48c8b192d144bfdc3ffe Mon Sep 17 00:00:00 2001 From: Kim <1877318+kimsible@users.noreply.github.com> Date: Mon, 20 Apr 2020 14:51:24 +0200 Subject: [PATCH] Add markdown support to plugins (#2654) * Add markdown renderer to plugins * Chore: add doc for markdown plugins * Fix typing markdown plugin helpers * Add lines between components in template Co-authored-by: kimsible --- .../plugin-show-installed.component.html | 18 ++++++++++++++++++ client/src/app/core/plugins/plugin.service.ts | 12 ++++++++++++ .../src/types/register-client-option.model.ts | 5 +++++ .../plugins/register-server-setting.model.ts | 2 +- support/doc/plugins/guide.md | 15 +++++++++++++++ 5 files changed, 51 insertions(+), 1 deletion(-) diff --git a/client/src/app/+admin/plugins/plugin-show-installed/plugin-show-installed.component.html b/client/src/app/+admin/plugins/plugin-show-installed/plugin-show-installed.component.html index 95dd74d31..bf135ecbd 100644 --- a/client/src/app/+admin/plugins/plugin-show-installed/plugin-show-installed.component.html +++ b/client/src/app/+admin/plugins/plugin-show-installed/plugin-show-installed.component.html @@ -8,9 +8,27 @@
+ + + + + + + + + + { + return this.markdownRenderer.textMarkdownToHTML(textMarkdown) + }, + + enhancedMarkdownToHTML: (enhancedMarkdown: string) => { + return this.markdownRenderer.enhancedMarkdownToHTML(enhancedMarkdown) + } + }, + translate: (value: string) => { return this.translationsObservable .pipe(map(allTranslations => allTranslations[npmName])) diff --git a/client/src/types/register-client-option.model.ts b/client/src/types/register-client-option.model.ts index 1c235107a..dff00e9dd 100644 --- a/client/src/types/register-client-option.model.ts +++ b/client/src/types/register-client-option.model.ts @@ -27,5 +27,10 @@ export type RegisterClientHelpers = { confirm?: { value: string, action?: () => void } }) => void + markdownRenderer: { + textMarkdownToHTML: (textMarkdown: string) => Promise + enhancedMarkdownToHTML: (enhancedMarkdown: string) => Promise + } + translate: (toTranslate: string) => Promise } diff --git a/shared/models/plugins/register-server-setting.model.ts b/shared/models/plugins/register-server-setting.model.ts index 45d79228d..ec175e9ef 100644 --- a/shared/models/plugins/register-server-setting.model.ts +++ b/shared/models/plugins/register-server-setting.model.ts @@ -1,7 +1,7 @@ export interface RegisterServerSettingOptions { name: string label: string - type: 'input' | 'input-checkbox' | 'input-textarea' + type: 'input' | 'input-checkbox' | 'input-textarea' | 'markdown-text' | 'markdown-enhanced' // If the setting is not private, anyone can view its value (client code included) // If the setting is private, only server-side hooks can access it diff --git a/support/doc/plugins/guide.md b/support/doc/plugins/guide.md index e6870ce17..1bee1f611 100644 --- a/support/doc/plugins/guide.md +++ b/support/doc/plugins/guide.md @@ -149,6 +149,7 @@ registerSetting({ name: 'admin-name', label: 'Admin name', type: 'input', + // type: input | input-checkbox | input-textarea | markdown-text | markdown-enhanced default: 'my super name' }) @@ -216,6 +217,20 @@ notifier.success('Success message content.') notifier.error('Error message content.') ``` +#### Markdown Renderer + +To render a formatted markdown text to HTML: + +```js +const { markdownRenderer } = peertubeHelpers + +await markdownRenderer.textMarkdownToHTML('**My Bold Text**') +// return My Bold Text + +await markdownRenderer.enhancedMarkdownToHTML('![alt-img](http://.../my-image.jpg)') +// return alt-img +``` + #### Custom Modal To show a custom modal: -- 2.25.1