Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
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
6 changes: 4 additions & 2 deletions src/components/Code.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import { defineComponent } from "vue";

import { cleanHtml, mdToHTML } from "@/core/markdown";
import Checkbox from "./Checkbox.vue";
import store from "@/store";


export default defineComponent({
name: "Code",
Expand All @@ -25,14 +27,14 @@ export default defineComponent({
},
data() {
return {
asHtml: false,
asHtml: store.state.asHtml,
};
},
computed: {
outputCode(): String {
store.setAsHTML(this.asHtml);
if (this.asHtml) {
const htmlCode = mdToHTML(this.code);

return cleanHtml(htmlCode);
}
return this.code;
Expand Down
2 changes: 1 addition & 1 deletion src/core/markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export function mdImageWithLink({
* Render Markdown code as HTML code.
*/
export function mdToHTML(value: string): string {
return md.render(value);
return md.render(value).trim();
}

/**
Expand Down
13 changes: 13 additions & 0 deletions src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import { DEBUG } from "@/constants/";
import { DEFAULT_REPO_INPUTS } from "@/constants/badgeValues";
import { reactive } from "vue";
// import asHtml from "@/components/Code.vue";

/**
* Global store.
Expand All @@ -14,6 +15,7 @@ const store = {
state: reactive({
repoUsername: DEFAULT_REPO_INPUTS.username,
repoName: DEFAULT_REPO_INPUTS.repoName,
asHtml: false,
}),

/**
Expand All @@ -37,6 +39,17 @@ const store = {

this.state.repoName = value;
},

/**
* Store asHtml value. e.g. true or false.
*/
setAsHTML(value: boolean){
if (DEBUG) {
console.debug(`Storing asHtml as: ${value}`);
}

this.state.asHtml = value;
}
};

export default store;
2 changes: 2 additions & 0 deletions tests/unit/components/Code.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import Code from "@/components/Code.vue";
import { shallowMount } from "@vue/test-utils";
import store from "@/store";
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This bit needs to be actually used.

Also please run tests and fix them. The Code component needs to switch between HTML and Markdown mode in the tests.

This file is failing.

This old code is like this:

      data() {
        return {
          asHtml: true,
        };
      },

I tried adding this and it didn't work.


    wrapper.setData({ asHtml: true })
    store.setAsHtml(true)


Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change


describe("Code.vue", () => {
it("renders a Markdown codeblock as Markdown code, with highlighting", () => {
Expand Down