Skip to content

Commit

Permalink
fix(bluesky-richtext-parser): account for line terminator
Browse files Browse the repository at this point in the history
  • Loading branch information
mary-ext committed Oct 17, 2024
1 parent 325adf4 commit 7139f4e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
25 changes: 25 additions & 0 deletions packages/bluesky/richtext-parser/lib/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ it('plain', () => {
text: 'hello world',
},
]);

expect(tokenize('\n')).toEqual([
{
type: 'text',
raw: '\n',
text: '\n',
},
]);
});

it('escapes', () => {
Expand Down Expand Up @@ -445,6 +453,23 @@ it('autolinks', () => {
url: 'https://example.com/',
},
]);

expect(
tokenize(
'https://github.com/mary-ext/atproto-scraping/commit/\ncaaa495ae654ef8a98f223f3cecfe2ca261d6b4f',
),
).toEqual([
{
type: 'autolink',
raw: 'https://github.com/mary-ext/atproto-scraping/commit/',
url: 'https://github.com/mary-ext/atproto-scraping/commit/',
},
{
type: 'text',
raw: '\ncaaa495ae654ef8a98f223f3cecfe2ca261d6b4f',
text: '\ncaaa495ae654ef8a98f223f3cecfe2ca261d6b4f',
},
]);
});

it('links', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/bluesky/richtext-parser/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const LINK_RE = /^\[((?:\[(?:\\.|[^\[\]\\])*\]|\\.|[^\[\]\\])*?)\]\((.*?)\)/;

const ESCAPE_RE = /^\\([@#:\\\[])/;

const TEXT_RE = /^.+?(?:(?=$|[:\\\[]|https?:\/\/)|(?:\s|(?<=[(){}\/\\\[\]\-|:;'".,=+]))(?=[@#]))/;
const TEXT_RE = /^[^]+?(?:(?=$|[:\\\[]|https?:\/\/)|(?:\s|(?<=[(){}\/\\\[\]\-|:;'".,=+]))(?=[@#]))/;

export interface MentionToken {
type: 'mention';
Expand Down

0 comments on commit 7139f4e

Please sign in to comment.