-
-
Notifications
You must be signed in to change notification settings - Fork 265
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(content): introduce build-time rendering/highlighting for markdo…
…wn (#1174)
- Loading branch information
1 parent
e029a28
commit 9ccf6b2
Showing
28 changed files
with
390 additions
and
289 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,6 @@ | ||
import { withHighlighter } from '@analogjs/content'; | ||
import { ContentRenderer, NoopContentRenderer } from '@analogjs/content'; | ||
import { Provider } from '@angular/core'; | ||
import { PrismHighlighter } from './lib/prism-highlighter'; | ||
|
||
export { PrismHighlighter }; | ||
|
||
export function withPrismHighlighter(): Provider { | ||
return withHighlighter({ useClass: PrismHighlighter }); | ||
export function withPrismHighlighter(): Provider[] { | ||
return [{ provide: ContentRenderer, useClass: NoopContentRenderer }]; | ||
} |
56 changes: 0 additions & 56 deletions
56
packages/content/prism-highlighter/src/lib/prism-highlighter.spec.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,32 @@ | ||
import { withHighlighter } from '@analogjs/content'; | ||
import { ContentRenderer, NoopContentRenderer } from '@analogjs/content'; | ||
import { Provider } from '@angular/core'; | ||
import type { BundledLanguage } from 'shiki'; | ||
import { | ||
defaultHighlighterOptions, | ||
SHIKI_CONTAINER_OPTION, | ||
SHIKI_HIGHLIGHT_OPTIONS, | ||
SHIKI_HIGHLIGHTER_OPTIONS, | ||
ShikiHighlighter, | ||
type ShikiHighlighterOptions, | ||
type ShikiHighlightOptions, | ||
} from './lib/shiki-highlighter'; | ||
import type { | ||
BundledLanguage, | ||
BundledTheme, | ||
CodeOptionsMeta, | ||
CodeOptionsMultipleThemes, | ||
CodeOptionsSingleTheme, | ||
CodeToHastOptionsCommon, | ||
} from 'shiki'; | ||
|
||
export { ShikiHighlighter }; | ||
export type ShikiHighlightOptions = Partial< | ||
Omit<CodeToHastOptionsCommon<BundledLanguage>, 'lang'> | ||
> & | ||
CodeOptionsMeta & | ||
Partial<CodeOptionsSingleTheme<BundledTheme>> & | ||
Partial<CodeOptionsMultipleThemes<BundledTheme>>; | ||
|
||
export interface WithShikiHighlighterOptions { | ||
highlighter?: Partial<ShikiHighlighterOptions> & { | ||
additionalLangs?: BundledLanguage[]; | ||
}; | ||
highlight?: ShikiHighlightOptions; | ||
export type WithShikiHighlighterOptions = ShikiHighlightOptions & { | ||
container?: string; | ||
} | ||
|
||
export function withShikiHighlighter({ | ||
highlighter = {}, | ||
highlight = {}, | ||
container = '%s', | ||
}: WithShikiHighlighterOptions = {}): Provider { | ||
if (!highlighter.themes) { | ||
if (highlight.theme) { | ||
highlighter.themes = [highlight.theme]; | ||
} else if (highlight.themes && typeof highlight.themes === 'object') { | ||
highlighter.themes = Object.values(highlight.themes) as string[]; | ||
} else { | ||
highlighter.themes = defaultHighlighterOptions.themes; | ||
} | ||
} | ||
|
||
if (!highlighter.langs) { | ||
highlighter.langs = defaultHighlighterOptions.langs; | ||
} | ||
|
||
if (highlighter.additionalLangs) { | ||
highlighter.langs.push(...highlighter.additionalLangs); | ||
delete highlighter.additionalLangs; | ||
} | ||
}; | ||
|
||
export function withShikiHighlighter( | ||
_opts: WithShikiHighlighterOptions = {} | ||
): Provider[] { | ||
return [ | ||
{ provide: SHIKI_HIGHLIGHTER_OPTIONS, useValue: highlighter }, | ||
{ provide: SHIKI_HIGHLIGHT_OPTIONS, useValue: highlight }, | ||
{ provide: SHIKI_CONTAINER_OPTION, useValue: container }, | ||
withHighlighter({ useClass: ShikiHighlighter }), | ||
{ | ||
provide: ContentRenderer, | ||
useClass: NoopContentRenderer, | ||
}, | ||
]; | ||
} |
30 changes: 0 additions & 30 deletions
30
packages/content/shiki-highlighter/src/lib/shiki-highlighter.spec.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.