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);