Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kaytex support reintroduced #371

Merged
merged 24 commits into from
Jul 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
105bdba
fix: enable csr for lab
edeleastar Jul 2, 2023
b2c725a
fix: enable csr in talk
edeleastar Jul 2, 2023
2240b5e
fix: enable CSR in wall
edeleastar Jul 2, 2023
40e04b7
fix: csr in the remaining pages
edeleastar Jul 2, 2023
623d81b
fix: include kaytex css
edeleastar Jul 2, 2023
ad10a30
chore: package updates
edeleastar Jul 2, 2023
36bfd64
fix: change showdown startup params
edeleastar Jul 2, 2023
a0c98d2
fix: remove markdown init from layout
edeleastar Jul 2, 2023
1996322
fix: remove markdown init
edeleastar Jul 2, 2023
cdf88a6
experiment: debug log
edeleastar Jul 2, 2023
8ed6629
experiment: console debug
edeleastar Jul 2, 2023
4ca347a
experiment: remove kaytex
edeleastar Jul 2, 2023
0ee4f38
experiment: mounting console log
edeleastar Jul 2, 2023
9754c79
experiment: remove katex import
edeleastar Jul 2, 2023
312e634
experiment: renable markdown without showdown
edeleastar Jul 2, 2023
fc25d52
experiment: conditional import of kaytex in lab only
edeleastar Jul 3, 2023
6f337e7
experiment: fix first load
edeleastar Jul 4, 2023
b2061ca
experiment: reconfigure markdown initialisation
edeleastar Jul 4, 2023
30be436
fix: remove package conflicts
edeleastar Jul 4, 2023
12deee9
fix: remove redundant code
edeleastar Jul 4, 2023
492fe89
experiment: relocate markdown kaytex to lib
edeleastar Jul 4, 2023
7d7398c
experiment: refactor note markdown processing
edeleastar Jul 4, 2023
5877a97
experiment: refactor - closer to production
edeleastar Jul 5, 2023
b2765c5
fix: correct panelnote url
edeleastar Jul 5, 2023
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
23 changes: 9 additions & 14 deletions apps/course/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,21 @@
"build": "vite build",
"package": "vite package",
"preview": "vite preview",
"prepare": "svelte-kit sync",
"check": "svelte-check --tsconfig ./tsconfig.json",
"check:watch": "svelte-check --tsconfig ./tsconfig.json --watch",
"lint": "prettier --check --ignore-path=../../.prettierignore . && TIMING=1 eslint \"src\"",
"format": "prettier --write --ignore-path=../../.prettierignore ."
},
"devDependencies": {
"@bobthered/tailwindcss-palette-generator": "^3.1.1",
"@floating-ui/dom": "^1.3.0",
"@skeletonlabs/skeleton": "^1.7.1",
"@floating-ui/dom": "^1.4.3",
"@skeletonlabs/skeleton": "^1.8.0",
"@sveltejs/adapter-auto": "^2.1.0",
"@sveltejs/adapter-netlify": "^2.0.7",
"@sveltejs/kit": "1.20.2",
"@sveltejs/kit": "1.21.0",
"@types/auth0-js": "^9.21.0",
"@types/showdown": "2.0.1",
"auth0-js": "^9.21.0",
"autoprefixer": "^10.4.14",
"buffer": "^6.0.3",
Expand All @@ -28,22 +30,15 @@
"postcss-load-config": "^4.0.1",
"prettier": "^2.8.8",
"svelte": "^3.59.1",
"svelte-check": "^3.4.3",
"svelte-check": "^3.4.4",
"svelte-preprocess": "^5.0.4",
"tailwindcss": "^3.3.2",
"tslib": "^2.5.3",
"tslib": "^2.6.0",
"tutors-reader-lib": "*",
"tutors-ui": "*",
"typescript": "^5.1.3",
"typescript": "^5.1.6",
"ui": "*",
"vite": "^4.3.9",
"@types/showdown": "2.0.1",
"showdown": "2.1.0",
"showdown-copy-code": "^1.0.2",
"showdown-custom-class": "^1.0.0",
"showdown-emoji": "^3.0.0",
"showdown-highlight": "^3.1.0",
"showdown-katex": "^0.8.0"
"vite": "^4.3.9"
},
"type": "module"
}
32 changes: 32 additions & 0 deletions apps/course/src/lib/markdown/rich-markdown.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// import showdown from "showdown";
// import showdownHighlight from "showdown-highlight";
// import { showdownCopyCode } from "showdown-copy-code";
// import customClassExt from "showdown-custom-class";
// import { initRichConverter } from "tutors-reader-lib/src/utils/markdown-utils";

