Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix custom renderer gets overridden when using MarkdownPipe #485

Merged
merged 1 commit into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions lib/src/markdown.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
SECURITY_CONTEXT,
} from './markdown.service';
import { MarkedOptions } from './marked-options';
import { MarkedRenderer } from './marked-renderer';
import { MermaidAPI } from './mermaid-options';

declare let window: any;
Expand Down Expand Up @@ -391,6 +392,22 @@ describe('MarkdownService', () => {
expect(markedParseSpy.calls.argsFor(0)[1]).toEqual(expectedOptions);
});

it('should not override markedOptions.renderer when parsing and parseOptions.renderer is not provided', () => {

const mockRaw = '### Markdown-x';
const mockRenderer = new MarkedRenderer();
mockRenderer.blockquote = () => 'mock-blocquote';
const mockMarkedOptions: MarkedOptions = { breaks: true, gfm: false, pedantic: true, silent: false, renderer: mockRenderer };

const markedUseSpy = spyOn(marked, 'use');

markdownService.options = mockMarkedOptions;
markdownService.parse(mockRaw);

expect(markedUseSpy).toHaveBeenCalled();
expect(markedUseSpy).toHaveBeenCalledWith({ renderer: mockRenderer });
});

it('should return empty string when raw is null/undefined/empty', () => {

expect(markdownService.parse(null!)).toBe('');
Expand Down
2 changes: 1 addition & 1 deletion lib/src/markdown.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export class MarkdownService {
inline: false,
emoji: false,
mermaid: false,
markedOptions: this.DEFAULT_MARKED_OPTIONS,
markedOptions: undefined,
disableSanitizer: false,
};

Expand Down