angular/dgeni

@link breaks JSON output

Opened this issue · 3 comments

I'm generating JSON using dgeni but when I have a description with {@link ...} it generates a correct anchor tag but the double quotes around the href attribute value are not escaped, causing the whole JSON file to be invalid and not parsable.

Example:
@property {string} merp The merp. Supported merps are defined in the {@link MerpTypes} constant.

Generates:

{
    "name": "merp",
    "description": "<p>The merp. Supported merps are defined in the <a href="api/my-module/object/MerpTypes"><code>MerpTypes</code></a> constant.</p>\n",
    "type": [
        "string"
    ]
}

Yeah, I had that problem recently. The trouble is that the inline tag doesn't know that it is going to be output as JSON.
We worked around it by manually converting the doc to JSON after the inline tags have run: https://github.com/angular/angular/blob/master/aio/transforms/angular.io-package/processors/convertToJson.js

I ended up using a task that processes after the dgeni task:

gulp.task('fix-json', function(){
    return gulp.src(['./src/components-data.json'])
        .pipe(replace(/href\s?=\s?"(.*?)"/g, 'href=\\"$1\\"'))
        .pipe(gulp.dest('./src'));
});

It seems like something that should be reasonable to have fixed in the inline tag processor or somewhere, though.

As I said, how would the inline tag processor know that it needs to escape for JSON?
The link inline tag is generating HTML links so it is reasonable for it to expect to be used in a HTML format.