chore(doc-gen): trim leading blank lines from markdown content

Harp 0.17 does not allow blank lines to appear between filters and their
content. This change ensures that any blank lines that could appear have
been trimmed inside Nunkjucks.

Closes #3325
This commit is contained in:
Peter Bacon Darwin 2015-07-28 12:00:18 +01:00 committed by Naomi Black
parent 6ab2a871ce
commit d426af741c
5 changed files with 25 additions and 7 deletions

View File

@ -54,4 +54,11 @@ module.exports = new Package('angular.io', [basePackage])
.config(function(getLinkInfo) { .config(function(getLinkInfo) {
getLinkInfo.relativeLinks = true; getLinkInfo.relativeLinks = true;
})
.config(function(templateEngine, getInjectables) {
templateEngine.filters = templateEngine.filters.concat(getInjectables([require('./rendering/trimBlankLines')]));
}); });

View File

@ -0,0 +1,12 @@
module.exports = function(encodeCodeBlock) {
return {
name: 'trimBlankLines',
process: function(str) {
var lines = str.split(/\r?\n/);
while(lines[0] === '') {
lines.shift();
}
return lines.join('\n');
}
};
};

View File

@ -8,7 +8,7 @@ p.location-badge.
defined in {$ githubViewLink(doc) $} defined in {$ githubViewLink(doc) $}
:markdown :markdown
{$ doc.description | indent(2, true) $} {$ doc.description | indent(2, true) | trimBlankLines $}
{%- if doc.decorators %} {%- if doc.decorators %}
.l-main-section .l-main-section
@ -37,7 +37,7 @@ p.location-badge.
{$ doc.constructorDoc.name $}{$ paramList(doc.constructorDoc.parameters) | indent(4, true) | trim $} {$ doc.constructorDoc.name $}{$ paramList(doc.constructorDoc.parameters) | indent(4, true) | trim $}
{% endif %} {% endif %}
:markdown :markdown
{$ doc.constructorDoc.description | indent(6, true) | replace('## Example', '') | replace('# Example', '') $} {$ doc.constructorDoc.description | indent(6, true) | replace('## Example', '') | replace('# Example', '') | trimBlankLines $}
{% endif -%} {% endif -%}
@ -52,8 +52,7 @@ p.location-badge.
{$ member.name $}{$ paramList(member.parameters) | indent(4, true) | trim $}{$ returnType(doc.returnType) $} {$ member.name $}{$ paramList(member.parameters) | indent(4, true) | trim $}{$ returnType(doc.returnType) $}
{% endif %} {% endif %}
:markdown :markdown
{$ member.description | indent(6, true) | replace('## Example', '') | replace('# Example', '') | trimBlankLines $}
{$ member.description | indent(6, true) | replace('## Example', '') | replace('# Example', '') $}

View File

@ -17,6 +17,6 @@
defined in {$ githubViewLink(doc) $} defined in {$ githubViewLink(doc) $}
:markdown :markdown
{$ doc.description | indent(4, true) $} {$ doc.description | indent(4, true) | trimBlankLines $}
{% endblock %} {% endblock %}

View File

@ -9,5 +9,5 @@
defined in {$ githubViewLink(doc) $} defined in {$ githubViewLink(doc) $}
:markdown :markdown
{$ doc.description | indent(4, true) $} {$ doc.description | indent(4, true) | trimBlankLines $}
{% endblock %} {% endblock %}