From 50a4bf6cb3fcef94e0be3c40399599d613c0b85e Mon Sep 17 00:00:00 2001 From: Mishig Date: Wed, 27 Sep 2023 00:23:19 +0200 Subject: [PATCH] Revert "Add node ci for sveltekit (#404)" This reverts commit 54857fe592547274a4929ca53f2bafc2857965a9. --- .github/workflows/lint-svelte-kit.yml | 33 ------------ kit/.prettierrc | 1 + kit/package-lock.json | 14 ----- kit/package.json | 6 +-- kit/preprocess.js | 51 ++++++++----------- kit/src/lib/CopyButton.svelte | 2 +- kit/src/lib/CourseFloatingBanner.svelte | 4 +- kit/src/lib/DocNotebookDropdown.svelte | 7 +-- kit/src/lib/Docstring.svelte | 10 ++-- kit/src/lib/Dropdown.svelte | 6 ++- kit/src/lib/DropdownEntry.svelte | 2 +- kit/src/lib/DropdownMenu.svelte | 6 +-- kit/src/lib/FrameworkContentBlock.svelte | 13 +++-- kit/src/lib/FrameworkSwitch.svelte | 10 ++-- kit/src/lib/FrameworkSwitchCourse.svelte | 6 +-- kit/src/lib/InferenceApi.svelte | 12 ++--- kit/src/lib/PipelineIcon.svelte | 10 ++-- .../IconImageClassification.svelte | 8 ++- .../IconSentenceSimilarity.svelte | 4 +- .../PipelineIcons/IconTextGeneration.svelte | 4 +- kit/src/lib/TokenizersLanguageContent.svelte | 8 +-- kit/src/lib/Tooltip.svelte | 2 +- kit/src/lib/pipeline.ts | 4 +- kit/src/lib/stores.ts | 7 ++- kit/src/lib/tooltip.ts | 2 +- kit/src/lib/types.ts | 9 ---- 26 files changed, 93 insertions(+), 148 deletions(-) delete mode 100644 .github/workflows/lint-svelte-kit.yml diff --git a/.github/workflows/lint-svelte-kit.yml b/.github/workflows/lint-svelte-kit.yml deleted file mode 100644 index 447b84c3..00000000 --- a/.github/workflows/lint-svelte-kit.yml +++ /dev/null @@ -1,33 +0,0 @@ -name: SvelteKit Lint -on: - pull_request: - paths: - - "kit/**" - - ".github/workflows/lint-svelte-kit.yml" - push: - branches: - - main - -jobs: - lint: - runs-on: ubuntu-latest - timeout-minutes: 10 - - steps: - - uses: actions/checkout@v3 - - - uses: actions/setup-node@v3 - with: - node-version: "18" - - - name: Install dependencies - run: npm install ci - working-directory: kit - - - name: Checking lint/format errors - run: npm run lint - working-directory: kit - - - name: Checking type errors - run: npm run check - working-directory: kit \ No newline at end of file diff --git a/kit/.prettierrc b/kit/.prettierrc index de36577e..7b1b699c 100644 --- a/kit/.prettierrc +++ b/kit/.prettierrc @@ -3,5 +3,6 @@ "trailingComma": "es5", "printWidth": 100, "plugins": ["prettier-plugin-svelte", "prettier-plugin-tailwindcss"], + "pluginSearchDirs": ["."], "overrides": [{ "files": "*.svelte", "options": { "parser": "svelte" } }] } diff --git a/kit/package-lock.json b/kit/package-lock.json index 18048c03..ecfe86f9 100644 --- a/kit/package-lock.json +++ b/kit/package-lock.json @@ -14,8 +14,6 @@ "@tailwindcss/aspect-ratio": "^0.4.2", "@tailwindcss/forms": "^0.5.6", "@tailwindcss/typography": "^0.5.10", - "@types/js-yaml": "^4.0.6", - "@types/node": "^20.6.5", "@typescript-eslint/eslint-plugin": "^6.7.2", "autoprefixer": "^10.4.14", "cheerio": "^1.0.0-rc.12", @@ -760,24 +758,12 @@ "integrity": "sha512-LG4opVs2ANWZ1TJoKc937iMmNstM/d0ae1vNbnBvBhqCSezgVUOzcLCqbI5elV8Vy6WKwKjaqR+zO9VKirBBCA==", "dev": true }, - "node_modules/@types/js-yaml": { - "version": "4.0.6", - "resolved": "https://registry.npmjs.org/@types/js-yaml/-/js-yaml-4.0.6.tgz", - "integrity": "sha512-ACTuifTSIIbyksx2HTon3aFtCKWcID7/h3XEmRpDYdMCXxPbl+m9GteOJeaAkiAta/NJaSFuA7ahZ0NkwajDSw==", - "dev": true - }, "node_modules/@types/json-schema": { "version": "7.0.13", "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.13.tgz", "integrity": "sha512-RbSSoHliUbnXj3ny0CNFOoxrIDV6SUGyStHsvDqosw6CkdPV8TtWGlfecuK4ToyMEAql6pzNxgCFKanovUzlgQ==", "dev": true }, - "node_modules/@types/node": { - "version": "20.6.5", - "resolved": "https://registry.npmjs.org/@types/node/-/node-20.6.5.tgz", - "integrity": "sha512-2qGq5LAOTh9izcc0+F+dToFigBWiK1phKPt7rNhOqJSr35y8rlIBjDwGtFSgAI6MGIhjwOVNSQZVdJsZJ2uR1w==", - "dev": true - }, "node_modules/@types/pug": { "version": "2.0.6", "resolved": "https://registry.npmjs.org/@types/pug/-/pug-2.0.6.tgz", diff --git a/kit/package.json b/kit/package.json index ceb60586..a7b70f09 100644 --- a/kit/package.json +++ b/kit/package.json @@ -8,8 +8,8 @@ "preview": "vite preview", "check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json", "check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch", - "lint": "prettier --check --plugin prettier-plugin-svelte .", - "format": "prettier --write --plugin prettier-plugin-svelte ." + "lint": "prettier --plugin-search-dir . --check . && eslint .", + "format": "prettier --plugin-search-dir . --write ." }, "devDependencies": { "@sveltejs/adapter-auto": "^2.0.0", @@ -18,8 +18,6 @@ "@tailwindcss/aspect-ratio": "^0.4.2", "@tailwindcss/forms": "^0.5.6", "@tailwindcss/typography": "^0.5.10", - "@types/js-yaml": "^4.0.6", - "@types/node": "^20.6.5", "@typescript-eslint/eslint-plugin": "^6.7.2", "autoprefixer": "^10.4.14", "cheerio": "^1.0.0-rc.12", diff --git a/kit/preprocess.js b/kit/preprocess.js index 903182d5..bc55952a 100644 --- a/kit/preprocess.js +++ b/kit/preprocess.js @@ -364,7 +364,7 @@ export const mdsvexPreprocess = { // content = addCourseImports(content); // } content = markKatex(content, markedKatex); - content = escapeSvelteConditionals(content); + content = escapeSvelteConditionals(content) const processed = await _mdsvexPreprocess.markup({ content, filename }); processed.code = renderKatex(processed.code, markedKatex); processed.code = headingWithAnchorLink(processed.code); @@ -461,53 +461,44 @@ let hfDocBodyEnd = false; function escapeSvelteSpecialChars() { return transform; - function isWithinDocBody(node) { - if (node.value === "") { - hfDocBodyStart = true; - hfDocBodyEnd = false; - } - if (node.value === "") { - hfDocBodyEnd = true; - } - return hfDocBodyStart && !hfDocBodyEnd; - } - function transform(tree) { visit(tree, "text", onText); visit(tree, "html", onHtml); } function onText(node) { - if (!isWithinDocBody(node)) { - return; - } node.value = node.value.replaceAll("{", "{"); node.value = node.value.replaceAll("<", "<"); } function onHtml(node) { - if (!isWithinDocBody(node)) { - return; + if(node.value === ""){ + hfDocBodyStart = true; + hfDocBodyEnd = false; + } + if(node.value === ""){ + hfDocBodyEnd = true; } const RE_TAG_NAME = /<\/?(\w+)/; const match = node.value.match(RE_TAG_NAME); - const REGEX_VALID_START_END_TAG = /^<(\w+)[^>]*>.*<\/\1>$/s; if (match) { const tagName = match[1]; if (!validTags.includes(tagName)) { node.value = node.value.replaceAll("<", "<"); - } else if (htmlTags.includes(tagName) && REGEX_VALID_START_END_TAG.test(node.value.trim())) { + }else if(hfDocBodyStart && !hfDocBodyEnd && htmlTags.includes(tagName)){ + const REGEX_VALID_START_END_TAG = /^<(\w+)[^>]*>.*<\/\1>$/s; + if(!REGEX_VALID_START_END_TAG.test(node.value.trim())){ + return; + } const $ = cheerio.load(node.value); // Go through each text node in the HTML and replace "{" with "{" - $("*") - .contents() - .each((index, element) => { - if (element.type === "text") { - element.data = element.data.replaceAll("{", "{"); - } - }); + $('*').contents().each((index, element) => { + if (element.type === 'text') { + element.data = element.data.replaceAll("{", "{"); + } + }); // Update the remark HTML node with the modified HTML - node.value = $("body").html(); + node.value = $('body').html(); } } } @@ -614,12 +605,12 @@ function headingWithAnchorLink(code) { }); } -function escapeSvelteConditionals(code) { +function escapeSvelteConditionals(code){ const REGEX_SVELTE_IF_START = /(\{#if[^}]+\})/g; const SVELTE_ELSE = "{:else}"; const SVELTE_IF_END = "{/if}"; - code = code.replace(REGEX_SVELTE_IF_START, "\n\n$1\n\n"); + code = code.replace(REGEX_SVELTE_IF_START, '\n\n$1\n\n'); code = code.replaceAll(SVELTE_ELSE, `\n\n${SVELTE_ELSE}\n\n`); code = code.replaceAll(SVELTE_IF_END, `\n\n${SVELTE_IF_END}\n\n`); return code; -} +} \ No newline at end of file diff --git a/kit/src/lib/CopyButton.svelte b/kit/src/lib/CopyButton.svelte index 233c790a..8bb87ca8 100644 --- a/kit/src/lib/CopyButton.svelte +++ b/kit/src/lib/CopyButton.svelte @@ -33,7 +33,7 @@