Skip to content

Commit

Permalink
extract markdown parse to its own function
Browse files Browse the repository at this point in the history
  • Loading branch information
jxjj committed Jan 31, 2025
1 parent 83a8dd7 commit cd84d92
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
14 changes: 2 additions & 12 deletions resources/client/components/Markdown.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,12 @@
</template>
<script setup lang="ts">
import { computed } from "vue";
import { marked } from "marked";
import markedKatex from "marked-katex-extension";
import { markdownToHTML } from "@/lib/markdownToHTML";
const props = defineProps<{
content: string;
}>();
const options = {
throwOnError: false,
};
marked.use(markedKatex(options));
const html = computed(() => {
const html = marked.parse(props.content);
return html;
});
const html = computed(() => markdownToHTML(props.content));
</script>
<style scoped></style>
15 changes: 15 additions & 0 deletions resources/client/lib/markdownToHTML.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { marked, MarkedOptions } from "marked";
import markedKatex, { MarkedKatexOptions } from "marked-katex-extension";

const options: MarkedOptions & MarkedKatexOptions = {
throwOnError: false,
async: false,
};

marked.use(markedKatex(options));

export function markdownToHTML(markdown: string): string {
// not using async so we can cast as string instead
// of Promise<string>
return marked.parse(markdown) as string;
}

0 comments on commit cd84d92

Please sign in to comment.