aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorKim <1877318+kimsible@users.noreply.github.com>2020-04-20 14:51:24 +0200
committerGitHub <noreply@github.com>2020-04-20 14:51:24 +0200
commit8c7725dc3c01a73bf56a48c8b192d144bfdc3ffe (patch)
treeb6e64c7589c7a5138116acd65c1515ef28bea5b9
parent2fd59d7d89d1c389446ee67838c821e2622fc8ca (diff)
downloadPeerTube-8c7725dc3c01a73bf56a48c8b192d144bfdc3ffe.tar.gz
PeerTube-8c7725dc3c01a73bf56a48c8b192d144bfdc3ffe.tar.zst
PeerTube-8c7725dc3c01a73bf56a48c8b192d144bfdc3ffe.zip
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 <kimsible@users.noreply.github.com>
-rw-r--r--client/src/app/+admin/plugins/plugin-show-installed/plugin-show-installed.component.html18
-rw-r--r--client/src/app/core/plugins/plugin.service.ts12
-rw-r--r--client/src/types/register-client-option.model.ts5
-rw-r--r--shared/models/plugins/register-server-setting.model.ts2
-rw-r--r--support/doc/plugins/guide.md15
5 files changed, 51 insertions, 1 deletions
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 @@
8 <form *ngIf="hasRegisteredSettings()" role="form" (ngSubmit)="formValidated()" [formGroup]="form"> 8 <form *ngIf="hasRegisteredSettings()" role="form" (ngSubmit)="formValidated()" [formGroup]="form">
9 <div class="form-group" *ngFor="let setting of registeredSettings"> 9 <div class="form-group" *ngFor="let setting of registeredSettings">
10 <label *ngIf="setting.type !== 'input-checkbox'" [attr.for]="setting.name" [innerHTML]="setting.label"></label> 10 <label *ngIf="setting.type !== 'input-checkbox'" [attr.for]="setting.name" [innerHTML]="setting.label"></label>
11
11 <input *ngIf="setting.type === 'input'" type="text" [id]="setting.name" [formControlName]="setting.name" /> 12 <input *ngIf="setting.type === 'input'" type="text" [id]="setting.name" [formControlName]="setting.name" />
13
12 <textarea *ngIf="setting.type === 'input-textarea'" type="text" [id]="setting.name" [formControlName]="setting.name"></textarea> 14 <textarea *ngIf="setting.type === 'input-textarea'" type="text" [id]="setting.name" [formControlName]="setting.name"></textarea>
13 15
16 <my-help *ngIf="setting.type === 'markdown-text'" helpType="markdownText"></my-help>
17
18 <my-help *ngIf="setting.type === 'markdown-enhanced'" helpType="markdownEnhanced"></my-help>
19
20 <my-markdown-textarea
21 *ngIf="setting.type === 'markdown-text'"
22 markdownType="text" [id]="setting.name" [formControlName]="setting.name" textareaWidth="500px" [previewColumn]="false"
23 [classes]="{ 'input-error': formErrors['settings.name'] }"
24 ></my-markdown-textarea>
25
26 <my-markdown-textarea
27 *ngIf="setting.type === 'markdown-enhanced'"
28 markdownType="enhanced" [id]="setting.name" [formControlName]="setting.name" textareaWidth="500px" [previewColumn]="false"
29 [classes]="{ 'input-error': formErrors['settings.name'] }"
30 ></my-markdown-textarea>
31
14 <my-peertube-checkbox 32 <my-peertube-checkbox
15 *ngIf="setting.type === 'input-checkbox'" 33 *ngIf="setting.type === 'input-checkbox'"
16 [id]="setting.name" 34 [id]="setting.name"
diff --git a/client/src/app/core/plugins/plugin.service.ts b/client/src/app/core/plugins/plugin.service.ts
index 039fd6ff1..3ed23160d 100644
--- a/client/src/app/core/plugins/plugin.service.ts
+++ b/client/src/app/core/plugins/plugin.service.ts
@@ -15,6 +15,7 @@ import { HttpClient } from '@angular/common/http'
15import { AuthService } from '@app/core/auth' 15import { AuthService } from '@app/core/auth'
16import { Notifier } from '@app/core/notification' 16import { Notifier } from '@app/core/notification'
17import { RestExtractor } from '@app/shared/rest' 17import { RestExtractor } from '@app/shared/rest'
18import { MarkdownService } from '@app/shared/renderer'
18import { PluginType } from '@shared/models/plugins/plugin.type' 19import { PluginType } from '@shared/models/plugins/plugin.type'
19import { PublicServerSetting } from '@shared/models/plugins/public-server.setting' 20import { PublicServerSetting } from '@shared/models/plugins/public-server.setting'
20import { getDevLocale, isOnDevLocale } from '@app/shared/i18n/i18n-utils' 21import { getDevLocale, isOnDevLocale } from '@app/shared/i18n/i18n-utils'
@@ -65,6 +66,7 @@ export class PluginService implements ClientHook {
65 private router: Router, 66 private router: Router,
66 private authService: AuthService, 67 private authService: AuthService,
67 private notifier: Notifier, 68 private notifier: Notifier,
69 private markdownRenderer: MarkdownService,
68 private server: ServerService, 70 private server: ServerService,
69 private zone: NgZone, 71 private zone: NgZone,
70 private authHttp: HttpClient, 72 private authHttp: HttpClient,
@@ -297,6 +299,16 @@ export class PluginService implements ClientHook {
297 this.customModal.show(input) 299 this.customModal.show(input)
298 }, 300 },
299 301
302 markdownRenderer: {
303 textMarkdownToHTML: (textMarkdown: string) => {
304 return this.markdownRenderer.textMarkdownToHTML(textMarkdown)
305 },
306
307 enhancedMarkdownToHTML: (enhancedMarkdown: string) => {
308 return this.markdownRenderer.enhancedMarkdownToHTML(enhancedMarkdown)
309 }
310 },
311
300 translate: (value: string) => { 312 translate: (value: string) => {
301 return this.translationsObservable 313 return this.translationsObservable
302 .pipe(map(allTranslations => allTranslations[npmName])) 314 .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 = {
27 confirm?: { value: string, action?: () => void } 27 confirm?: { value: string, action?: () => void }
28 }) => void 28 }) => void
29 29
30 markdownRenderer: {
31 textMarkdownToHTML: (textMarkdown: string) => Promise<string>
32 enhancedMarkdownToHTML: (enhancedMarkdown: string) => Promise<string>
33 }
34
30 translate: (toTranslate: string) => Promise<string> 35 translate: (toTranslate: string) => Promise<string>
31} 36}
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 @@
1export interface RegisterServerSettingOptions { 1export interface RegisterServerSettingOptions {
2 name: string 2 name: string
3 label: string 3 label: string
4 type: 'input' | 'input-checkbox' | 'input-textarea' 4 type: 'input' | 'input-checkbox' | 'input-textarea' | 'markdown-text' | 'markdown-enhanced'
5 5
6 // If the setting is not private, anyone can view its value (client code included) 6 // If the setting is not private, anyone can view its value (client code included)
7 // If the setting is private, only server-side hooks can access it 7 // 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({
149 name: 'admin-name', 149 name: 'admin-name',
150 label: 'Admin name', 150 label: 'Admin name',
151 type: 'input', 151 type: 'input',
152 // type: input | input-checkbox | input-textarea | markdown-text | markdown-enhanced
152 default: 'my super name' 153 default: 'my super name'
153}) 154})
154 155
@@ -216,6 +217,20 @@ notifier.success('Success message content.')
216notifier.error('Error message content.') 217notifier.error('Error message content.')
217``` 218```
218 219
220#### Markdown Renderer
221
222To render a formatted markdown text to HTML:
223
224```js
225const { markdownRenderer } = peertubeHelpers
226
227await markdownRenderer.textMarkdownToHTML('**My Bold Text**')
228// return <strong>My Bold Text</strong>
229
230await markdownRenderer.enhancedMarkdownToHTML('![alt-img](http://.../my-image.jpg)')
231// return <img alt=alt-img src=http://.../my-image.jpg />
232```
233
219#### Custom Modal 234#### Custom Modal
220 235
221To show a custom modal: 236To show a custom modal: