Skip to content

Commit

Permalink
filters: adds json
Browse files Browse the repository at this point in the history
  • Loading branch information
dresende committed Feb 5, 2024
1 parent a74c7dd commit 0100c88
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
5 changes: 5 additions & 0 deletions core/Filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,8 @@ export const nl = (text) => {
export const quote = (html) => {
return String(html).replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/'/g, "&#39;").replace(/"/g, "&quot;");
};

// print indented JSON
export const json = (json) => {
return `<pre>${JSON.stringify(json, null, 4)}</pre>`;
};
6 changes: 6 additions & 0 deletions test/Filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,10 @@ describe("Filters", () => {

view().should.equal("&lt;b&gt;bold&lt;/b&gt;");
});

it("json", async () => {
const view = await keikan.compileData("<%-: { x: 2 } | json %>");

view().should.equal(`<pre>${JSON.stringify({ x: 2 }, null, 4)}</pre>`);
});
});

0 comments on commit 0100c88

Please sign in to comment.