Compare commits

..

No commits in common. "1c174a3b1cb5bca00d0de177a7717093fc1dbd22" and "ac7b41ecfc56ee527bb16c13c5c1c9518d4e2ff0" have entirely different histories.

3 changed files with 5 additions and 17 deletions

View File

@ -6,7 +6,6 @@
import ComboBox from './ComboBox.svelte' import ComboBox from './ComboBox.svelte'
import Icon from '@iconify/svelte' import Icon from '@iconify/svelte'
import { goto } from '$app/navigation' import { goto } from '$app/navigation'
import hljs from 'highlight.js'
type Language = { type Language = {
text: string text: string
@ -32,7 +31,7 @@
}) })
selectedLang.subscribe((lang) => { selectedLang.subscribe((lang) => {
textWrap = lang === 'plaintext' || lang === 'markdown' textWrap = lang === 'plt' || lang === 'md'
}) })
$: { $: {

View File

@ -1,5 +1,3 @@
import hljs from 'highlight.js'
export const slugify = (str: string) => export const slugify = (str: string) =>
str str
.trim() .trim()
@ -39,8 +37,3 @@ export const byId = (id: string) => document.getElementById(id)
export function isInIframe(): boolean { export function isInIframe(): boolean {
return window !== window.parent return window !== window.parent
} }
export function getHljsLangFromShort(short: string): string {
const langs = hljs.listLanguages().map((lang) => ({ lang, short: shorten(lang) }))
return langs.find((l) => l.short === short)?.lang ?? 'plaintext'
}

View File

@ -8,7 +8,7 @@
import rehypeStringify from 'rehype-stringify' import rehypeStringify from 'rehype-stringify'
import hljs from 'highlight.js' import hljs from 'highlight.js'
import 'highlight.js/styles/nord.min.css' import 'highlight.js/styles/nord.min.css'
import { getHljsLangFromShort, getLangFromUrl, isInIframe } from '$lib/utils' import { getLangFromUrl, isInIframe } from '$lib/utils'
import TopBar from '../components/TopBar.svelte' import TopBar from '../components/TopBar.svelte'
import Icon from '@iconify/svelte' import Icon from '@iconify/svelte'
import CodeView from '../components/CodeView.svelte' import CodeView from '../components/CodeView.svelte'
@ -26,16 +26,12 @@
let lang = getLangFromUrl() let lang = getLangFromUrl()
// Remove github flavored markdown, redundant with markdown // Remove github flavored markdown, redundant with markdown
lang = lang === 'gflm' ? 'md' : lang lang = lang === 'gflm' ? 'md' : lang
// Get the correct language name for hljs
lang = getHljsLangFromShort(lang)
// decompress the data // decompress the data
const { decompress } = await import('$lib/brotli') const { decompress } = await import('$lib/brotli')
decompressed = await decompress(hash) decompressed = await decompress(hash)
// Markdown // Markdown
if (lang === 'markdown') { if (lang === 'md') {
const html = await unified() const html = await unified()
.use(remarkParse) .use(remarkParse)
.use(remarkGfm) .use(remarkGfm)
@ -47,12 +43,12 @@
htmlContent = html.toString() htmlContent = html.toString()
} }
// Plain text // Plain text
else if (lang === 'plaintext' || !lang) { else if (lang === 'plt' || !lang) {
isPlainText = true isPlainText = true
} }
// Code // Code
else { else {
htmlContent = hljs.highlight(decompressed, { language: lang }).value htmlContent = hljs.highlight(lang, decompressed).value
} }
} else { } else {
// Redirect to editor page // Redirect to editor page