Skip to content

Commit 9fbc25a

Browse files
committed
feat: improve table rendering + add markdown-it-decorate module
1 parent d98e0b3 commit 9fbc25a

File tree

7 files changed

+107
-5
lines changed

7 files changed

+107
-5
lines changed

client/components/editor/editor-markdown.vue

+2
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ import './markdown/fold'
225225
// Markdown-it
226226
import MarkdownIt from 'markdown-it'
227227
import mdAttrs from 'markdown-it-attrs'
228+
import mdDecorate from 'markdown-it-decorate'
228229
import mdEmoji from 'markdown-it-emoji'
229230
import mdTaskLists from 'markdown-it-task-lists'
230231
import mdExpandTabs from 'markdown-it-expand-tabs'
@@ -288,6 +289,7 @@ const md = new MarkdownIt({
288289
.use(mdAttrs, {
289290
allowedAttributes: ['id', 'class', 'target']
290291
})
292+
.use(mdDecorate)
291293
.use(underline)
292294
.use(mdEmoji)
293295
.use(mdTaskLists, { label: false, labelAfter: false })

client/themes/default/scss/app.scss

+85-2
Original file line numberDiff line numberDiff line change
@@ -662,13 +662,40 @@
662662
// ---------------------------------
663663

664664
table {
665-
margin: .5rem 1.75rem;
665+
margin: .5rem 0;
666666
border-spacing: 0;
667+
border-radius: 5px;
668+
border: 1px solid mc('grey', '300');
669+
670+
@at-root .theme--dark & {
671+
border-color: mc('grey', '600');
672+
}
673+
674+
&.dense {
675+
td, th {
676+
font-size: .85rem;
677+
padding: .5rem;
678+
}
679+
}
667680

668681
th {
669682
padding: .75rem;
670683
border-bottom: 2px solid mc('grey', '500');
671684
color: mc('grey', '600');
685+
background-color: mc('grey', '100');
686+
687+
@at-root .theme--dark & {
688+
background-color: darken(mc('grey', '900'), 8%);
689+
border-bottom-color: mc('grey', '600');
690+
color: mc('grey', '500');
691+
}
692+
693+
&:first-child {
694+
border-top-left-radius: 7px;
695+
}
696+
&:last-child {
697+
border-top-right-radius: 7px;
698+
}
672699
}
673700

674701
td {
@@ -677,7 +704,56 @@
677704

678705
tr {
679706
td {
680-
border-bottom: 1px solid mc('grey', '200');
707+
border-bottom: 1px solid mc('grey', '300');
708+
border-right: 1px solid mc('grey', '100');
709+
710+
@at-root .theme--dark & {
711+
border-bottom-color: mc('grey', '700');
712+
border-right-color: mc('grey', '800');
713+
}
714+
715+
&:nth-child(even) {
716+
background-color: mc('grey', '50');
717+
718+
@at-root .theme--dark & {
719+
background-color: darken(mc('grey', '900'), 4%);
720+
}
721+
}
722+
723+
&:last-child {
724+
border-right: none;
725+
}
726+
}
727+
728+
&:nth-child(even) {
729+
td {
730+
background-color: mc('grey', '50');
731+
732+
@at-root .theme--dark & {
733+
background-color: darken(mc('grey', '800'), 8%);
734+
}
735+
736+
&:nth-child(even) {
737+
background-color: mc('grey', '100');
738+
739+
@at-root .theme--dark & {
740+
background-color: darken(mc('grey', '800'), 10%);
741+
}
742+
}
743+
}
744+
}
745+
746+
&:last-child {
747+
td {
748+
border-bottom: none;
749+
750+
&:first-child {
751+
border-bottom-left-radius: 7px;
752+
}
753+
&:last-child {
754+
border-bottom-right-radius: 7px;
755+
}
756+
}
681757
}
682758
}
683759
}
@@ -699,6 +775,7 @@
699775
border: 1px solid mc('blue-grey', '100');
700776
box-shadow: inset -1px -1px 0 0 #FFF, inset 1px 0 0 #FFF;
701777
padding: .5rem .75rem;
778+
border-radius: 0 !important;
702779

703780
@at-root .theme--dark & {
704781
border-color: mc('grey', '700');
@@ -735,6 +812,12 @@
735812
}
736813
}
737814

815+
// -> Add horizontal scrollbar when table is too wide
816+
.table-container {
817+
width: 100%;
818+
overflow-x: auto;
819+
}
820+
738821
// ---------------------------------
739822
// IMAGES
740823
// ---------------------------------

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@
106106
"markdown-it": "11.0.1",
107107
"markdown-it-abbr": "1.0.4",
108108
"markdown-it-attrs": "3.0.3",
109+
"markdown-it-decorate": "1.2.2",
109110
"markdown-it-emoji": "1.4.0",
110111
"markdown-it-expand-tabs": "1.0.13",
111112
"markdown-it-external-links": "0.0.6",

server/models/pages.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -959,9 +959,8 @@ module.exports = class Page extends Model {
959959
// -> Save render to cache
960960
await WIKI.models.pages.savePageToCache(page)
961961
} else {
962-
// -> No render? Possible duplicate issue
963-
/* TODO: Detect duplicate and delete */
964-
throw new Error('Error while fetching page. Duplicate entry detected. Reload the page to try again.')
962+
// -> No render? Last page render failed...
963+
throw new Error('Page has no rendered version. Looks like the Last page render failed. Try to edit the page and save it again.')
965964
}
966965
}
967966
}

