Skip to content

Commit a79b205

Browse files
committed
Updated Del
1 parent d7f3c35 commit a79b205

File tree

4 files changed

+42
-43
lines changed

4 files changed

+42
-43
lines changed

dist/index.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,10 @@ const makeTextNode = (text) => ({
1010
type: 'text',
1111
value: text,
1212
});
13-
const makeStrikethroughNode = (text) => {
14-
return {
15-
type: 'text',
16-
value: `~~${text}~~`,
17-
};
18-
};
13+
const makeStrikethroughNode = (text) => ({
14+
type: 'delete',
15+
children: [{ type: 'text', value: text }],
16+
});
1917
const shortenId = (hash) => `${hash.slice(0, 4)}${hash.slice(-4)}`;
2018
const corepassPattern = /\[(!?)(((cb|ab|ce)[0-9]{2}[0-9a-f]{40})|((?:[a-z0-9_-]|\p{Emoji})+(?:\.(?:[a-z0-9_-]|\p{Emoji})+)*\.([a-z0-9]+)))@coreid\]/giu;
2119
function isTextNode(node) {
@@ -41,14 +39,15 @@ export default function remarkCorepass(options = {}) {
4139
}
4240
let id = fullId;
4341
let willSkip = (finalOptions.enableSkippingIcanCheck) ? ((skip === '!') ? true : false) : false;
44-
let displayName = '';
42+
let displayName, fullName;
4543
if (cpId !== '' && cpId !== undefined) {
46-
displayName = shortenId(id.toUpperCase());
44+
fullName = id.toUpperCase();
45+
displayName = shortenId(fullName);
4746
if (finalOptions.enableIcanCheck && !willSkip && !Ican.isValid(id, true)) {
4847
newNodes.push(makeStrikethroughNode(`${displayName}@coreid`));
4948
}
5049
else {
51-
newNodes.push(makeLinkNode(`corepass:${id.toLowerCase()}`, `${displayName}@coreid`, displayName));
50+
newNodes.push(makeLinkNode(`corepass:${id.toLowerCase()}`, `${displayName}@coreid`, fullName));
5251
}
5352
}
5453
else {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "remark-corepass",
3-
"version": "0.1.1",
3+
"version": "0.1.2",
44
"description": "A Remark plugin to transform CorePass notations into markdown links.",
55
"main": "dist/index.js",
66
"types": "types/index.d.ts",

src/index.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ interface TextNode extends Node {
2323
value: string;
2424
}
2525

26+
interface DelNode extends Node {
27+
type: 'delete';
28+
children: Array<TextNode>;
29+
}
30+
2631
const makeLinkNode = (url: string, text: string, title?: string): LinkNode => ({
2732
type: 'link',
2833
url,
@@ -35,12 +40,10 @@ const makeTextNode = (text: string): TextNode => ({
3540
value: text,
3641
});
3742

38-
const makeStrikethroughNode = (text: string): TextNode => {
39-
return {
40-
type: 'text',
41-
value: `~~${text}~~`,
42-
};
43-
};
43+
const makeStrikethroughNode = (text: string): DelNode => ({
44+
type: 'delete',
45+
children: [{ type: 'text', value: text }],
46+
});
4447

4548
const shortenId = (hash: string) => `${hash.slice(0, 4)}${hash.slice(-4)}`;
4649

@@ -81,13 +84,14 @@ export default function remarkCorepass(options: CorepassOptions = {}): (ast: Nod
8184
}
8285
let id = fullId as string;
8386
let willSkip = (finalOptions.enableSkippingIcanCheck) ? ((skip === '!') ? true : false) : false;
84-
let displayName = '';
87+
let displayName, fullName;
8588
if (cpId !== '' && cpId !== undefined) {
86-
displayName = shortenId(id.toUpperCase());
89+
fullName = id.toUpperCase();
90+
displayName = shortenId(fullName);
8791
if (finalOptions.enableIcanCheck && !willSkip && !Ican.isValid(id, true)) {
8892
newNodes.push(makeStrikethroughNode(`${displayName}@coreid`));
8993
} else {
90-
newNodes.push(makeLinkNode(`corepass:${id.toLowerCase()}`, `${displayName}@coreid`, displayName));
94+
newNodes.push(makeLinkNode(`corepass:${id.toLowerCase()}`, `${displayName}@coreid`, fullName));
9195
}
9296
} else {
9397
displayName = `${id}`;

test/remarkCorepass.test.ts

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,54 +15,50 @@ const processMarkdown = async (markdown: string, options: Record<string, any> =
1515
return result.toString();
1616
};
1717

18+
const normalizeString = (str: string) => str.trim();
19+
1820
const CorePassHandlers = suite('CorePass handlers');
1921

2022
CorePassHandlers('Transforms CoreID link', async () => {
2123
const input = '[cb7147879011ea207df5b35a24ca6f0859dcfb145999@coreid]';
22-
const output = await processMarkdown(input, { enableIcanCheck: true });
23-
assert.match(output, /\[CB715999@coreid\]\(corepass:cb7147879011ea207df5b35a24ca6f0859dcfb145999 "CB715999"\)/);
24+
const output = normalizeString(await processMarkdown(input, { enableIcanCheck: true }));
25+
const expected = '[CB71…5999@coreid](corepass:cb7147879011ea207df5b35a24ca6f0859dcfb145999 "CB7147879011EA207DF5B35A24CA6F0859DCFB145999")';
26+
assert.is(output, expected);
2427
});
2528

2629
CorePassHandlers('Transforms CoreID link w/ bad checksum & w/o ican check', async () => {
2730
const input = '[!cb7247879011ea207df5b35a24ca6f0859dcfb145999@coreid]';
28-
const output = await processMarkdown(input, { enableIcanCheck: true });
29-
assert.match(output, /\[CB725999@coreid\]\(corepass:cb7247879011ea207df5b35a24ca6f0859dcfb145999 "CB725999"\)/);
30-
});
31-
32-
CorePassHandlers('Transforms CoreID link w/ bad checksum & w/ ican check', async () => {
33-
const input = '[cb7247879011ea207df5b35a24ca6f0859dcfb145999@coreid]';
34-
const output = await processMarkdown(input, { enableIcanCheck: true });
35-
assert.match(output, /~~CB725999@coreid~~/);
31+
const output = normalizeString(await processMarkdown(input, { enableIcanCheck: true }));
32+
const expected = '[CB72…5999@coreid](corepass:cb7247879011ea207df5b35a24ca6f0859dcfb145999 "CB7247879011EA207DF5B35A24CA6F0859DCFB145999")';
33+
assert.is(output, expected);
3634
});
3735

3836
CorePassHandlers('Transforms CoreID link as domain pattern', async () => {
3937
const input = '[sub.domain.cc@coreid]';
40-
const output = await processMarkdown(input);
41-
assert.match(output, /\[sub.domain.cc@coreid\]\(corepass:sub.domain.cc "sub.domain.cc"\)/);
38+
const output = normalizeString(await processMarkdown(input));
39+
const expected = '[sub.domain.cc@coreid](corepass:sub.domain.cc "sub.domain.cc")';
40+
assert.is(output, expected);
4241
});
4342

4443
CorePassHandlers('Transforms CoreID link as emoji domain pattern', async () => {
4544
const input = '[emoji🎉domain.cc@coreid]';
46-
const output = await processMarkdown(input);
47-
assert.match(output, /\[emoji🎉domain.cc@coreid\]\(corepass:emoji🎉domain.cc "emoji🎉domain.cc"\)/);
45+
const output = normalizeString(await processMarkdown(input));
46+
const expected = '[emoji🎉domain.cc@coreid](corepass:emoji🎉domain.cc "emoji🎉domain.cc")';
47+
assert.is(output, expected);
4848
});
4949

5050
CorePassHandlers('Transforms CoreID link defined with round brackets', async () => {
5151
const input = '[cb7147879011ea207df5b35a24ca6f0859dcfb145999@coreid]';
52-
const output = await processMarkdown(input, { enableIcanCheck: true });
53-
assert.match(output, /\[CB715999@coreid\]\(corepass:cb7147879011ea207df5b35a24ca6f0859dcfb145999 "CB715999"\)/);
52+
const output = normalizeString(await processMarkdown(input, { enableIcanCheck: true }));
53+
const expected = '[CB71…5999@coreid](corepass:cb7147879011ea207df5b35a24ca6f0859dcfb145999 "CB7147879011EA207DF5B35A24CA6F0859DCFB145999")';
54+
assert.is(output, expected);
5455
});
5556

5657
CorePassHandlers('Transforms CoreID link defined with round brackets, w/o ican check and w/ bad checksum', async () => {
5758
const input = '[!cb7247879011ea207df5b35a24ca6f0859dcfb145999@coreid]';
58-
const output = await processMarkdown(input, { enableIcanCheck: true });
59-
assert.match(output, /\[CB725999@coreid\]\(corepass:cb7247879011ea207df5b35a24ca6f0859dcfb145999 "CB725999"\)/);
60-
});
61-
62-
CorePassHandlers('Transforms CoreID link defined with round brackets, w/ ican check and w/ bad checksum', async () => {
63-
const input = '[cb7247879011ea207df5b35a24ca6f0859dcfb145999@coreid]';
64-
const output = await processMarkdown(input, { enableIcanCheck: true });
65-
assert.match(output, /~~CB725999@coreid~~/);
59+
const output = normalizeString(await processMarkdown(input, { enableIcanCheck: true }));
60+
const expected = '[CB72…5999@coreid](corepass:cb7247879011ea207df5b35a24ca6f0859dcfb145999 "CB7247879011EA207DF5B35A24CA6F0859DCFB145999")';
61+
assert.is(output, expected);
6662
});
6763

6864
CorePassHandlers.run();

0 commit comments

Comments
 (0)