-
Notifications
You must be signed in to change notification settings - Fork 354
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix inconsistent spacing between paragraphs
- Loading branch information
1 parent
6e7a642
commit b57069e
Showing
12 changed files
with
130 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
ios/MullvadVPN/Extensions/NSAttributedString+Extensions.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// | ||
// NSAttributedString+Markdown.swift | ||
// MullvadVPN | ||
// | ||
// Created by pronebird on 19/11/2021. | ||
// Copyright © 2021 Mullvad VPN AB. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
|
||
extension NSAttributedString { | ||
enum MarkdownElement { | ||
case bold | ||
} | ||
|
||
convenience init( | ||
markdownString: String, | ||
options: MarkdownStylingOptions, | ||
applyEffect: ((MarkdownElement, String) -> [NSAttributedString.Key: Any])? = nil | ||
) { | ||
let attributedString = NSMutableAttributedString() | ||
let components = markdownString.components(separatedBy: "**") | ||
|
||
for (stringIndex, string) in components.enumerated() { | ||
var attributes: [NSAttributedString.Key: Any] = [:] | ||
|
||
if stringIndex % 2 == 0 { | ||
attributes[.font] = options.font | ||
} else { | ||
attributes[.font] = options.boldFont | ||
attributes.merge(applyEffect?(.bold, string) ?? [:], uniquingKeysWith: { $1 }) | ||
} | ||
|
||
attributedString.append(NSAttributedString(string: string, attributes: attributes)) | ||
} | ||
|
||
attributedString.addAttribute( | ||
.paragraphStyle, | ||
value: options.paragraphStyle, | ||
range: NSRange(location: 0, length: attributedString.length) | ||
) | ||
|
||
self.init(attributedString: attributedString) | ||
} | ||
} | ||
|
||
extension NSMutableAttributedString { | ||
func apply(paragraphStyle: NSParagraphStyle) { | ||
let attributeRange = NSRange(location: 0, length: length) | ||
addAttribute(.paragraphStyle, value: paragraphStyle, range: attributeRange) | ||
} | ||
} |
60 changes: 0 additions & 60 deletions
60
ios/MullvadVPN/Extensions/NSAttributedString+Markdown.swift
This file was deleted.
Oops, something went wrong.
20 changes: 20 additions & 0 deletions
20
ios/MullvadVPN/Extensions/NSParagraphStyle+Extensions.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// | ||
// NSParagraphStyle+Extensions.swift | ||
// MullvadVPN | ||
// | ||
// Created by Jon Petersson on 2024-06-27. | ||
// Copyright © 2024 Mullvad VPN AB. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
|
||
extension NSParagraphStyle { | ||
static var alert: NSParagraphStyle { | ||
let style = NSMutableParagraphStyle() | ||
|
||
style.paragraphSpacing = 16 | ||
style.lineBreakMode = .byWordWrapping | ||
|
||
return style | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.