damus

nostr ios client
git clone git://jb55.com/damus
Log | Files | Refs | README | LICENSE

commit 9e6fbeefcdb3a83167f9bc9851446007b34039e1
parent de58e5219974fef90bc917609e5372715cc8f025
Author: William Casarin <jb55@jb55.com>
Date:   Sun,  6 Aug 2023 14:16:43 -0700

url: smartparens hack

support urls like (https://jb55.com/something)

Diffstat:
Mdamus-c/damus.c | 12+++++++++++-
MdamusTests/UrlTests.swift | 8++++++++
2 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/damus-c/damus.c b/damus-c/damus.c @@ -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; diff --git a/damusTests/UrlTests.swift b/damusTests/UrlTests.swift @@ -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"