Skip to content
This repository was archived by the owner on Mar 31, 2025. It is now read-only.
This repository was archived by the owner on Mar 31, 2025. It is now read-only.

Regression: since 0.28.0, marked filter does not render markdown in HTML blocks #310

@Splaktar

Description

@Splaktar

I first hit this in angular/material#11881, which ended up with the project pinning the dependency to 0.27.5 and not being able to upgrade since then. At that time, early 2020, I was quite unfamiliar with Marked and how it was used in dgeni-packages. So I was hoping that someone else would report this and it would get fixed. Unfortunately, that hasn't happened.

I have dug deeper recently in angular/angular.js#17141 and this seems to be related to 16ceb9c from PR #281, released in 0.28.0.

There is a breaking changes note:

There are a few relevant breaking changes with this latest version of `marked`.
This only affects usage of the `renderMarkdown()` service and the `marked`
nunjucks filter. Take a look through the
[marked release notes](https://github.com/markedjs/marked/releases) and
check if this affects you.
  1. renderMarkdown() is not used by AngularJS or AngularJS Material.
  2. They both use require('dgeni-packages/nunjucks') and the marked filter, i.e. {$ doc.description | marked $}

I read through the Marked release notes, but being unfamiliar with the library, I didn't really see anything related or of value to fixing this.

I read through this project's README.md but didn't see any references on how to use the marked filter.

It looks like the code for the filter is here:

/**
* @dgRenderFilter marked
* @description Convert the value, as markdown, into HTML using the marked library
*/
module.exports = function markedNunjucksFilter(renderMarkdown) {
return {
name: 'marked',
process(str) {
const output = str && renderMarkdown(str);
return output;
}
};
};

I don't see how a change to any marked APIs could cause issues with this simple filter.

Except that it seems to call renderMarkdown()

const marked = require('marked');
/**
* @dgService renderMarkdown
* @description
* Render the markdown in the given string as HTML.
*/
module.exports = function renderMarkdown(trimIndentation) {
const renderer = new marked.Renderer();
// Remove the leading whitespace from the code block before it gets to the
// markdown code render function
renderer.code = (code, string, language) => {
const trimmedCode = trimIndentation(code);
let renderedCode = marked.Renderer.prototype.code.call(renderer, trimmedCode, string, language);
// Bug in marked - forgets to add a final newline sometimes
if ( !/\n$/.test(renderedCode) ) {
renderedCode += '\n';
}
return renderedCode;
};
return content => marked(content, { renderer: renderer });
};

Which does import marked and use its APIs.

There is perhaps something that I'm missing here where this can be fixed in the AngularJS and AngularJS Material projects, but from what I can tell, with limited knowledge of this library, the fix needs to be made here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions