Skip to content

Commit 6293bb1

Browse files
committed
feat: refine table layout for known scope
1 parent 579f955 commit 6293bb1

File tree

3 files changed

+51
-26
lines changed

3 files changed

+51
-26
lines changed

assets/styles/post.styl

Lines changed: 39 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -151,27 +151,8 @@ margin-y($top, $bottom = $top)
151151
border-radius 4px
152152
margin-y(1.5em)
153153

154-
thead
155-
position sticky
156-
top -1px
157-
background #f3f6f988
158-
backdrop-filter blur(4px)
159-
160-
th
161-
position relative
162-
163-
&::after
164-
content ""
165-
position absolute
166-
bottom 0
167-
width 100%
168-
height 1px
169-
left 0
170-
background #f1f1f1
171-
172-
// pre
173-
// table
174-
// max-width 480px
154+
th
155+
background #f3f6f988
175156

176157
th
177158
td
@@ -360,6 +341,43 @@ margin-y($top, $bottom = $top)
360341
[data-target]
361342
animation target-blink 6s ease 1 both
362343

344+
table[data-scope]
345+
display grid
346+
grid-auto-rows auto
347+
348+
& > thead
349+
& > thead > tr
350+
& > tbody
351+
& > tbody > tr
352+
display contents
353+
354+
& > thead > tr > th
355+
position sticky
356+
top 0
357+
z-index 1
358+
border-top none
359+
backdrop-filter blur(4px)
360+
361+
& > tbody > tr > td
362+
border-top none
363+
word-break break-word
364+
365+
&[data-scope="props"]
366+
grid-template-columns max-content fit-content(20%) fit-content(20%) auto
367+
368+
&[data-scope="configs"]
369+
grid-template-columns max-content fit-content(30%) fit-content(30%) auto
370+
371+
&[data-scope="events"]
372+
&[data-scope="methods"]
373+
&[data-scope="slots"]
374+
&[data-scope="icons"]
375+
grid-template-columns minmax(max-content, 30%) auto
376+
377+
&[data-scope="options"]
378+
&[data-scope="modifiers"]
379+
grid-template-columns max-content fit-content(30%) fit-content(30%) auto
380+
363381
.meta
364382
display flex
365383
justify-content center

one/build/page.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import stringifyObject from 'stringify-object'
1414
import { readFileSync, writeFileSync, replaceExtSync } from './util'
1515
import demo from './remark-demo'
1616
import ref from './remark-ref'
17-
import anchor from './remark-anchor'
17+
import scope from './remark-scope'
1818
import details from './remark-details'
1919
import custom from './remark-custom'
2020
import toc from './remark-extract-toc'
@@ -34,7 +34,7 @@ const PAGE_TPL = readFileSync(resolve(__dirname, '../templates/page.etpl'))
3434
const renderPage = etpl.compile(PAGE_TPL)
3535

3636
const md = remark()
37-
.use(anchor)
37+
.use(scope)
3838
.use(custom)
3939
.use(ref)
4040
.use(details)

one/build/remark-anchor.js renamed to one/build/remark-scope.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@ export default function attacher () {
2626
let scope = null
2727

2828
visit(tree, (node, index, parent) => {
29-
const { type, depth, children, value, position } = node
29+
const { type, children, value, position } = node
3030
if (type === 'heading') {
31+
let { depth } = node
32+
3133
if (depth === 3) {
3234
let text = children[0]
3335
if (text && text.type === 'element' && text.tagName === 'icon-link') {
@@ -46,14 +48,19 @@ export default function attacher () {
4648
return
4749
}
4850

51+
if (type === 'table' && scope) {
52+
node.data = node.data || {}
53+
node.data.hProperties = { ...node.data.hProperties, 'data-scope': scope }
54+
}
55+
4956
if (
5057
type === 'inlineCode' &&
51-
position.end.offset - position.start.offset - value.length === 4
58+
position.end.offset - position.start.offset - value.length === 4 // ``value`` has 4 backticks
5259
) {
5360
const id = `${scope || 'doc'}-${value.replace(/\./g, '-')}`
5461

5562
node.data = node.data || {}
56-
node.data.hProperties = { id }
63+
node.data.hProperties = { ...node.data.hProperties, id }
5764

5865
parent.children[index] = {
5966
type: 'link',

0 commit comments

Comments
 (0)