Skip to content

Commit

Permalink
fix: codeHieghtLimit frontmatter priority
Browse files Browse the repository at this point in the history
  • Loading branch information
YunYouJun committed Feb 14, 2024
1 parent 47351d5 commit 5e6b6c2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
3 changes: 1 addition & 2 deletions packages/valaxy/client/styles/common/code.scss
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,9 @@ html:not(.dark) .vp-code-dark {
}

div[class*="language-"] {
overflow-y: hidden;
overflow: auto hidden;
position: relative;
background-color: var(--va-code-block-bg);
overflow-x: auto;
}

[class*='language-'] pre,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import type MarkdownIt from 'markdown-it'
import type { SiteConfig } from 'valaxy/types'
import type { ThemeOptions } from '../../types'
import type { MarkdownEnv } from '../../env'

export interface Options {
hasSingleTheme: boolean
Expand Down Expand Up @@ -32,8 +33,9 @@ export function extractTitle(info: string, html = false) {
return info.match(/\[(.*)\]/)?.[1] || extractLang(info) || 'txt'
}

function getCodeHeightLimitStyle(options: Options) {
const codeHeightLimit = options?.siteConfig?.codeHeightLimit
function getCodeHeightLimitStyle(options: Options, env: MarkdownEnv) {
// frontmatter has higher priority
const codeHeightLimit = env.frontmatter?.codeHeightLimit || options?.siteConfig?.codeHeightLimit
if (codeHeightLimit === undefined || codeHeightLimit <= 0)
return ''

Expand All @@ -51,7 +53,7 @@ function getCodeHeightLimitStyle(options: Options) {
export function preWrapperPlugin(md: MarkdownIt, options: Options) {
const fence = md.renderer.rules.fence!
md.renderer.rules.fence = (...args) => {
const [tokens, idx] = args
const [tokens, idx, _, env] = args
const token = tokens[idx]
// remove title from info
token.info = token.info.replace(/\[.*\]/, '')
Expand All @@ -60,7 +62,7 @@ export function preWrapperPlugin(md: MarkdownIt, options: Options) {
const rawCode = fence(...args)

return `
<div ${getCodeHeightLimitStyle(options)} class="language-${lang}${getAdaptiveThemeMarker(options)}${
<div ${getCodeHeightLimitStyle(options, env)} class="language-${lang}${getAdaptiveThemeMarker(options)}${
/ active( |$)/.test(token.info) ? ' active' : ''
}">
<button title="Copy Code" class="copy"></button><span class="lang">${lang}</span>${rawCode}<button class="collapse"></button>
Expand Down

1 comment on commit 5e6b6c2

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉 Published on https://yun.valaxy.site as production
🚀 Deployed on https://65cd04b4fbdf020e8f5845e1--valaxy.netlify.app

Please sign in to comment.