Skip to content

Commit

Permalink
Fix/down integration (#1751)
Browse files Browse the repository at this point in the history
* WIP: integrate Down in message cell

* WIP: update MarkdownBarView

* basic implementation of MarkdownTextView

* swap out MarklightTextView with MarkdownTextView

* tidy up

* use staging backend

* reset markdown when sending

* parse attributed string when sending

* refactor current attributes

* automatically switch off header after newline

* add comments

* add support for different header types

* update header icon automatically

* only remove old headers if new one is selected

* reset active markdown when in header and newline detected

* allow designated init to be called for subclasses of TextView

* add DownStyle presets

* tidy up

* improve how currentAttributes is calculated

* tidy up

* update currentAttributes only when activeMarkdown changes

* adjust compact style

* make method private

* WIP: insertListItem stub

* markdownAtCaret returns markdown from previous position

* add Down via Carthage

* add MarkdownTextStorage

* tidy up

* add methods to add & remove markdown over a range

* selecting/deselecting header adds/removes MD over line

* tidy up

* tidy up

* activate MarkdownTextView in drafts

* improve markdownAtCaret

* support adding/removing markdown over selections

* tidy up

* refactor

* listen to notifications for text changes

* post notification for selection changes

* add method to calculate prev line range

* remove list item stub

* activate list button

* automatic list generation

* ensure only one type of header is active at a time

* re-enable emoji substitution

* refactor

* detect link attachments from parsed string

* prevent combination of code with bold or italic

* refactor

* remove Down from project file & switch off staging

* tidy up MarkdownBarView

* tidy up

* fix compact style

* update drafts

* disable MarklightTextViewTests

* process header attributes first

* add tests

* fix attributes creation order

* more tests

* more tests and some refactoring

* still more tests

* add button highlighting for lists

* update list tests

* add test stubs

* improve lists

* tidy up

* more tests

* tidy up

* tidy up

* tidy up

* tidy up

* add MarkdownTextStorageTests

* fix Down import in tests

* remove Marklight

* update method name & remove unused method

* fix typo

* fix rendering for obfuscated messages

* tidy up

* trim trailing newline if present

* update drafts to store attributed text

* adjust paragraph style

* tidy up

* update buttons after validating list

* adjust style

* adjust style

* update snapshot tests

* uodate test

* bump component

* update third party notices

* Bump Down.framework

* Try #2

* Correct tag

* Multi library approach
  • Loading branch information
johnxnguyen authored and mikeger committed Mar 12, 2018
1 parent 0dcfdbd commit 73d1a00
Show file tree
Hide file tree
Showing 34 changed files with 1,908 additions and 1,296 deletions.
2 changes: 1 addition & 1 deletion Cartfile
Expand Up @@ -13,5 +13,5 @@ github "wireapp/wire-ios-canvas" ~> 5.0
github "wireapp/HockeySDK-iOS" ~> 5.0
github "wireapp/FLAnimatedImage" "1.0.12-wire"
github "wireapp/PureLayout" "v3.0.0"
github "wireapp/Marklight" ~> 1.0.9
github "wireapp/mixpanel-swift" ~> 2.2
github "wireapp/Down" "v1.0.2-test"
2 changes: 1 addition & 1 deletion Cartfile.resolved
Expand Up @@ -5,7 +5,6 @@ github "wireapp/CocoaLumberjack" "3.3.0"
github "wireapp/FLAnimatedImage" "1.0.12-wire"
github "wireapp/FormatterKit" "1.8.1-swift3.0.2"
github "wireapp/HockeySDK-iOS" "5.0.0"
github "wireapp/Marklight" "1.0.9"
github "wireapp/PINCache" "2.3-swift3.1"
github "wireapp/PureLayout" "v3.0.0"
github "wireapp/TTTAttributedLabel" "2.0.0-swift3.0.2"
Expand Down Expand Up @@ -33,3 +32,4 @@ github "wireapp/wire-ios-testing" "13.0.1"
github "wireapp/wire-ios-transport" "34.0.2"
github "wireapp/wire-ios-utilities" "20.2.0"
github "wireapp/wire-ios-ziphy" "7.0.1"
github "wireapp/Down" "v1.0.2-test"
209 changes: 207 additions & 2 deletions THIRD-PARTY-NOTICES.txt
Expand Up @@ -806,10 +806,215 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

31) Marklight under MIT
31) Down under MIT
-----------------------

Copyright (c) 2016 Matteo Gavagnin
The MIT License (MIT)

Copyright (c) 2016 Rob Phillips.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

-----

cmark

Copyright (c) 2014, John MacFarlane

All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

-----

houdini.h, houdini_href_e.c, houdini_html_e.c, houdini_html_u.c,
html_unescape.gperf, html_unescape.h

derive from https://github.com/vmg/houdini (with some modifications)

Copyright (C) 2012 Vicent Martí

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

-----

buffer.h, buffer.c, chunk.h

are derived from code (C) 2012 Github, Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

-----

utf8.c and utf8.c

are derived from utf8proc
(<http://www.public-software-group.org/utf8proc>),
(C) 2009 Public Software Group e. V., Berlin, Germany.

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.

-----

The normalization code in runtests.py was derived from the
markdowntest project, Copyright 2013 Karl Dubost:

The MIT License (MIT)

Copyright (c) 2013 Karl Dubost

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

-----

The CommonMark spec (test/spec.txt) is

Copyright (C) 2014-15 John MacFarlane

Released under the Creative Commons CC-BY-SA 4.0 license:
<http://creativecommons.org/licenses/by-sa/4.0/>.

-----

The test software in test/ is

Copyright (c) 2014, John MacFarlane

All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

-----

The normalization code in runtests.py was derived from the
markdowntest project, Copyright 2013 Karl Dubost:

The MIT License (MIT)

Copyright (c) 2013 Karl Dubost

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
Expand Down
52 changes: 52 additions & 0 deletions Wire-iOS Tests/MarkdownTextStorageTests.swift
@@ -0,0 +1,52 @@
////
// Wire
// Copyright (C) 2018 Wire Swiss GmbH
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see http://www.gnu.org/licenses/.
//

import XCTest
@testable import Wire
import Down

final class MarkdownTextStorageTests: XCTestCase {

var sut: MarkdownTextStorage!

override func setUp() {
super.setUp()
sut = MarkdownTextStorage()
}

override func tearDown() {
sut = nil
super.tearDown()
}

func testThatItCorrectlyAddsMarkdownIDAttributeAfterAutocorrect() {
// GIVEN
let correction = "their"
let wholeRange = NSMakeRange(0, correction.characters.count)
sut.currentMarkdown = .bold
// WHEN: simulate inserting autocorrected text
sut.replaceCharacters(in: NSMakeRange(0, 0), with: correction)
sut.setAttributes([:], range: wholeRange)
// THEN
var effectiveRange = NSMakeRange(NSNotFound, 0)
let result = sut.attribute(MarkdownIDAttributeName, at: 0, effectiveRange: &effectiveRange) as? Markdown
XCTAssertEqual(.bold, result)
XCTAssertEqual(wholeRange, effectiveRange)
}

}

0 comments on commit 73d1a00

Please sign in to comment.