Skip to content

Commit 6aad228

Browse files
committed
fix: fixed table content overflow container (#273)
1 parent 47732b9 commit 6aad228

File tree

7 files changed

+74
-50
lines changed

7 files changed

+74
-50
lines changed

source/css/common/basic.styl

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
&::-webkit-scrollbar {
2121
width 0.4rem
22-
height 0.4rem
22+
height 0.32rem
2323
transition all 0.2s ease
2424
}
2525

source/css/common/markdown.styl

+37-25
Original file line numberDiff line numberDiff line change
@@ -281,40 +281,52 @@
281281
}
282282

283283

284-
& > table {
284+
& > .table-container {
285+
box-sizing border-box
285286
width 100%
287+
margin 1.5rem 0
286288
overflow auto
287-
border-collapse collapse
288-
border-spacing 0
289289

290-
+keep-mobile() {
291-
& {
292-
table-layout fixed
290+
table {
291+
box-sizing border-box
292+
width 100%
293+
border-collapse collapse
294+
border-spacing 0
295+
296+
+keep-mobile() {
297+
& {
298+
table-layout fixed
299+
}
293300
}
294-
}
295301

296-
td
297-
th {
298-
padding 0
299-
}
302+
td
303+
th {
304+
padding 0
305+
}
300306

301-
th {
302-
font-weight 600
303-
}
307+
td {
308+
color var(--text-color-3)
309+
}
304310

305-
td
306-
th {
307-
padding 0.4rem 1rem
308-
border 0.1rem solid var(--border-color)
309-
}
311+
th {
312+
color var(--text-color-2)
313+
font-weight 600
314+
}
310315

311-
tr {
312-
background-color var(--background-color-1)
313-
border 0.1rem solid var(--text-color-6)
314-
}
316+
td
317+
th {
318+
padding 0.5rem 1rem
319+
border 0.1rem solid var(--border-color)
320+
}
321+
322+
tr {
323+
background-color var(--background-color-1)
324+
border 0.1rem solid var(--border-color)
325+
}
315326

316-
tr:nth-child(2n) {
317-
background-color var(--background-color-2)
327+
tr:nth-child(2n) {
328+
background-color var(--background-color-2)
329+
}
318330
}
319331
}
320332

source/js/code-block.js

-6
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,6 @@
33
KEEP.initCodeBlock = () => {
44
if (KEEP.theme_config?.code_block?.tools?.enable === true) {
55
KEEP.utils.initCodeBlockTools = () => {
6-
HTMLElement.prototype.wrap = function (wrapper) {
7-
this.parentNode.insertBefore(wrapper, this)
8-
this.parentNode.removeChild(this)
9-
wrapper.appendChild(this)
10-
}
11-
126
const { style: codeBlockStyle } = KEEP.theme_config?.code_block || {}
137
const { style: codeBlockToolsStyle } = KEEP.theme_config?.code_block?.tools || {}
148

source/js/main.js

+22-14
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
11
/* global KEEP */
22

33
window.addEventListener('DOMContentLoaded', () => {
4-
const { version, local_search, code_block, lazyload } = KEEP.theme_config
4+
const { version, local_search, lazyload } = KEEP.theme_config
55

66
KEEP.themeInfo = {
77
theme: `Keep v${version}`,
88
author: 'XPoet',
9-
repository: 'https://github.com/XPoet/hexo-theme-keep'
10-
}
11-
12-
KEEP.localStorageKey = 'KEEP-THEME-STATUS'
13-
14-
KEEP.styleStatus = {
15-
isDark: false,
16-
fontSizeLevel: 0,
17-
isShowToc: true
9+
repository: 'https://github.com/XPoet/hexo-theme-keep',
10+
localStorageKey: 'KEEP-THEME-STATUS',
11+
styleStatus: {
12+
isDark: false,
13+
fontSizeLevel: 0,
14+
isShowToc: true
15+
}
1816
}
1917

2018
// print theme base info
@@ -37,23 +35,33 @@ window.addEventListener('DOMContentLoaded', () => {
3735

3836
// set styleStatus to localStorage
3937
KEEP.setStyleStatus = () => {
40-
localStorage.setItem(KEEP.localStorageKey, JSON.stringify(KEEP.styleStatus))
38+
localStorage.setItem(KEEP.themeInfo.localStorageKey, JSON.stringify(KEEP.themeInfo.styleStatus))
4139
}
4240

4341
// get styleStatus from localStorage
4442
KEEP.getStyleStatus = () => {
45-
let temp = localStorage.getItem(KEEP.localStorageKey)
43+
let temp = localStorage.getItem(KEEP.themeInfo.localStorageKey)
4644
if (temp) {
4745
temp = JSON.parse(temp)
48-
for (let key in KEEP.styleStatus) {
49-
KEEP.styleStatus[key] = temp[key]
46+
for (let key in KEEP.themeInfo.styleStatus) {
47+
KEEP.themeInfo.styleStatus[key] = temp[key]
5048
}
5149
return temp
5250
} else {
5351
return null
5452
}
5553
}
5654

55+
// init prototype function
56+
KEEP.initPrototype = () => {
57+
HTMLElement.prototype.wrap = function (wrapper) {
58+
this.parentNode.insertBefore(wrapper, this)
59+
this.parentNode.removeChild(this)
60+
wrapper.appendChild(this)
61+
}
62+
}
63+
KEEP.initPrototype()
64+
5765
KEEP.initExecute = () => {
5866
KEEP.initUtils()
5967
KEEP.initHeaderShrink()

source/js/post/post-helper.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ function initPostHelper() {
1515
this.toggleShowTocBtn &&
1616
this.toggleShowTocBtn.addEventListener('click', () => {
1717
this.isShowToc = !this.isShowToc
18-
KEEP.styleStatus.isShowToc = this.isShowToc
18+
KEEP.themeInfo.styleStatus.isShowToc = this.isShowToc
1919
KEEP.setStyleStatus()
2020
this.handleToggleToc(this.isShowToc)
2121
})

source/js/toggle-theme.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ KEEP.initModeToggle = () => {
99
document.body.classList.remove('dark-mode')
1010
document.body.classList.add('light-mode')
1111
this.iconDom.className = 'fas fa-moon'
12-
KEEP.styleStatus.isDark = false
12+
KEEP.themeInfo.styleStatus.isDark = false
1313
KEEP.setStyleStatus()
1414
},
1515

1616
enableDarkMode() {
1717
document.body.classList.add('dark-mode')
1818
document.body.classList.remove('light-mode')
1919
this.iconDom.className = 'fas fa-sun'
20-
KEEP.styleStatus.isDark = true
20+
KEEP.themeInfo.styleStatus.isDark = true
2121
KEEP.setStyleStatus()
2222
},
2323

source/js/utils.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ KEEP.initUtils = () => {
154154
`${fs * (1 + fontSizeLevel * 0.05)}px`,
155155
'important'
156156
)
157-
KEEP.styleStatus.fontSizeLevel = fontSizeLevel
157+
KEEP.themeInfo.styleStatus.fontSizeLevel = fontSizeLevel
158158
KEEP.setStyleStatus()
159159
}
160160

@@ -671,6 +671,15 @@ KEEP.initUtils = () => {
671671
})
672672
}
673673
}
674+
},
675+
676+
// wrap table dom with div
677+
wrapTableWithBox() {
678+
document.querySelectorAll('table').forEach((element) => {
679+
const box = document.createElement('div')
680+
box.className = 'table-container'
681+
element.wrap(box)
682+
})
674683
}
675684
}
676685

@@ -688,4 +697,5 @@ KEEP.initUtils = () => {
688697
KEEP.utils.initTypewriter()
689698
KEEP.utils.trimPostMetaInfoBar()
690699
KEEP.utils.closeWebsiteAnnouncement()
700+
KEEP.utils.wrapTableWithBox()
691701
}

0 commit comments

Comments
 (0)