Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Markdown: fix rendering when source has prepending whitespace #698

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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