server/modules/rendering/html-core/renderer.js

+10
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,16 @@ module.exports = {
243243
}
244244
})
245245

246+
// --------------------------------
247+
// Wrap root table nodes
248+
// --------------------------------
249+
250+
$('body').contents().toArray().forEach(item => {
251+
if (item && item.name === 'table' && item.parent.name === 'body') {
252+
$(item).wrap('<div class="table-container"></div>')
253+
}
254+
})
255+
246256
// --------------------------------
247257
// Escape mustache expresions
248258
// --------------------------------

server/modules/rendering/markdown-core/renderer.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const md = require('markdown-it')
22
const mdAttrs = require('markdown-it-attrs')
3+
const mdDecorate = require('markdown-it-decorate')
34
const _ = require('lodash')
45
const underline = require('./underline')
56

@@ -42,6 +43,7 @@ module.exports = {
4243
mkdown.use(mdAttrs, {
4344
allowedAttributes: ['id', 'class', 'target']
4445
})
46+
mkdown.use(mdDecorate)
4547

4648
for (let child of this.children) {
4749
const renderer = require(`../${_.kebabCase(child.key)}/renderer.js`)

yarn.lock

+5
Original file line numberDiff line numberDiff line change
@@ -12968,6 +12968,11 @@ markdown-it-attrs@3.0.3:
1296812968
resolved "https://registry.yarnpkg.com/markdown-it-attrs/-/markdown-it-attrs-3.0.3.tgz#92acdb16fe551cb056c5eb9848413443cafb5231"
1296912969
integrity sha512-cLnICU2t61skNCr4Wih/sdza+UbQcqJGZwvqAypnbWA284nzDm+Gpc90iaRk/JjsIy4emag5v3s0rXFhFBWhCA==
1297012970

12971+
markdown-it-decorate@1.2.2:
12972+
version "1.2.2"
12973+
resolved "https://registry.yarnpkg.com/markdown-it-decorate/-/markdown-it-decorate-1.2.2.tgz#f1e11d11d837ae78906198f8a2c974f0e646acb7"
12974+
integrity sha512-7BFWJ97KBXgkaPVjKHISQnhSW8RWQ7yRNXpr8pPUV2Rw4GHvGrgb6CelKCM+GSijP0uSLCAVfc/knWIz+2v/Sw==
12975+
1297112976
markdown-it-emoji@1.4.0:
1297212977
version "1.4.0"
1297312978
resolved "https://registry.yarnpkg.com/markdown-it-emoji/-/markdown-it-emoji-1.4.0.tgz#9bee0e9a990a963ba96df6980c4fddb05dfb4dcc"

0 commit comments

Comments
 (0)