Skip to content

Commit 8e2e58d

Browse files
Fix table issue
1 parent bcec569 commit 8e2e58d

File tree

5 files changed

+17
-14
lines changed

5 files changed

+17
-14
lines changed

index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import { parse } from 'parse5';
22

3-
import { indentify } from './lib/utils.js';
3+
import { filterAst, indentify } from './lib/utils.js';
44
import { getGlobalConfig } from './lib/utils/get-clobal-config.js';
55
import { renderTag } from './lib/utils/render-tag.js';
66

77
const htmlToCli = (rawHTML, theme = {}) => {
88
const document = parse(rawHTML);
99

1010
// console.dir(
11-
// filterAst(document),
11+
// filterAst(document).childNodes[0].childNodes[1].childNodes,
1212
// { depth: null },
1313
// );
1414

lib/tag-helpers/block-tag.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,11 @@ export function blockTag(wrapper, localContext) {
7676
return null;
7777
}
7878

79-
let topBlock = (localContext && localContext.marginTop) || 0;
79+
let topBlock = (localContext?.marginTop) || 0;
8080

8181
topBlock = !context || !context.pre ? topBlock + 1 : topBlock;
8282

83-
let bottomBlock = (localContext && localContext.marginBottom) || 0;
83+
let bottomBlock = (localContext?.marginBottom) || 0;
8484

8585
bottomBlock = !context || !context.pre ? bottomBlock + 1 : bottomBlock;
8686

lib/tags/table.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ export const caption = blockTag();
1919

2020
const captions = (tag, context) => blockTag((value) => bold.blue(value))(tag, context);
2121

22-
const trVals = (tr) => {
22+
const trVals = (context) => (tr) => {
2323
const theadTds = !tr || !tr.childNodes
2424
? null
2525
: tr.childNodes.filter((tag) => ['td', 'th'].includes(tag.nodeName));
2626

2727
const theadTdsValue = theadTds
28-
? theadTds.map((tag, context) => {
28+
? theadTds.map((tag) => {
2929
const det = tag.nodeName === 'td' ? td(tag, context) : th(tag, context);
3030

3131
const parsedStyle = styleParser(getAttribute(tag, 'style', ''));
@@ -50,12 +50,12 @@ const trVals = (tr) => {
5050
return theadTdsValue;
5151
};
5252

53-
const tbodyVals = (tbody) => {
53+
const tbodyVals = (context) => (tbody) => {
5454
const theadTrs = tbody
5555
? tbody.childNodes.filter((tag) => ['tr'].includes(tag.nodeName))
5656
: null;
5757

58-
const theadTrsVals = theadTrs.map(trVals);
58+
const theadTrsVals = theadTrs.map(trVals(context));
5959
return theadTrsVals;
6060
};
6161

@@ -79,23 +79,23 @@ export const table = (tag, context) => {
7979
? null
8080
: thead.childNodes.find((child) => child.nodeName === 'tr');
8181

82-
const theadsValue = theadTr ? trVals(theadTr) : null;
82+
const theadsValue = theadTr ? trVals(context)(theadTr) : null;
8383

8484
if (theadsValue && theadsValue[0]) {
8585
tableArray.push(theadsValue);
8686
}
8787

8888
const trs = tag.childNodes.filter((child) => ['tbody'].includes(child.nodeName));
8989

90-
trs.map(tbodyVals).map((value) => tableArray.push(...value));
90+
trs.map(tbodyVals(context)).map((value) => tableArray.push(...value));
9191

9292
const tfoot = tag.childNodes.find((child) => child.nodeName === 'tfoot');
9393

9494
const tfootTr = !tfoot || !tfoot.childNodes
9595
? null
9696
: tfoot.childNodes.find((child) => child.nodeName === 'tr');
9797

98-
const tfootdsValue = tfootTr ? trVals(tfootTr) : null;
98+
const tfootdsValue = tfootTr ? trVals(context)(tfootTr) : null;
9999

100100
if (tfootdsValue && tfootdsValue[0]) {
101101
tableArray.push(tfootdsValue);

lib/tags/text-styles.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ export const b = bold;
2020
export const s = strikethrough;
2121
export const strike = strikethrough;
2222

23-
export const em = italic;
2423
// eslint-disable-next-line unicorn/prevent-abbreviations
25-
export const i = italic;
26-
export const cite = italic;
24+
export const i = inlineTag((value, tag, context) => context.theme.italic(value));
25+
export const em = inlineTag((value, tag, context) => context.theme.italic(value));
26+
export const cite = inlineTag((value, tag, context) => context.theme.italic(value));
2727

2828
export const strong = bold;
2929

lib/utils/get-theme.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ export const getTheme = (customTheme) => ({
2121
del: (value) => style(customTheme.del || 'bgRed black', value),
2222
ins: (value) => style(customTheme.ins || 'bgGreen black', value),
2323
italic: (value) => style(customTheme.italic || 'italic', value),
24+
i: (value) => style(customTheme.i || 'italic', value),
25+
em: (value) => style(customTheme.em || 'italic', value),
26+
cite: (value) => style(customTheme.cite || 'italic', value),
2427
strike: (value) => style(customTheme.strikethrough || 'strikethrough', value),
2528
underline: (value) => style(customTheme.underline || 'underline', value),
2629
bold: (value) => style(customTheme.bold || 'bold', value),

0 commit comments

Comments
 (0)