dgeni icon indicating copy to clipboard operation
dgeni copied to clipboard

@link breaks JSON output

Open vozeldr opened this issue 7 years ago • 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"
    ]
}

vozeldr avatar Mar 27 '17 14:03 vozeldr

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

petebacondarwin avatar Mar 27 '17 14:03 petebacondarwin

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.

vozeldr avatar Mar 27 '17 19:03 vozeldr

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.

petebacondarwin avatar Mar 27 '17 20:03 petebacondarwin