Skip to content

Commit

Permalink
Markdown: fix rendering when source has prepending whitespace
Browse files Browse the repository at this point in the history
Fixed an issue with pat-markdown where rendering was not like expected when source has prepending whitespace (#697)
Fixes #697
  • Loading branch information
thet committed Jan 22, 2020
1 parent e55ed34 commit 0948452
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Features
- Fixed an issue with pat-scroll when placed on an item without a href
- Fixed an issue with pat-autofocus that would set focus on hidden items
- Fixed an issue with pat-inject scroll that would scroll too much (#694)
- Fixed an issue with pat-markdown where rendering was not like expected when source has prepending whitespace (#697)
Fixes
~~~~~
Expand Down
1 change: 1 addition & 0 deletions src/pat/markdown/markdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ define([
render: function(text) {
var $rendering = $("<div/>"),
converter = new Showdown.Converter({tables: true, extensions: ['prettify']});
text = text.trim();
$rendering.html(converter.makeHtml(text));
return $rendering;
},
Expand Down
7 changes: 7 additions & 0 deletions src/pat/markdown/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ define(["pat-markdown"], function(Pattern) {
var $rendering = Pattern.prototype.render("*This is markdown*");
expect($rendering.html()).toBe("<p><em>This is markdown</em></p>");
});

it("removes whitespace from start and end of text", function() {
// If text is not removed, the rendering breaks and ouputs this instead:
// '<pre class="pat-syntax-highlight" tabindex="0"><code data-inner="1"> *This is markdown* </code></pre>'
var $rendering = Pattern.prototype.render(" *This is markdown* ");
expect($rendering.html()).toBe("<p><em>This is markdown</em></p>");
});
});

describe("Session extraction", function() {
Expand Down

0 comments on commit 0948452

Please sign in to comment.