Skip to content

Commit c527df6

Browse files
authored
Merge pull request #24 from M2Mobi/feature/OptimizeInlineImageSwift3.0
Feature/optimize inline image swift3.0
2 parents 39dff77 + bdcc5af commit c527df6

File tree

12 files changed

+88
-20
lines changed

12 files changed

+88
-20
lines changed

Example/Podfile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,11 @@ target 'markymark_Tests' do
1111

1212
pod 'markymark', :path => '../'
1313
end
14+
15+
post_install do |installer|
16+
installer.pods_project.targets.each do |target|
17+
target.build_configurations.each do |config|
18+
config.build_settings['SWIFT_VERSION'] = '3.0'
19+
end
20+
end
21+
end

Example/Podfile.lock

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
PODS:
2-
- markymark (0.1.5)
2+
- markymark (3.0.2)
33

44
DEPENDENCIES:
55
- markymark (from `../`)
66

77
EXTERNAL SOURCES:
88
markymark:
9-
:path: ../
9+
:path: "../"
1010

1111
SPEC CHECKSUMS:
12-
markymark: c2c5e17740530f1273495eac05a7de6ca987e305
12+
markymark: 5d40bacda3f5c401c9aa7f662ab8d764fa865792
1313

14-
PODFILE CHECKSUM: 481cd97f67bbaaac4fbd503a35c4acb0fe69c1cc
14+
PODFILE CHECKSUM: 1823fb3e3e4adb2b8d02e7af879d75b146ddd807
1515

16-
COCOAPODS: 1.1.0.rc.2
16+
COCOAPODS: 1.0.1

Example/markymark.xcodeproj/project.pbxproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@
347347
isa = PBXProject;
348348
attributes = {
349349
LastSwiftUpdateCheck = 0720;
350-
LastUpgradeCheck = 0800;
350+
LastUpgradeCheck = 0820;
351351
ORGANIZATIONNAME = CocoaPods;
352352
TargetAttributes = {
353353
607FACCF1AFB9204008FA782 = {
@@ -417,7 +417,7 @@
417417
);
418418
runOnlyForDeploymentPostprocessing = 0;
419419
shellPath = /bin/sh;
420-
shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n";
420+
shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n";
421421
showEnvVarsInLog = 0;
422422
};
423423
029A2E5D6800056D702BE822 /* [CP] Embed Pods Frameworks */ = {
@@ -477,7 +477,7 @@
477477
);
478478
runOnlyForDeploymentPostprocessing = 0;
479479
shellPath = /bin/sh;
480-
shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n";
480+
shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n";
481481
showEnvVarsInLog = 0;
482482
};
483483
F220BF3FD9625FD67595F183 /* [CP] Embed Pods Frameworks */ = {

Example/markymark.xcodeproj/xcshareddata/xcschemes/markymark-Example.xcscheme

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "0800"
3+
LastUpgradeVersion = "0820"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"

Example/markymark/Images.xcassets/AppIcon.appiconset/Contents.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
{
22
"images" : [
3+
{
4+
"idiom" : "iphone",
5+
"size" : "20x20",
6+
"scale" : "2x"
7+
},
8+
{
9+
"idiom" : "iphone",
10+
"size" : "20x20",
11+
"scale" : "3x"
12+
},
313
{
414
"idiom" : "iphone",
515
"size" : "29x29",
@@ -35,4 +45,4 @@
3545
"version" : 1,
3646
"author" : "xcode"
3747
}
38-
}
48+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"images" : [
3+
{
4+
"idiom" : "universal",
5+
"filename" : "appleLogo.png",
6+
"scale" : "1x"
7+
},
8+
{
9+
"idiom" : "universal",
10+
"scale" : "2x"
11+
},
12+
{
13+
"idiom" : "universal",
14+
"scale" : "3x"
15+
}
16+
],
17+
"info" : {
18+
"version" : 1,
19+
"author" : "xcode"
20+
}
21+
}
Loading
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"images" : [
3+
{
4+
"idiom" : "universal",
5+
"filename" : "appleLogoSmall.png",
6+
"scale" : "1x"
7+
},
8+
{
9+
"idiom" : "universal",
10+
"scale" : "2x"
11+
},
12+
{
13+
"idiom" : "universal",
14+
"scale" : "3x"
15+
}
16+
],
17+
"info" : {
18+
"version" : 1,
19+
"author" : "xcode"
20+
}
21+
}
Loading

Example/markymark/markdown.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ c. Number 3
5151
---
5252
![My Apple](http://images.apple.com/apple-events/static/apple-events/october-2013/video/poster_large.jpg)
5353

54+
Inline image ![Apple logo](appleLogo) Apple logo ![Apple logo](appleLogoSmall)
55+
5456
# Paragraphs
5557
Lorem ipsum *dolor* sit amet, __consectetur__ adipiscing elit. Proin ***aliquet vulputate*** diam. Duis sodales ~~sapien~~ quis ***elementum* posuere**. Duis quam lectus, posueresed [~~pellentesqueaauctor~~](https://m2mobi.com) eu [Velit](https://m2mobi.com).
5658
---
@@ -71,4 +73,4 @@ On *multiple* lines
7173

7274
``` @Override ```
7375

74-
Or maybe in line `@Override`
76+
Or maybe in line `@Override`

markymark.podspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = "markymark"
3-
s.version = "3.0.1"
3+
s.version = "3.0.2"
44
s.summary = "Markdown parser for iOS"
55
s.description = <<-DESC
66
Marky Mark is a parser written in Swift that converts markdown into native views. The way it looks is highly customizable and the supported markdown syntax and tags are easy to extend.
@@ -15,4 +15,4 @@ Marky Mark is a parser written in Swift that converts markdown into native views
1515

1616
s.source_files = 'markymark/Classes/**/*{.swift}'
1717

18-
end
18+
end

markymark/Classes/Layout Builders/AttributedString/Block Builders/Inline/TextAttachment.swift

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,23 @@ import Foundation
1010
import UIKit
1111

1212
class TextAttachment: NSTextAttachment {
13-
13+
1414
override func attachmentBounds(for textContainer: NSTextContainer?, proposedLineFragment lineFrag: CGRect, glyphPosition position: CGPoint, characterIndex charIndex: Int) -> CGRect {
15-
15+
1616
var imageSize = CGSize()
17-
17+
1818
let originalImageSize = image?.size ?? CGSize()
1919
let imageRatio = originalImageSize.height / originalImageSize.width
20-
21-
imageSize.width = lineFrag.width
22-
imageSize.height = imageSize.width * imageRatio
23-
20+
21+
let desiredWidth = originalImageSize.height/imageRatio
22+
if desiredWidth > lineFrag.width {
23+
imageSize.width = lineFrag.width
24+
imageSize.height = imageSize.width * imageRatio
25+
} else {
26+
imageSize.height = originalImageSize.height
27+
imageSize.width = desiredWidth
28+
}
29+
2430
return CGRect(origin: CGPoint(), size: imageSize)
2531
}
2632
}

0 commit comments

Comments
 (0)