-
Notifications
You must be signed in to change notification settings - Fork 34
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
feat: add support collapsed-lines
for code highlighters
#246
Conversation
Pull Request Test Coverage Report for Build 10871006435Details
💛 - Coveralls |
@@ -78,5 +80,22 @@ export const prepareConfigFile = ( | |||
) | |||
} | |||
|
|||
return app.writeTemp('prismjs/config.js', imports.join('\n')) | |||
imports.push( | |||
`import "${getRealPath('@vuepress/highlighter-helper/styles/collapsed-lines.css', url)}"`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should only import these when the feature is enabled?
@@ -29,6 +33,7 @@ export const prismjsPlugin = ({ | |||
md.use<PreWrapperOptions>(preWrapperPlugin, { preWrapper }) | |||
if (preWrapper) { | |||
md.use(lineNumbersPlugin, { lineNumbers, removeLastLine: true }) | |||
md.use(collapsedLinesPlugin, { collapsedLines, removeLastLine: true }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this plugin should be used anyway?
removeLastLine: true, | ||
}) | ||
md.use(lineNumbersPlugin, { lineNumbers, removeLastLine: true }) | ||
md.use(collapsedLinesPlugin, { collapsedLines, removeLastLine: true }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same
@@ -64,5 +66,22 @@ export const prepareConfigFile = ( | |||
) | |||
} | |||
|
|||
return app.writeTemp('shiki/config.js', imports.join('\n')) | |||
imports.push( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same
if (preWrapper) { | ||
md.use<MarkdownItLineNumbersOptions>(lineNumbersPlugin, { lineNumbers }) | ||
md.use(lineNumbersPlugin, { lineNumbers }) | ||
md.use(collapsedLinesPlugin, { collapsedLines }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same
selector = 'div[class*="language-"].has-collapsed-lines > .collapsed-lines', | ||
}: { selector?: string } = {}): void => { | ||
if (__VUEPRESS_SSR__) return | ||
window.addEventListener('click', (e) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer useEventListener
, I discourage to see __VUEPRESS_SSR__
as a judgement to visit window outside onMounted
@property --vp-collapsed-lines-bg { | ||
inherits: false; | ||
initial-value: #fff; | ||
syntax: '<color>'; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this needed?
https://developer.mozilla.org/zh-CN/docs/Web/CSS/@property From the table, firefox only supports it from 128. I am not sure if there will be errors under lower version of firfox.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't worry, in lower versions it will just be recognized as a regular CSS variable, and after the downgrade, the corresponding background gradient transition animation simply won't take effect.
@@ -23,7 +23,7 @@ div[class*='language-'] { | |||
border-right: 1px solid var(--code-c-highlight-bg, var(--code-c-text)); | |||
border-radius: var(--code-border-radius) 0 0 var(--code-border-radius); | |||
|
|||
transition: border var(--t-color); | |||
transition: border var(--vp-t-color); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice catch, could this be in a sperate PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see that it was fixed in another commit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some documentation improvements are suggested
docs/plugins/markdown/prismjs.md
Outdated
|
||
- `number`: collapse the code block starting from line `number`, for example, `12` means collapsing the code block starting from line 12. | ||
- `true`: Equivalent to `15`, collapsing the code block starting from line 15. | ||
- `false`: Disable code block collapsed, but `:collapsed-lines` can still be added to collapse individual code blocks. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the description can be changed to:
Add support for code block collapsing, but disable it globally
Also I would prefer the word code block collapsing
instead of code block collapsed.
docs/plugins/markdown/prismjs.md
Outdated
- `false`: Disable code block collapsed, but `:collapsed-lines` can still be added to collapse individual code blocks. | ||
- `'disabled'`: Completely disable code block collapsed, `:collapsed-lines` will not take effect. | ||
|
||
You can add the `:collapsed-lines` / `:no-collapsed-lines` marker to the code block to override the settings in the configuration item. You can also add `=` after `:collapsed-lines` to customize the starting collapsed line number, for example, `:collapsed-lines=12` means collapsing the code block starting from line 12. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to customize the starting line number being collapsed
docs/plugins/markdown/prismjs.md
Outdated
- `false`: Disable code block collapsed, but `:collapsed-lines` can still be added to collapse individual code blocks. | ||
- `'disabled'`: Completely disable code block collapsed, `:collapsed-lines` will not take effect. | ||
|
||
You can add the `:collapsed-lines` / `:no-collapsed-lines` marker to the code block to override the settings in the configuration item. You can also add `=` after `:collapsed-lines` to customize the starting collapsed line number, for example, `:collapsed-lines=12` means collapsing the code block starting from line 12. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To override global settings, you can add the xxx marker to code blocks.
docs/plugins/markdown/prismjs.md
Outdated
|
||
- Default: `'disabled'` | ||
|
||
- Details: Whether to enable code block collapsing. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this could be changed to Default behavior of code block collapsing
And the description of the first two settings could be added with the words by default
Before submitting the PR, please make sure you do the following
close #123
).What is the purpose of this pull request?
Description
Screenshots
Before
After