Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: shiki plugin space style #769

Merged
merged 1 commit into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/khaki-falcons-act.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@rspress/theme-default": patch
"@rspress/plugin-shiki": patch
---

fix: plugin-shiki space style
4 changes: 4 additions & 0 deletions packages/plugin-shiki/shiki.css
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
--shiki-token-link: #f9a76d;
}

.rspress-doc span.line {
padding: 0 1.25rem;
}

.diff,
.code-line-highlighted {
transition: background-color 0.5s;
Expand Down
6 changes: 6 additions & 0 deletions packages/plugin-shiki/src/shiki/rehypePlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ export const rehypePluginShiki: Plugin<[Options], Root> = function ({
}
});

// Strip the final empty span
const lastLine = codeLines[codeLines.length - 1];
if (lastLine?.children.length === 0) {
codeLines.pop();
}

// @ts-expect-error
parent.children.splice(index!, 1, {
type: 'element',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,10 @@ export function PackageManagerTabs({
{Object.entries(commandInfo).map(([key, value]) => (
<Tab key={key}>
<Pre>
<Code className="language-js">{value}</Code>
{/* For this case, we can specify to highlight the code in runtime instead of compile time */}
<Code className="language-js" codeHighlighter="prism">
{value}
</Code>
</Pre>
</Tab>
))}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@ import { SvgWrapper } from '#theme/components/SvgWrapper';
export interface CodeProps {
children: string;
className?: string;
codeHighlighter?: 'prism' | 'shiki';
meta?: string;
}

export function Code(props: CodeProps) {
const { siteData } = usePageData();
const { defaultWrapCode, codeHighlighter } = siteData.markdown;
const codeHighlighter =
props.codeHighlighter ?? siteData.markdown.codeHighlighter;
const { defaultWrapCode } = siteData.markdown;
const [codeWrap, setCodeWrap] = useState(defaultWrapCode);
const wrapButtonRef = useRef<HTMLButtonElement>(null);
const codeBlockRef = useRef<HTMLDivElement>();
Expand Down
Loading