Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0e38265

Browse files
authored
feat(plugin-md-power): add full-width support for table container, close #740 (#741)
1 parent fbb6ec9 commit 0e38265

File tree

6 files changed

+75
-3
lines changed

6 files changed

+75
-3
lines changed

docs/en/guide/markdown/table.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ export default defineUserConfig({
3333
// Whether the table width is the max-content width
3434
// Inline elements will not wrap automatically; a scrollbar is displayed when the content exceeds the container width.
3535
maxContent: false,
36+
// The table width defaults to occupying the entire row.
37+
fullWidth: false,
3638
/**
3739
* Copy as HTML/Markdown
3840
* `true` is equivalent to `'all'`, enabling both HTML and Markdown copying.
@@ -82,6 +84,10 @@ Displays a copy button in the top-right corner of the table for copying as HTML
8284
Inline elements will not wrap automatically; a scrollbar is displayed when the content exceeds the container width.
8385
:::
8486

87+
::: field name="fullWidth" type="boolean" optional default="false"
88+
The table width defaults to occupying the entire row.
89+
:::
90+
8591
::: field name="hl-rows" type="string" optional
8692
Configures row highlighting within the table.
8793

@@ -208,6 +214,28 @@ Built-in `type` support: `tip`, `note`, `info`, `success`, `warning`, `danger`,
208214

209215
:::
210216

217+
**Input:**
218+
219+
```md
220+
::: table full-width
221+
| Header 1 | Header 2 | Header 3 |
222+
|----------|----------|----------|
223+
| Cell 1 | Cell 2 | Cell 3 |
224+
| Row 2 | Data | Info |
225+
:::
226+
```
227+
228+
**Output:**
229+
230+
::: table full-width
231+
232+
| Header 1 | Header 2 | Header 3 |
233+
|----------|----------|----------|
234+
| Cell 1 | Cell 2 | Cell 3 |
235+
| Row 2 | Data | Info |
236+
237+
:::
238+
211239
### Table Row Highlighting
212240

213241
**Input:**

docs/guide/markdown/table.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ export default defineUserConfig({
3131
// 表格宽度是否为最大内容宽度
3232
// 行内元素不再自动换行,超出容器宽度时表格显示滚动条
3333
maxContent: false,
34+
// 表格宽度默认占据整行
35+
fullWidth: false,
3436
/**
3537
* 复制为 html/markdown
3638
* true 相当于 `all`,相当于同时启用 html 和 markdown
@@ -80,6 +82,10 @@ export default defineUserConfig({
8082
行内元素不再自动换行,超出容器宽度时表格显示滚动条
8183
:::
8284

85+
::: field name="fullWidth" type="boolean" optional default="false"
86+
表格宽度默认占据整行
87+
:::
88+
8389
::: field name="hl-rows" type="string" optional
8490
配置表格中的行高亮。
8591

@@ -205,6 +211,28 @@ export default defineUserConfig({
205211

206212
:::
207213

214+
**输入:**
215+
216+
```md
217+
::: table full-width
218+
| Header 1 | Header 2 | Header 3 |
219+
|----------|----------|----------|
220+
| Cell 1 | Cell 2 | Cell 3 |
221+
| Row 2 | Data | Info |
222+
:::
223+
```
224+
225+
**输出:**
226+
227+
::: table full-width
228+
229+
| Header 1 | Header 2 | Header 3 |
230+
|----------|----------|----------|
231+
| Cell 1 | Cell 2 | Cell 3 |
232+
| Row 2 | Data | Info |
233+
234+
:::
235+
208236
### 表格行高亮
209237

210238
**输入:**

plugins/plugin-md-power/src/client/components/VPTable.vue

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ const props = defineProps<{
1212
copy?: false | 'all' | 'html' | 'md'
1313
/** 最大化内容 */
1414
maxContent?: boolean
15+
/** 填充整行宽度 */
16+
fullWidth?: boolean
1517
/** @internal */
1618
markdown?: string
1719
}>()
@@ -33,7 +35,7 @@ function onCopy(type: 'html' | 'md') {
3335
</script>
3436

3537
<template>
36-
<div class="vp-table" :class="{ [align || 'left']: true }">
38+
<div class="vp-table" :class="{ [align || 'left']: true, full: fullWidth }">
3739
<div class="table-container">
3840
<div class="table-content">
3941
<div v-if="copy" class="table-toolbar">
@@ -144,6 +146,13 @@ function onCopy(type: 'html' | 'md') {
144146
width: max-content;
145147
}
146148
149+
.vp-table.full,
150+
.vp-table.full .table-container,
151+
.vp-table.full .table-content,
152+
.vp-table.full .table-content table {
153+
min-width: 100%;
154+
}
155+
147156
/* ----- Highlight --------- */
148157
.vp-table table th.tip,
149158
.vp-table table td.tip,

plugins/plugin-md-power/src/node/container/table.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export interface TableContainerAttrs extends TableContainerOptions {
4747
export function tablePlugin(md: Markdown, options: TableContainerOptions = {}): void {
4848
createContainerSyntaxPlugin(md, 'table', (tokens, index, opt, env) => {
4949
const { hlCols = '', hlRows = '', hlCells = '', ...meta } = tokens[index].meta as TableContainerAttrs
50-
const props = { copy: true, maxContent: false, ...options, ...meta } as TableContainerAttrs & { markdown?: string }
50+
const props = { copy: true, maxContent: false, fullWidth: false, ...options, ...meta } as TableContainerAttrs & { markdown?: string }
5151
const content = tokens[index].content
5252

5353
if (props.copy) {

plugins/plugin-md-power/src/shared/table.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,11 @@ export interface TableContainerOptions {
2828
* @default false
2929
*/
3030
maxContent?: boolean
31+
32+
/**
33+
* 表格宽度是否填充整行宽度
34+
*
35+
* @default false
36+
*/
37+
fullWidth?: boolean
3138
}

theme/src/client/styles/content.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@
207207
* Table
208208
* -------------------------------------------------------------------------- */
209209
.vp-doc table {
210-
display: block;
210+
display: table;
211211
margin: 20px 0;
212212
overflow-x: auto;
213213
border-collapse: collapse;

0 commit comments

Comments
 (0)