-
Notifications
You must be signed in to change notification settings - Fork 150
Improve Mark formatting #1352
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Improve Mark formatting #1352
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
d655451
Mark Formatting - Fix autocorrected strings and changing the caret po…
af4c463
Mark formatter - Fix autocorrected formatting
61c04b7
Merge branch 'develop' into feature/mark-formatting-improvements
dd8a325
Remove setting the color to the placeholder attributes
87b3cd8
Update preprocessMarkForInsertion
fadc312
Fix whitespace issues
4711da4
Update MarkFormatter to support incoming color changes
590b646
Update how toggleMark works to support color customization and resett…
42485a7
Update TextStorage to process the mark formatting within replaceChara…
2970e7f
Fix Hound lint issues
8712387
Fix lint issue
a41d881
Update MarkConverter to remove extra spaces within the style attribute
28e62ab
Use if let to unwrap textColor value
7b9cc63
Fix defaultTextColor typo
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
47 changes: 47 additions & 0 deletions
47
...onverters/StringAttributesToAttributes/Implementations/MarkStringAttributeConverter.swift
This file contains hidden or 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,47 @@ | ||
| import Foundation | ||
| import UIKit | ||
|
|
||
| /// Converts the mark style information from string attributes and aggregates it into an | ||
| /// existing array of element nodes. | ||
| /// | ||
| open class MarkStringAttributeConverter: StringAttributeConverter { | ||
|
|
||
| private let toggler = HTMLStyleToggler(defaultElement: .mark, cssAttributeMatcher: ForegroundColorCSSAttributeMatcher()) | ||
|
|
||
| public func convert( | ||
| attributes: [NSAttributedString.Key: Any], | ||
| andAggregateWith elementNodes: [ElementNode]) -> [ElementNode] { | ||
|
|
||
| var elementNodes = elementNodes | ||
|
|
||
| // We add the representation right away, if it exists... as it could contain attributes beyond just this | ||
| // style. The enable and disable methods below can modify this as necessary. | ||
| // | ||
|
|
||
| if let elementNode = attributes.storedElement(for: NSAttributedString.Key.markHtmlRepresentation) { | ||
| let styleAttribute = elementNode.attributes.first(where: { $0.name == "style" }) | ||
| if let elementStyle = styleAttribute?.value.toString() { | ||
| // Remove spaces between attribute name and value, and between style attributes. | ||
| let styleAttributes = elementStyle.replacingOccurrences(of: ": ", with: ":").replacingOccurrences(of: "; ", with: ";") | ||
| elementNode.attributes["style"] = .string(styleAttributes) | ||
| } | ||
| elementNodes.append(elementNode) | ||
| } | ||
|
|
||
| if shouldEnableMarkElement(for: attributes) { | ||
| return toggler.enable(in: elementNodes) | ||
| } else { | ||
| return toggler.disable(in: elementNodes) | ||
| } | ||
| } | ||
|
|
||
| // MARK: - Style Detection | ||
|
|
||
| func shouldEnableMarkElement(for attributes: [NSAttributedString.Key: Any]) -> Bool { | ||
| return isMark(for: attributes) | ||
| } | ||
|
|
||
| func isMark(for attributes: [NSAttributedString.Key: Any]) -> Bool { | ||
| return attributes[.markHtmlRepresentation] != nil | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.