Skip to content

Commit

Permalink
feat(markdown): support global whitelist config
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianschmidt committed Jan 27, 2025
1 parent a13159c commit 5a16938
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions etc/lime-elements.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,7 @@ export namespace Components {
export type Config = {
iconPath?: string;
defaultLocale?: string;
markdownWhitelist?: CustomElementDefinition[];
featureSwitches?: Record<string, boolean>;
};

Expand Down
6 changes: 5 additions & 1 deletion src/components/markdown/markdown.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Component, h, Prop, Watch } from '@stencil/core';
import { markdownToHTML } from './markdown-parser';
import { globalConfig } from '../../global/config';
import { CustomElementDefinition } from '../../global/shared-types/custom-element.types';

/**
Expand Down Expand Up @@ -38,10 +39,13 @@ export class Markdown {
* Whitelisted html elements.
*
* Any custom element added here will not be sanitized and thus rendered.
* Can also be set via `limel-config`. Setting this property will override
* the global config.
* @alpha
*/
@Prop()
public whitelist?: CustomElementDefinition[];
public whitelist?: CustomElementDefinition[] =
globalConfig.markdownWhitelist;

@Watch('value')
public async textChanged() {
Expand Down
11 changes: 11 additions & 0 deletions src/global/config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { CustomElementDefinition } from './shared-types/custom-element.types';

/**
* Configuration options for limel-config.
*
Expand All @@ -14,6 +16,14 @@ export type Config = {
*/
defaultLocale?: string;

/**
* Whitelisted html elements for `limel-markdown`.
*
* Any custom element added here will not be sanitized and thus rendered.
* @alpha
*/
markdownWhitelist?: CustomElementDefinition[];

/**
* @internal
*/
Expand All @@ -23,6 +33,7 @@ export type Config = {
class ConfigClass implements Config {
public iconPath = '';
public defaultLocale = navigator.language;
public markdownWhitelist?: CustomElementDefinition[];
public featureSwitches: any = getFeatureSwitches(localStorage);
}

Expand Down

0 comments on commit 5a16938

Please sign in to comment.