Skip to content

Commit 6edb8a2

Browse files
authored
Merge pull request #1082 from Patternslib/fix-markdown
fix(pat markdown): Restore old behavior where the trigger element was…
2 parents c36cd51 + ecb0330 commit 6edb8a2

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

src/pat/markdown/markdown.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ const Markdown = Base.extend({
2222
? this.$el.val()
2323
: this.$el[0].innerHTML;
2424
let rendered = await this.render(source);
25-
this.el.innerHTML = "";
26-
this.el.append(...rendered[0].childNodes);
25+
this.el.replaceWith(...rendered);
2726
}
2827
},
2928

src/pat/markdown/markdown.test.js

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ describe("pat-markdown", function () {
1616
afterEach(() => {
1717
jest.restoreAllMocks();
1818
});
19-
it("It renders content for elements with the pattern trigger.", async function () {
19+
it("Replaces the DOM element with the rendered Markdown content.", async function () {
2020
var $el = $('<p class="pat-markdown"></p>');
2121
$el.appendTo("#lab");
2222
jest.spyOn(pattern.prototype, "render").mockImplementation(() => {
2323
return $("<p>Rendering</p>");
2424
});
2525
pattern.init($el);
2626
await utils.timeout(1); // wait a tick for async to settle.
27-
expect($("#lab").html()).toBe('<p class="pat-markdown">Rendering</p>');
27+
expect($("#lab").html()).toBe("<p>Rendering</p>");
2828
});
2929

3030
it("It does not render when the DOM element doesn't have the pattern trigger", function () {
@@ -162,26 +162,30 @@ describe("pat-markdown", function () {
162162

163163
describe("Code blocks", function () {
164164
it("It correctly renders code blocks", async function () {
165-
document.body.innerHTML = `<div class="pat-markdown">
165+
document.body.innerHTML = `
166+
<main>
167+
<div class="pat-markdown">
166168
# Title
167169
168170
some content
169171
170172
\`\`\`javascript
171173
const foo = "bar";
172174
\`\`\`
173-
</div>
174-
`;
175+
176+
</div>
177+
</main>
178+
`;
175179

176180
new pattern(document.querySelector(".pat-markdown"));
177181
await utils.timeout(1); // wait a tick for async to settle.
178182
await utils.timeout(1); // wait a tick for async to settle.
179183

180-
expect(document.body.querySelector(".pat-markdown > h1").textContent).toBe("Title"); // prettier-ignore
181-
expect(document.body.querySelector(".pat-markdown > p").textContent).toBe("some content"); // prettier-ignore
182-
expect(document.body.querySelector(".pat-markdown > pre code")).toBeTruthy(); // prettier-ignore
183-
expect(document.body.querySelector(".pat-markdown > pre.language-javascript code.language-javascript")).toBeTruthy(); // prettier-ignore
184-
expect(document.body.querySelector(".pat-markdown > pre code .hljs-keyword")).toBeTruthy(); // prettier-ignore
184+
expect(document.body.querySelector("main > div > h1").textContent).toBe("Title"); // prettier-ignore
185+
expect(document.body.querySelector("main > div > p").textContent).toBe("some content"); // prettier-ignore
186+
expect(document.body.querySelector("main > div > pre code")).toBeTruthy(); // prettier-ignore
187+
expect(document.body.querySelector("main > div > pre.language-javascript code.language-javascript")).toBeTruthy(); // prettier-ignore
188+
expect(document.body.querySelector("main > div > pre code .hljs-keyword")).toBeTruthy(); // prettier-ignore
185189
});
186190
});
187191
});

0 commit comments

Comments
 (0)