Skip to content

Commit

Permalink
Fix bug where blockquotes had trailing spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Dec 24, 2015
1 parent 33752f4 commit a51f112
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 2 deletions.
13 changes: 11 additions & 2 deletions lib/stringify.js
Original file line number Diff line number Diff line change
Expand Up @@ -1242,9 +1242,18 @@ compilerPrototype.paragraph = function (node) {
* @return {string} - Markdown block quote.
*/
compilerPrototype.blockquote = function (node) {
var indent = ANGLE_BRACKET_CLOSE + SPACE;
var values = this.block(node).split(LINE);
var result = [];
var length = values.length;
var index = -1;
var value;

while (++index < length) {
value = values[index];
result[index] = (value ? SPACE : EMPTY) + value;
}

return indent + this.block(node).split(LINE).join(LINE + indent);
return ANGLE_BRACKET_CLOSE + result.join(LINE + ANGLE_BRACKET_CLOSE);
};

/**
Expand Down
3 changes: 3 additions & 0 deletions test/input/blockquotes-empty-lines.output.text
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
> Note there is no space on the following line.
>
> Note there is no space on the preceding line.
96 changes: 96 additions & 0 deletions test/tree/blockquotes-empty-lines.output.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
{
"type": "root",
"children": [
{
"type": "blockquote",
"children": [
{
"type": "paragraph",
"children": [
{
"type": "text",
"value": "Note there is no space on the following line.",
"position": {
"start": {
"line": 1,
"column": 3
},
"end": {
"line": 1,
"column": 48
},
"indent": []
}
}
],
"position": {
"start": {
"line": 1,
"column": 3
},
"end": {
"line": 1,
"column": 48
},
"indent": []
}
},
{
"type": "paragraph",
"children": [
{
"type": "text",
"value": "Note there is no space on the preceding line.",
"position": {
"start": {
"line": 3,
"column": 3
},
"end": {
"line": 3,
"column": 48
},
"indent": []
}
}
],
"position": {
"start": {
"line": 3,
"column": 3
},
"end": {
"line": 3,
"column": 48
},
"indent": []
}
}
],
"position": {
"start": {
"line": 1,
"column": 1
},
"end": {
"line": 3,
"column": 48
},
"indent": [
1,
1
]
}
}
],
"position": {
"start": {
"line": 1,
"column": 1
},
"end": {
"line": 4,
"column": 1
}
}
}

0 comments on commit a51f112

Please sign in to comment.