Skip to content

Commit 3f08011

Browse files
Add gfm alerts
1 parent 233aefd commit 3f08011

File tree

7 files changed

+57
-15
lines changed

7 files changed

+57
-15
lines changed

lib/tags.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import {
2020
p,
2121
picture,
2222
section,
23-
span,
2423
} from './tags/base-tags.js';
2524
import { blockquote } from './tags/blockquote.js';
2625
import { br } from './tags/br.js';
@@ -39,6 +38,7 @@ import { img } from './tags/img.js';
3938
import { button, input, output } from './tags/inputs.js';
4039
import { li, ol, ul } from './tags/list.js';
4140
import { progress } from './tags/progress.js';
41+
import { span } from './tags/span.js';
4242
import { caption, table } from './tags/table.js';
4343
import {
4444
b,

lib/tags/base-tags.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ const inline = inlineTag();
77

88
const blockWithNewlines = blockTag((value) => value, { marginTop: 1, marginBottom: 1 });
99

10-
export const span = inline;
1110
export const label = inline;
1211
export const blink = inline;
1312

lib/tags/blockquote.js

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,23 @@
1-
import compose from 'compose-function';
1+
import chalkString from 'chalk-string';
22

33
import { blockTag } from '../tag-helpers/block-tag.js';
4-
import { indentify } from '../utils.js';
5-
6-
export const blockquote = (tag, context) => blockTag(
7-
compose(
8-
indentify(context.theme.blockquote('│ '), false),
9-
),
10-
{ marginTop: 1, marginBottom: 1 },
11-
)(tag, { ...context, lineWidth: context.lineWidth - 2 });
4+
import { getAttribute, getColorFromClass, indentify } from '../utils.js';
5+
6+
const newStyle = chalkString();
7+
8+
export const blockquote = (tag, context) => {
9+
const classAttributes = getAttribute(tag, 'class', '')
10+
?.split(' ')
11+
?.find((classAttribute) => classAttribute.startsWith('x-cli-color-'));
12+
13+
const color = getColorFromClass(classAttributes);
14+
15+
return blockTag(
16+
indentify(
17+
color ? newStyle(color, '│ ') : context.theme.blockquote('│ '),
18+
false,
19+
),
20+
21+
{ marginTop: 1, marginBottom: 1 },
22+
)(tag, { ...context, lineWidth: context.lineWidth - 2 });
23+
};

lib/tags/code.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,13 @@ export const code = (tag, context) => inlineTag((value, tag) => {
4848
pad,
4949
true,
5050
)(
51-
wrapAnsi(codeLine, context.lineWidth - pad.length - 2, {
51+
wrapAnsi(`|${codeLine}|`, context.lineWidth - pad.length - 2, {
5252
trim: true,
53-
}),
53+
}).slice(1, -1),
5454
)}`,
5555
);
5656

57-
return indentify('', false)(codeContent.join('\n'));
57+
return indentify(' ', false)(codeContent.join('\n'));
5858
})(tag, context);
5959

6060
export const pre = (tag, context) => blockTag((value) => value, { marginTop: 2, marginBottom: 2 })(

lib/tags/span.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import ansiEscapes from 'ansi-escapes';
2+
import chalkString from 'chalk-string';
3+
import { stdout } from 'supports-hyperlinks';
4+
5+
import inlineTag from '../tag-helpers/inline-tag.js';
6+
import { getAttribute, getColorFromClass } from '../utils.js';
7+
8+
const newStyle = chalkString();
9+
10+
export const span = inlineTag((value, tag, context) => {
11+
const classAttributes = getAttribute(tag, 'class', '')
12+
?.split(' ')
13+
?.find((classAttribute) => classAttribute.startsWith('x-cli-color-'));
14+
15+
const color = getColorFromClass(classAttributes);
16+
17+
const text = color ? newStyle(color, value) : context.theme.a(value);
18+
19+
return text;
20+
});

lib/utils.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,11 @@ export const getAttribute = (tag, attributeName, defaultValue) => {
6161

6262
return attribute.value;
6363
};
64+
65+
export const getColorFromClass = (classAttribute = '') => {
66+
if (classAttribute?.startsWith('x-cli-color-')) {
67+
return classAttribute?.slice(12);
68+
}
69+
70+
return null;
71+
};

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
"bin": {
1212
"html": "bin/html.js"
1313
},
14+
"engines": {
15+
"node": ">=16.0.0",
16+
"npm": ">=7.0.0"
17+
},
1418
"author": "Grigorii Horos",
1519
"license": "GPL3",
1620
"keywords": [
@@ -25,7 +29,6 @@
2529
"type": "git",
2630
"url": "https://github.com/horosgrisa/cli-html.git"
2731
},
28-
"engines": {},
2932
"homepage": "https://github.com/horosgrisa/cli-html",
3033
"dependencies": {
3134
"ansi-align": "^3.0.1",

0 commit comments

Comments
 (0)