( file: DiffFile, theme: HighlightThemeInput = "dark", )
| 677 | |
| 678 | /** Highlight a diff file and return just the rendered line trees the UI needs. */ |
| 679 | export async function loadHighlightedDiff( |
| 680 | file: DiffFile, |
| 681 | theme: HighlightThemeInput = "dark", |
| 682 | ): Promise<HighlightedDiffCode> { |
| 683 | try { |
| 684 | const highlighter = await prepareHighlighter(file.language, theme); |
| 685 | return queueHighlightedWork(() => { |
| 686 | const highlighted = renderDiffWithHighlighter( |
| 687 | file.metadata, |
| 688 | highlighter, |
| 689 | pierreRenderOptions(theme), |
| 690 | ); |
| 691 | return aliasHighlightedContextLines(file, { |
| 692 | deletionLines: highlighted.code.deletionLines as Array<HastNode | undefined>, |
| 693 | additionLines: highlighted.code.additionLines as Array<HastNode | undefined>, |
| 694 | }); |
| 695 | }); |
| 696 | } catch { |
| 697 | const fallbackTheme = highlightThemeAppearance(theme); |
| 698 | const highlighter = await prepareHighlighter("text", fallbackTheme); |
| 699 | return queueHighlightedWork(() => { |
| 700 | const highlighted = renderDiffWithHighlighter( |
| 701 | { ...file.metadata, lang: "text" }, |
| 702 | highlighter, |
| 703 | pierreRenderOptions(fallbackTheme), |
| 704 | ); |
| 705 | return aliasHighlightedContextLines(file, { |
| 706 | deletionLines: highlighted.code.deletionLines as Array<HastNode | undefined>, |
| 707 | additionLines: highlighted.code.additionLines as Array<HastNode | undefined>, |
| 708 | }); |
| 709 | }); |
| 710 | } |
| 711 | } |
| 712 | |
| 713 | /** Highlight a full source file for unchanged lines synthesized during gap expansion. */ |
| 714 | export async function loadHighlightedSourceLines({ |
no test coverage detected