Skip to content

Commit

Permalink
Add gfm alerts
Browse files Browse the repository at this point in the history
  • Loading branch information
grigorii-horos committed May 12, 2024
1 parent 233aefd commit 3f08011
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 15 deletions.
2 changes: 1 addition & 1 deletion lib/tags.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import {
p,
picture,
section,
span,
} from './tags/base-tags.js';
import { blockquote } from './tags/blockquote.js';
import { br } from './tags/br.js';
Expand All @@ -39,6 +38,7 @@ import { img } from './tags/img.js';
import { button, input, output } from './tags/inputs.js';
import { li, ol, ul } from './tags/list.js';
import { progress } from './tags/progress.js';
import { span } from './tags/span.js';
import { caption, table } from './tags/table.js';
import {
b,
Expand Down
1 change: 0 additions & 1 deletion lib/tags/base-tags.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const inline = inlineTag();

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

export const span = inline;
export const label = inline;
export const blink = inline;

Expand Down
30 changes: 21 additions & 9 deletions lib/tags/blockquote.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
import compose from 'compose-function';
import chalkString from 'chalk-string';

import { blockTag } from '../tag-helpers/block-tag.js';
import { indentify } from '../utils.js';

export const blockquote = (tag, context) => blockTag(
compose(
indentify(context.theme.blockquote('│ '), false),
),
{ marginTop: 1, marginBottom: 1 },
)(tag, { ...context, lineWidth: context.lineWidth - 2 });
import { getAttribute, getColorFromClass, indentify } from '../utils.js';

const newStyle = chalkString();

export const blockquote = (tag, context) => {
const classAttributes = getAttribute(tag, 'class', '')
?.split(' ')
?.find((classAttribute) => classAttribute.startsWith('x-cli-color-'));

const color = getColorFromClass(classAttributes);

return blockTag(
indentify(
color ? newStyle(color, '│ ') : context.theme.blockquote('│ '),
false,
),

{ marginTop: 1, marginBottom: 1 },
)(tag, { ...context, lineWidth: context.lineWidth - 2 });
};
6 changes: 3 additions & 3 deletions lib/tags/code.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ export const code = (tag, context) => inlineTag((value, tag) => {
pad,
true,
)(
wrapAnsi(codeLine, context.lineWidth - pad.length - 2, {
wrapAnsi(`|${codeLine}|`, context.lineWidth - pad.length - 2, {
trim: true,
}),
}).slice(1, -1),
)}`,
);

return indentify('', false)(codeContent.join('\n'));
return indentify(' ', false)(codeContent.join('\n'));
})(tag, context);

export const pre = (tag, context) => blockTag((value) => value, { marginTop: 2, marginBottom: 2 })(
Expand Down
20 changes: 20 additions & 0 deletions lib/tags/span.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import ansiEscapes from 'ansi-escapes';
import chalkString from 'chalk-string';
import { stdout } from 'supports-hyperlinks';

import inlineTag from '../tag-helpers/inline-tag.js';
import { getAttribute, getColorFromClass } from '../utils.js';

const newStyle = chalkString();

export const span = inlineTag((value, tag, context) => {
const classAttributes = getAttribute(tag, 'class', '')
?.split(' ')
?.find((classAttribute) => classAttribute.startsWith('x-cli-color-'));

const color = getColorFromClass(classAttributes);

const text = color ? newStyle(color, value) : context.theme.a(value);

return text;
});
8 changes: 8 additions & 0 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,11 @@ export const getAttribute = (tag, attributeName, defaultValue) => {

return attribute.value;
};

export const getColorFromClass = (classAttribute = '') => {
if (classAttribute?.startsWith('x-cli-color-')) {
return classAttribute?.slice(12);
}

return null;
};
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
"bin": {
"html": "bin/html.js"
},
"engines": {
"node": ">=16.0.0",
"npm": ">=7.0.0"
},
"author": "Grigorii Horos",
"license": "GPL3",
"keywords": [
Expand All @@ -25,7 +29,6 @@
"type": "git",
"url": "https://github.com/horosgrisa/cli-html.git"
},
"engines": {},
"homepage": "https://github.com/horosgrisa/cli-html",
"dependencies": {
"ansi-align": "^3.0.1",
Expand Down

0 comments on commit 3f08011

Please sign in to comment.