Skip to content

implement link detection in FAQ answers#295

Open
Giorgi217 wants to merge 1 commit intodevelopfrom
bug/EPMEDU-4855-Invalid-Url-FAQ
Open

implement link detection in FAQ answers#295
Giorgi217 wants to merge 1 commit intodevelopfrom
bug/EPMEDU-4855-Invalid-Url-FAQ

Conversation

@Giorgi217
Copy link
Copy Markdown
Collaborator

@Giorgi217 Giorgi217 commented Mar 29, 2026

Pull Request overview

Enable clickable links in FAQ answers using AttributedString


Problem

FAQ answers were displayed as plain text.

  • Links were not clickable
  • Bare domains (e.g. example.com) were not detected

Summary

  • Convert answer to AttributedString
  • Detect URLs using NSDataDetector
  • Detect bare domains via regex and convert to https:// links
  • Prevent duplicate link assignments

Changes

File What changed
QuestionViewMapper.swift Added link detection and AttributedString mapping
FAQViewItem.swift Updated answer type to AttributedString

How to test

  • Add answers with URLs and bare domains
  • Verify links are clickable
  • Ensure no duplicates or crashes
Simulator Screenshot - iPhone 17 Pro - 2026-03-29 at 06 33 50 Simulator Screenshot - iPhone 17 Pro - 2026-03-29 at 06 33 53

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR enables clickable links in FAQ answers by converting the answer text into an AttributedString and applying .link attributes for detected URLs and bare domains.

Changes:

  • Map FAQModel.Question.answer into an AttributedString with link attributes (via NSDataDetector + regex).
  • Update FAQViewItem.answer from String to AttributedString.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

let collapsed: Bool
}

private extension QuestionViewMapper {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Link detection is a common task that shouldn't live in a FAQ-specific mapper. Consider extracting to a reusable service like LinkDetector.

let id: String
let question: String
let answer: String
let answer: AttributedString
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should be careful using AttributedStrings - because they override your Text modifiers (font, color, background, etc)

}

func applyBareDomainLinks(to attributed: inout AttributedString, in text: String) {
let pattern = #"\b(?:[A-Za-z0-9-]+\.)+[A-Za-z]{2,}\b"#
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This pattern creates false positives. file.tar.gz as an example. It is better to remove it altogether.
I see two major solutions here:

  1. We made a decision not to use the bare domains and BE always sends us URLs with https:// - for example, https://animealproject.ge
  2. Use URL detector, but transform String to markdown format.
  3. BE sends us strings in markdown format (requires alignment with Android)

}

private extension QuestionViewMapper {
func attributedStringWithLinks(from text: String) -> AttributedString {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a pretty common problem, it is better to create a reusable LinkDetector class.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants