jfcere / ngx-markdown

Angular markdown component/directive/pipe/service to parse static, dynamic or remote content to HTML with syntax highlight and more...
https://jfcere.github.io/ngx-markdown
MIT License
1.06k stars 182 forks source link

MarkedRenderer stopped working without any changes other than in package.json when going from 13.1 to 16 #504

Closed polonmedia closed 6 months ago

polonmedia commented 7 months ago

I'm losing my mind here. image image

All I did was:

This is my code (everything used to work in 13.1.0): image

import { MarkedOptions, MarkedRenderer } from 'ngx-markdown';

export function markedOptionsFactory(): MarkedOptions {
  const renderer: MarkedRenderer = new MarkedRenderer();

  renderer.code = (text: string, lang: string) => {
    switch (lang) {
      case 'angular':
        return text;
      case 'html':
        return `<pre class="language-${lang}"><code class="language-${lang}">${text.replace(/[\u00A0-\u9999<>]/gim, (i: string) => {
          return `&#${i.charCodeAt(0)};`;
        })}</code></pre>`;
      default:
        return `<pre class="language-${lang}"><code class="language-${lang}">${text.replace(/{/g, '&#123;').replace(/}/g, '&#125;')}</code></pre>`;
    }
  };

  renderer.codespan = (text: string) => `<samp>${text.replace(/{/g, '&#123;').replace(/}/g, '&#125;')}</samp>`;

  renderer.table = (header: string, body: string) => {
    if (body) {
      body = `<tbody>${body}</tbody>`;
    }
    return `<table class="cui-md-table">\n<thead>\n${header}</thead>\n${body}</table>\n`;
  };

  return {
    renderer,
    gfm: true,
    breaks: true,
    pedantic: false,
    smartLists: true,
    smartypants: false,
  };
}

Any idea why the custom renderer is not recognized at all?

What it was: image

What it is: image

No class is added from the factory code - it's like it is not even considered. I was wondering what it is?

jfcere commented 6 months ago

Hi @polonmedia,

I am not sure what is the problem in your repository but I tested it in StackBlitz and your code seems to work fine:

https://stackblitz.com/edit/ngx-markdown-issue-504?file=src%2Fapp%2Fapp.module.ts

image

Let me know if the provided StackBlitz helped you to solve your issue.

jfcere commented 6 months ago

If you are not using the markdown component, this could be related to the following issue that has been fixed in v17.1.0: https://github.com/jfcere/ngx-markdown/issues/456

jfcere commented 6 months ago

Closing as there has not been any follow up.