Skip to content

Commit 31944b7

Browse files
committed
Support bold
1 parent e562ace commit 31944b7

File tree

5 files changed

+52
-52
lines changed

5 files changed

+52
-52
lines changed

src/__tests__/normalizeLines.test.tsx

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ describe('normalizeLines', () => {
66
it('should handle single line markdown with no multi-line ranges', () => {
77
const lines: Paragraph[] = [
88
{
9-
text: '*Hello, world!*',
9+
text: '**Hello, world!**',
1010
start: 0,
11-
length: 13,
11+
length: 15,
1212
markdownRanges: [],
1313
},
1414
];
@@ -17,42 +17,42 @@ describe('normalizeLines', () => {
1717
{
1818
type: 'syntax',
1919
start: 0,
20-
length: 1,
20+
length: 2,
2121
},
2222
{
2323
type: 'bold',
24-
start: 1,
24+
start: 2,
2525
length: 11,
2626
},
2727
{
2828
type: 'syntax',
29-
start: 12,
30-
length: 1,
29+
start: 13,
30+
length: 2,
3131
},
3232
];
3333

3434
const result = normalizeLines(lines, ranges);
3535
const paragraph = result[0] as Paragraph;
3636
expect(paragraph.markdownRanges).toEqual([
37-
{length: 1, start: 0, type: 'syntax'},
38-
{length: 11, start: 1, type: 'bold'},
39-
{length: 1, start: 12, type: 'syntax'},
37+
{length: 2, start: 0, type: 'syntax'},
38+
{length: 11, start: 2, type: 'bold'},
39+
{length: 2, start: 13, type: 'syntax'},
4040
]);
41-
expect(paragraph.text).toEqual('*Hello, world!*');
41+
expect(paragraph.text).toEqual('**Hello, world!**');
4242
});
4343

4444
it('should handle multiline line markdown with no multi-line ranges', () => {
4545
const lines: Paragraph[] = [
4646
{
47-
text: '*Hello',
47+
text: '**Hello',
4848
start: 0,
49-
length: 6,
49+
length: 7,
5050
markdownRanges: [],
5151
},
5252
{
53-
text: 'world!*',
54-
start: 7,
55-
length: 7,
53+
text: 'world!**',
54+
start: 8,
55+
length: 8,
5656
markdownRanges: [],
5757
},
5858
];
@@ -61,28 +61,28 @@ describe('normalizeLines', () => {
6161
{
6262
type: 'syntax',
6363
start: 0,
64-
length: 1,
64+
length: 2,
6565
},
6666
{
6767
type: 'bold',
6868
start: 0,
69-
length: 13,
69+
length: 14,
7070
},
7171
{
7272
type: 'syntax',
73-
start: 13,
74-
length: 1,
73+
start: 14,
74+
length: 2,
7575
},
7676
];
7777

7878
const result = normalizeLines(lines, ranges);
7979
expect(result.length).toBe(2);
8080
const firstParagraph = result[0] as Paragraph;
8181
const secondParagraph = result[1] as Paragraph;
82-
expect(firstParagraph.text).toEqual('*Hello');
83-
expect(secondParagraph.text).toEqual('world!*');
84-
expect(firstParagraph.markdownRanges).toContainEqual({type: 'bold', start: 0, length: 6});
85-
expect(secondParagraph.markdownRanges).toContainEqual({type: 'bold', start: 7, length: 6});
82+
expect(firstParagraph.text).toEqual('**Hello');
83+
expect(secondParagraph.text).toEqual('world!**');
84+
expect(firstParagraph.markdownRanges).toContainEqual({type: 'bold', start: 0, length: 7});
85+
expect(secondParagraph.markdownRanges).toContainEqual({type: 'bold', start: 8, length: 6});
8686
});
8787

8888
it('should merge lines when handling multi-line markdown ranges', () => {

src/__tests__/parseExpensiMark.test.ts

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ describe('parsing error', () => {
4949
});
5050

5151
test('bold', () => {
52-
expect('Hello, *world*!').toBeParsedAs([
53-
{type: 'syntax', start: 7, length: 1},
54-
{type: 'bold', start: 8, length: 5},
55-
{type: 'syntax', start: 13, length: 1},
52+
expect('Hello, **world**!').toBeParsedAs([
53+
{type: 'syntax', start: 7, length: 2},
54+
{type: 'bold', start: 9, length: 5},
55+
{type: 'syntax', start: 14, length: 2},
5656
]);
5757
});
5858

@@ -281,19 +281,19 @@ test('h1', () => {
281281
});
282282

283283
test('nested bold and italic', () => {
284-
expect('*_Hello_*, _*world*_!').toBeParsedAs([
285-
{type: 'syntax', start: 0, length: 1},
286-
{type: 'bold', start: 1, length: 7},
287-
{type: 'syntax', start: 1, length: 1},
288-
{type: 'italic', start: 2, length: 5},
289-
{type: 'syntax', start: 7, length: 1},
284+
expect('**_Hello_**, _**world**_!').toBeParsedAs([
285+
{type: 'syntax', start: 0, length: 2},
286+
{type: 'bold', start: 2, length: 7},
287+
{type: 'syntax', start: 2, length: 1},
288+
{type: 'italic', start: 3, length: 5},
290289
{type: 'syntax', start: 8, length: 1},
291-
{type: 'syntax', start: 11, length: 1},
292-
{type: 'italic', start: 12, length: 7},
293-
{type: 'syntax', start: 12, length: 1},
294-
{type: 'bold', start: 13, length: 5},
295-
{type: 'syntax', start: 18, length: 1},
296-
{type: 'syntax', start: 19, length: 1},
290+
{type: 'syntax', start: 9, length: 2},
291+
{type: 'syntax', start: 13, length: 1},
292+
{type: 'italic', start: 14, length: 9},
293+
{type: 'syntax', start: 14, length: 2},
294+
{type: 'bold', start: 16, length: 5},
295+
{type: 'syntax', start: 21, length: 2},
296+
{type: 'syntax', start: 23, length: 1},
297297
]);
298298
});
299299

@@ -412,13 +412,13 @@ describe('trailing whitespace', () => {
412412
});
413413

414414
test('with another style inside', () => {
415-
expect('>> Hello *world*').toBeParsedAs([
416-
{type: 'blockquote', start: 0, length: 16, depth: 2},
415+
expect('>> Hello **world**').toBeParsedAs([
416+
{type: 'blockquote', start: 0, length: 18, depth: 2},
417417
{type: 'syntax', start: 0, length: 1},
418418
{type: 'syntax', start: 1, length: 1},
419-
{type: 'syntax', start: 9, length: 1},
420-
{type: 'bold', start: 10, length: 5},
421-
{type: 'syntax', start: 15, length: 1},
419+
{type: 'syntax', start: 9, length: 2},
420+
{type: 'bold', start: 11, length: 5},
421+
{type: 'syntax', start: 16, length: 2},
422422
]);
423423
});
424424
});

src/__tests__/singleLineInputFix.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ describe('Single-line input fix validation', () => {
3434
});
3535

3636
it('should not generate BR elements for single-line markdown (isMultiline=false)', () => {
37-
const text = 'hello *world* test';
37+
const text = 'hello **world** test';
3838
const ranges = parseExpensiMark(text);
3939

4040
const result = parseRangesToHTMLNodes(text, ranges, false, {}, true);
@@ -100,7 +100,7 @@ describe('Single-line input fix validation', () => {
100100

101101
it('should work correctly with markdown in single-line context', () => {
102102
// Test that our fix doesn't break markdown functionality
103-
const markdownText = '*bold* normal `code`';
103+
const markdownText = '**bold** normal `code`';
104104
const ranges = parseExpensiMark(markdownText);
105105

106106
const result = parseRangesToHTMLNodes(markdownText, ranges, false, {}, true);

src/__tests__/webParser.test.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ test('no formatting', () => {
4444
});
4545

4646
test('bold', () => {
47-
expect('Hello, *world*!').toBeParsedAsHTML(
48-
'<p data-type="line" data-id="0"><span data-type="text" data-id="0,0">Hello, </span><span data-type="syntax" data-id="0,1"><span data-type="text" data-id="0,1,0">*</span></span><span data-type="bold" data-id="0,2"><span data-type="text" data-id="0,2,0">world</span></span><span data-type="syntax" data-id="0,3"><span data-type="text" data-id="0,3,0">*</span></span><span data-type="text" data-id="0,4">!</span></p>',
47+
expect('Hello, **world**!').toBeParsedAsHTML(
48+
'<p data-type="line" data-id="0"><span data-type="text" data-id="0,0">Hello, </span><span data-type="syntax" data-id="0,1"><span data-type="text" data-id="0,1,0">**</span></span><span data-type="bold" data-id="0,2"><span data-type="text" data-id="0,2,0">world</span></span><span data-type="syntax" data-id="0,3"><span data-type="text" data-id="0,3,0">**</span></span><span data-type="text" data-id="0,4">!</span></p>',
4949
);
5050
});
5151

@@ -224,8 +224,8 @@ test('heading', () => {
224224
});
225225

226226
test('nested bold and italic', () => {
227-
expect('*_Hello_*, _*world*_!').toBeParsedAsHTML(
228-
'<p data-type="line" data-id="0"><span data-type="syntax" data-id="0,0"><span data-type="text" data-id="0,0,0">*</span></span><span data-type="bold" data-id="0,1"><span data-type="syntax" data-id="0,1,0"><span data-type="text" data-id="0,1,0,0">_</span></span><span data-type="italic" data-id="0,1,1"><span data-type="text" data-id="0,1,1,0">Hello</span></span><span data-type="syntax" data-id="0,1,2"><span data-type="text" data-id="0,1,2,0">_</span></span></span><span data-type="syntax" data-id="0,2"><span data-type="text" data-id="0,2,0">*</span></span><span data-type="text" data-id="0,3">, </span><span data-type="syntax" data-id="0,4"><span data-type="text" data-id="0,4,0">_</span></span><span data-type="italic" data-id="0,5"><span data-type="syntax" data-id="0,5,0"><span data-type="text" data-id="0,5,0,0">*</span></span><span data-type="bold" data-id="0,5,1"><span data-type="text" data-id="0,5,1,0">world</span></span><span data-type="syntax" data-id="0,5,2"><span data-type="text" data-id="0,5,2,0">*</span></span></span><span data-type="syntax" data-id="0,6"><span data-type="text" data-id="0,6,0">_</span></span><span data-type="text" data-id="0,7">!</span></p>',
227+
expect('**_Hello_**, _**world**_!').toBeParsedAsHTML(
228+
'<p data-type="line" data-id="0"><span data-type="syntax" data-id="0,0"><span data-type="text" data-id="0,0,0">**</span></span><span data-type="bold" data-id="0,1"><span data-type="syntax" data-id="0,1,0"><span data-type="text" data-id="0,1,0,0">_</span></span><span data-type="italic" data-id="0,1,1"><span data-type="text" data-id="0,1,1,0">Hello</span></span><span data-type="syntax" data-id="0,1,2"><span data-type="text" data-id="0,1,2,0">_</span></span></span><span data-type="syntax" data-id="0,2"><span data-type="text" data-id="0,2,0">**</span></span><span data-type="text" data-id="0,3">, </span><span data-type="syntax" data-id="0,4"><span data-type="text" data-id="0,4,0">_</span></span><span data-type="italic" data-id="0,5"><span data-type="syntax" data-id="0,5,0"><span data-type="text" data-id="0,5,0,0">**</span></span><span data-type="bold" data-id="0,5,1"><span data-type="text" data-id="0,5,1,0">world</span></span><span data-type="syntax" data-id="0,5,2"><span data-type="text" data-id="0,5,2,0">**</span></span></span><span data-type="syntax" data-id="0,6"><span data-type="text" data-id="0,6,0">_</span></span><span data-type="text" data-id="0,7">!</span></p>',
229229
);
230230
});
231231

src/parseExpensiMark.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,9 @@ function parseTreeToTextAndRanges(tree: StackItem): [string, MarkdownRange[]] {
134134
if (node.tag === '<>') {
135135
processChildren(node);
136136
} else if (node.tag === '<strong>') {
137-
appendSyntax('*');
137+
appendSyntax('**');
138138
addChildrenWithStyle(node, 'bold');
139-
appendSyntax('*');
139+
appendSyntax('**');
140140
} else if (node.tag === '<em>') {
141141
appendSyntax('_');
142142
addChildrenWithStyle(node, 'italic');

0 commit comments

Comments
 (0)