// let converter: any;

// function convertMdToHtml(md: string): string {
// return converter.makeHtml(md);
// }

// export async function initKaytex() {
// //const kaytex = await import("showdown-katex");
// let showdownConverter = new showdown.Converter({
// tables: true,
// emoji: true,
// openLinksInNewWindow: true,
// extensions: [
// showdownHighlight,
// customClassExt,
// showdownCopyCode,
// // kaytex.default({
// // throwOnError: false,
// // displayMode: true,
// // errorColor: "red"
// // })
// ]
// });
// converter = showdownConverter;
// initRichConverter(convertMdToHtml);
// }
3 changes: 1 addition & 2 deletions apps/course/src/routes/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,12 @@
import { getKeys } from "../environment";
import TutorsTerms from "$lib/support/TutorsTerms.svelte";
import { analyticsService } from "tutors-reader-lib/src/services/analytics-service";
import { initMarkdownParser, initServices } from "./tutors-startup";
import { initServices } from "./tutors-startup";
import Sidebars from "$lib/navigators/sidebars/Sidebars.svelte";

let mounted = false;
const themes: any = { tutors, dyslexia, halloween, valentines };
let currentRoute = "";
initMarkdownParser();

storePopup.set({ computePosition, autoUpdate, flip, shift, offset, arrow });

Expand Down
34 changes: 21 additions & 13 deletions apps/course/src/routes/lab/[courseid]/[...loid]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,23 @@
import type { PageData } from "./$types";
import { goto, afterNavigate } from "$app/navigation";
export let data: PageData;
import { page } from "$app/stores";
import { initKaytex } from "tutors-reader-lib/src/utils/markdown-utils";

let refresh = true;

onMount(async () => {
window.addEventListener("keydown", keypressInput);

await initKaytex();
data.lab.convertMd();
const lastSegment = $page.url.pathname.substring($page.url.pathname.lastIndexOf("/") + 1);
if (lastSegment.startsWith("book")) {
data.lab.setFirstPageActive();
} else {
data.lab.setActivePage(lastSegment);
}
refresh = !refresh;
});

