Browse Source

fix(patch): unhandled unsupported language error

fall back to rendering line without formatting

in the future we should lazy load other/ all languages
master
DanConwayDev 2 years ago
parent
commit
3f83d10146
No known key found for this signature in database
GPG Key ID: 68E15486D73F75E1
  1. 32
      src/lib/components/events/content/Patch.svelte

32
src/lib/components/events/content/Patch.svelte

@ -46,6 +46,19 @@ @@ -46,6 +46,19 @@
return '#'
}
}
let getFortmattedDiffHtml = (
change: Change,
language: string
): string | undefined => {
try {
return hljs.highlight(
change.type == 'normal' ? change.content : change.content.substring(1),
{ language }
).value
} catch {
return undefined
}
}
</script>
<div class="">
@ -170,16 +183,19 @@ @@ -170,16 +183,19 @@
class:pb-3={index === file.chunks.length - 1 &&
i === chunk.changes.length - 1}
>
{#if getFortmattedDiffHtml(change, (file.to || file.from)
?.split('.')
.pop() || '')}
<!-- eslint-disable-next-line svelte/no-at-html-tags -->
{@html hljs.highlight(
change.type == 'normal'
{@html getFortmattedDiffHtml(
change,
(file.to || file.from)?.split('.').pop() || ''
)}
{:else}
{change.type == 'normal'
? change.content
: change.content.substring(1),
{
language:
(file.to || file.from)?.split('.').pop() || '',
}
).value}
: change.content.substring(1)}
{/if}
{#if (change.type == 'normal' ? change.content : change.content.substring(1)).length === 0}
<!-- force empty line to have height -->
<span></span>

Loading…
Cancel
Save