ISTWCMS-6306: Refactor link handling logic with reusable method.
Extracted link sanitization into a new prepareLink
method to improve code reusability and readability. Replaced duplicate logic with method calls to streamline the code. Updated conditions for consistent link handling and added inline documentation for clarity.