Skip to content

Commit

Permalink
Merge pull request #29 from renehernandez/sync-fixes
Browse files Browse the repository at this point in the history
Fixes nunjucks autoescaping html char and incorrect path location
  • Loading branch information
renehernandez authored Apr 15, 2021
2 parents 48919dc + 149c547 commit 6a3ec19
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 22 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ jobs:

- name: Build
run: npm run build
env:
BUILD: production

- name: Test
run: npm run test
2 changes: 2 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ jobs:

- name: Build
run: npm run build
env:
BUILD: production

- name: Create release
id: create_release
Expand Down
8 changes: 4 additions & 4 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ import commonjs from '@rollup/plugin-commonjs';
import svelte from "rollup-plugin-svelte";
import autoPreprocess from "svelte-preprocess";
import copy from "rollup-plugin-copy";
import { env } from "process";

export default {
input: 'src/index.ts',
output: {
file: 'dist/main.js',
format: 'cjs',
exports: 'default'
exports: 'default',
sourcemap: process.env.BUILD === "development" ? "inline" : false
},
external: ['obsidian', "path"],
external: ['obsidian'],
plugins: [
typescript({ sourceMap: env.env === "DEV" }),
typescript({ sourceMap: process.env.BUILD === "development" }),
resolve({
browser: true,
dedupe: ["svelte"],
Expand Down
2 changes: 1 addition & 1 deletion src/fileDoc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export class FileDoc {
}

public filePath(): string {
return this.fsHandler.normalizePath(`${this.fsHandler.getBasePath()}/${this.sanitizeName()}.md`);
return this.fsHandler.normalizePath(`${this.sanitizeName()}.md`);
}

public sanitizeName(): string {
Expand Down
4 changes: 0 additions & 4 deletions src/fileSystem/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ export class FileSystemHandler implements IFileSystemHandler {
this.adapter = adapter;
}

public getBasePath(): string {
return this.adapter.getBasePath();
}

public normalizePath(path: string): string {
return obsidian.normalizePath(path);
}
Expand Down
2 changes: 0 additions & 2 deletions src/fileSystem/interface.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
export interface IFileSystemHandler {
getBasePath(): string;

normalizePath(path: string): string;

read(path: string): Promise<string>;
Expand Down
4 changes: 3 additions & 1 deletion src/template/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ export class TemplateLoader {
async load(): Promise<nunjucks.Template> {
let content = await this.selectTemplate();

return nunjucks.compile(content);
let env = nunjucks.configure({ autoescape: false });

return nunjucks.compile(content, env);
}

async selectTemplate(): Promise<string> {
Expand Down
2 changes: 1 addition & 1 deletion tests/fileDoc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ describe("File Doc", () => {
});

it("generates the fileDoc path", () => {
assert.equal(fileDoc.filePath(), "/base/Hello World.md");
assert.equal(fileDoc.filePath(), "Hello World.md");
});
});
});
1 change: 0 additions & 1 deletion tests/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const path = require('path');

export function fileSystemHandler(): IFileSystemHandler {
return {
getBasePath: () => "/base",
normalizePath: (path: string) => path,
read: async (path: string) => {
return fs.readFileSync(path).toString();
Expand Down
16 changes: 8 additions & 8 deletions tests/templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,29 +123,29 @@ describe("HighlightTemplateRenderer", () => {
highlight = new Highlight({
id: 10,
book_id: 5,
text: 'Looks important',
note: 'It really looks important',
text: "Looks important. It's super <great>",
note: "It really looks important. Can't wait for it",
url: 'https://readwise.io',
location: 1,
});
});

it('renders default template with doc', async () => {
assert.equal(await templateRenderer.render(highlight), `Looks important %% highlight_id: 10 %%
Note: It really looks important
assert.equal(await templateRenderer.render(highlight), `Looks important. It's super <great> %% highlight_id: 10 %%
Note: It really looks important. Can't wait for it
`);
});

it('renders custom template with doc', async () => {
assert.equal(await customTemplateRenderer.render(highlight), `Looks important \`highlight_id: 10\` %% location: 1 %%
Note: It really looks important
assert.equal(await customTemplateRenderer.render(highlight), `Looks important. It's super <great> \`highlight_id: 10\` %% location: 1 %%
Note: It really looks important. Can't wait for it
`);
});

it('adds highlight_id if not present on template', async () => {
let customTemplateWithoutIdRenderer = await HighlightTemplateRenderer.create(resolvePathToData('Readwise Note Highlight Missing Id'), handler);
assert.equal(await customTemplateWithoutIdRenderer.render(highlight), `Looks important %% location: 1 %%
Note: It really looks important
assert.equal(await customTemplateWithoutIdRenderer.render(highlight), `Looks important. It's super <great> %% location: 1 %%
Note: It really looks important. Can't wait for it
%% highlight_id: 10 %%
`);
});
Expand Down

0 comments on commit 6a3ec19

Please sign in to comment.