onDestroy(() => {
Expand All @@ -15,7 +29,7 @@

afterNavigate(() => {
const elemPage = document.querySelector("#page");
elemPage.scrollTop = 0;
if (elemPage) elemPage.scrollTop = 0;
});

async function keypressInput(e: KeyboardEvent) {
Expand All @@ -32,19 +46,11 @@
</script>

<svelte:head>
<!-- <script
src="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.16.4/katex.min.js"
integrity="sha512-DAZH0Wu7q9Hnm0Fw8tRZsTeQBzIugiUy6k2r7E0KKMlC2nBvvrNSH/LVnGueCXRfDs5epP+Ieoh3L+VzSKi0Aw=="
crossorigin="anonymous"
referrerpolicy="no-referrer"
></script>
<link
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.16.4/katex.min.css"
integrity="sha512-nii0D5CrWiLjtPcfU3pQJifaRLxKKVut/hbsazsodCcIOERZbwLH7dQxzOKy3Ey/Fv8fXCA9+Rf+wQzqklbEJQ=="
crossorigin="anonymous"
referrerpolicy="no-referrer"
/> -->
href="https://cdn.jsdelivr.net/npm/katex@0.16.8/dist/katex.min.css"
integrity="sha384-GvrOXuhMATgEsSwCs4smul74iXGOixntILdUW9XmUC6+HX0sLNAK3q71HotJqlAn"
crossorigin="anonymous" />
</svelte:head>

<div class="block fixed w-full mx-auto bottom-0 lg:hidden bg-primary-50-900-token z-30">
Expand All @@ -67,7 +73,9 @@
<div id="lab-panel" class="flex-1 w-1/2 min-h-screen">
<div class="card bg-surface-100-800-token p-8 lg:px-4 py-8 m-2 rounded-xl">
<article class="mx-auto prose dark:prose-invert max-w-none w-[80%]">
{@html data.lab.content}
{#key refresh}
{@html data.lab.content}
{/key}
</article>
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions apps/course/src/routes/lab/[courseid]/[...loid]/+page.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { initMarkdownParser } from "../../../tutors-startup";
import type { PageLoad } from "./$types";
import { courseService } from "tutors-reader-lib/src/services/course-service";

export const ssr = false;

export const load: PageLoad = async ({ url, params }) => {
initMarkdownParser();
const lab = await courseService.readLab(params.courseid, url.pathname);
const lastSegment = url.pathname.substring(url.pathname.lastIndexOf("/") + 1);
if (lastSegment.startsWith("book")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
{#if data.lo}
<div class="min-h-screen flex w-11/12 mx-auto">
<div class="w-full">
{#key data.lo}
<NoteCard lo="{data.lo}" />
{/key}
<NoteCard lo="{data.lo}" />
</div>
<div class="hidden md:block">
<TopicNavigatorCard topic="{data.lo.parent}" />
Expand Down
2 changes: 1 addition & 1 deletion apps/course/src/routes/note/[courseid]/[...loid]/+page.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { PageLoad } from "./$types";
import { courseService } from "tutors-reader-lib/src/services/course-service";


export const ssr = false;

export const load: PageLoad = async ({ url, params }) => {
const lo = await courseService.readLo(params.courseid, url.pathname);
Expand Down
2 changes: 2 additions & 0 deletions apps/course/src/routes/search/[courseid]/+page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { courseService } from "tutors-reader-lib/src/services/course-service";
import type { Course } from "tutors-reader-lib/src/models/course";
import { currentLo } from "tutors-reader-lib/src/stores/stores";

export const ssr = false;

export const load: PageLoad = async ({ params }) => {
const course: Course = await courseService.readCourse(params.courseid);
currentLo.set(course.lo);
Expand Down
2 changes: 1 addition & 1 deletion apps/course/src/routes/talk/[courseid]/[...loid]/+page.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { PageLoad } from "./$types";
import { courseService } from "tutors-reader-lib/src/services/course-service";


export const ssr = false;

export const load: PageLoad = async ({ url, params }) => {
const lo = await courseService.readLo(params.courseid, url.pathname);
Expand Down
36 changes: 0 additions & 36 deletions apps/course/src/routes/tutors-startup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,42 +6,6 @@ import { presenceService } from "tutors-reader-lib/src/services/presence-service
import { initFirebase } from "tutors-reader-lib/src/utils/firebase-utils";
import { getKeys } from "../environment";
import { goto } from "$app/navigation";
import showdown from "showdown";
import showdownHighlight from "showdown-highlight";
import { showdownCopyCode } from "showdown-copy-code";
import showdownKatex from "showdown-katex";
//const showdownKatex = await import('showdown-katex');
import customClassExt from "showdown-custom-class";
import { initConverter } from "tutors-reader-lib/src/utils/markdown-utils";

let converter: any;

function convertMdToHtml(md: string): string {
return converter.makeHtml(md);
}

export function initMarkdownParser() {
let showdownConverter = new showdown.Converter({
tables: true,
emoji: true,
openLinksInNewWindow: true,
extensions: [
showdownHighlight,
customClassExt,
showdownCopyCode,
showdownKatex({
// maybe you want katex to throwOnError
throwOnError: false,
// disable displayMode
displayMode: false,
// change errorColor to blue
errorColor: "red"
})
]
})
converter = showdownConverter;
initConverter(convertMdToHtml);
}

export async function initServices() {
if (getKeys().firebase.apiKey !== "XXX") {
Expand Down
2 changes: 2 additions & 0 deletions apps/course/src/routes/video/[courseid]/[...loid]/+page.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import type { PageLoad } from "./$types";
import { courseService } from "tutors-reader-lib/src/services/course-service";

export const ssr = false;

export const load: PageLoad = async ({ url, params }) => {
let videoId = url.pathname;
let videoStartEnd = url.searchParams.toString();
Expand Down
2 changes: 2 additions & 0 deletions apps/course/src/routes/wall/[type]/[courseid]/+page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import type { PageLoad } from "./$types";
import { courseService } from "tutors-reader-lib/src/services/course-service";
import { currentLo } from "tutors-reader-lib/src/stores/stores";

export const ssr = false;

export const load: PageLoad = async ({ params }) => {
const course = await courseService.readCourse(params.courseid);
const los = await courseService.readWall(params.courseid, params.type);
Expand Down
Loading