Skip to content

Commit

Permalink
fix(hot): mitigate empty code blocks (hotfix)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tahul committed Jul 20, 2022
1 parent 73741f3 commit a13cca9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/runtime/server/api/highlight.ts
Expand Up @@ -40,7 +40,13 @@ const resolveTheme = (theme: string | Record<string, string>): Record<string, Th
*/
const resolveBody = (body: Partial<HighlightParams>) => {
// Assert body schema
if (typeof body.code !== 'string') { throw createError({ statusMessage: 'Bad Request', statusCode: 400, message: 'Missing code key.' }) }
if (typeof body.code !== 'string') {
// TODO: Maybe remove this hotfix?
// I could not reproduce the issue with local content, but it might happen when using `parseContent` or external content sources.
body.code = ''

// throw createError({ statusMessage: 'Bad Request', statusCode: 400, message: 'Missing code key.' })
}

return {
// Remove trailing carriage returns
Expand Down
2 changes: 2 additions & 0 deletions src/runtime/server/storage.ts
Expand Up @@ -10,7 +10,9 @@ import { transformContent } from '../transformers'
import type { ModuleOptions } from '../../module'
import { getPreview, isPreview } from './preview'
// eslint-disable-next-line import/named
// @ts-ignore
import { useNitroApp, useRuntimeConfig, useStorage } from '#imports'
// @ts-ignore
import { transformers as customTransformers } from '#content/virtual/transformers'

interface ParseContentOptions {
Expand Down

0 comments on commit a13cca9

Please sign in to comment.