1
0
mirror of git://jb55.com/damus synced 2024-09-16 02:03:45 +00:00

url: smartparens hack

support urls like (https://jb55.com/something)
This commit is contained in:
William Casarin 2023-08-06 14:16:43 -07:00
parent de58e52199
commit 9e6fbeefcd
2 changed files with 19 additions and 1 deletions

View File

@ -192,7 +192,17 @@ static int parse_url(struct cursor *cur, struct note_block *block) {
cur->p = start;
return 0;
}
// smart parens
if (start - 1 >= 0 &&
start < cur->end &&
*(start - 1) == '(' &&
(cur->p - 1) < cur->end &&
*(cur->p - 1) == ')')
{
cur->p--;
}
block->type = BLOCK_URL;
block->block.str.start = (const char *)start;
block->block.str.end = (const char *)cur->p;

View File

@ -49,6 +49,14 @@ final class UrlTests: XCTestCase {
XCTAssertEqual(parsed[1].is_url?.absoluteString, "https://jb55.com")
}
func testParseSmartParens() {
let testString = "(https://nostr-con.com/simplex)"
let parsed = parse_note_content(content: .content(testString, nil)).blocks
XCTAssertNotNil(parsed)
XCTAssertEqual(parsed[1].is_url?.absoluteString, "https://nostr-con.com/simplex")
}
func testLinkIsNotAHashtag() {
let link = "https://github.com/damus-io/damus/blob/b7513f28fa1d31c2747865067256ad1d7cf43aac/damus/Nostr/NostrEvent.swift#L560"