From 5eee97972d6768d2b4490239e96cfa4a42947b95 Mon Sep 17 00:00:00 2001 From: Chris Garrett Date: Tue, 29 Oct 2019 19:19:21 -0700 Subject: [PATCH] [BUGFIX] Adds support for decorators This PR adds general support for decorators when used within markdown blocks. It does this by reaching into the YUIDoc global and patching the method that handles comment parsing. Given YUIDoc is pretty much abandoned at this point, this should be a relatively stable patch. Presumably, attempts to modernize it will also add decorator support, should they occur. The fix replaces all @ symbols within codeblocks with a placeholder, processes them, and then switches them back after processing. --- lib/broccoli-yuidoc.js | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/lib/broccoli-yuidoc.js b/lib/broccoli-yuidoc.js index a8d3ca8..ea6bc4d 100644 --- a/lib/broccoli-yuidoc.js +++ b/lib/broccoli-yuidoc.js @@ -3,6 +3,35 @@ var rsvp = require('rsvp'); var path = require('path'); var CachingWriter = require('broccoli-caching-writer'); +var Y = require('yuidocjs'); + +var originalHandleComment = Y.DocParser.prototype.handlecomment; + +var AT_PLACEHOLDER = '---AT-PLACEHOLDER---'; +var AT_PLACEHOLDER_REGEX = new RegExp(AT_PLACEHOLDER, 'g'); + +Y.DocParser.prototype.handlecomment = function(comment, file, line) { + var lines = comment.split(/\r\n|\n/); + + var inMarkdownBlock = false; + + var newLines = lines.map((line) => { + if (line.match(/^(\s*\*)?\s*```/)) { + inMarkdownBlock = !inMarkdownBlock; + } + + return inMarkdownBlock ? line.replace(/@/g, AT_PLACEHOLDER) : line; + }); + + var ret = originalHandleComment.call(this, newLines.join('\n'), file, line); + var description = ret.find(t => t.tag === 'description'); + + if (description) { + description.value = description.value.replace(AT_PLACEHOLDER_REGEX, '@'); + } + + return ret; +} BroccoliYuidoc.prototype = Object.create(CachingWriter.prototype); BroccoliYuidoc.prototype.constructor = BroccoliYuidoc; @@ -15,7 +44,6 @@ function BroccoliYuidoc(inputNodes, options) { }; BroccoliYuidoc.prototype.build = function() { - var Y = require('yuidocjs'); var options = this.options; options.outdir = path.resolve(this.outputPath, options.outdir);