Skip to content

Commit

Permalink
Merge branch 'gonzalezreal:main' into feature/fbernardo/mutiple_table…
Browse files Browse the repository at this point in the history
…_styles
  • Loading branch information
fbernardo authored Sep 15, 2024
2 parents aa22c2e + 5544181 commit a68a7b5
Show file tree
Hide file tree
Showing 15 changed files with 161 additions and 85 deletions.
12 changes: 5 additions & 7 deletions .github/workflows/format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@ on:
jobs:
format:
name: swift-format
runs-on: macos-12
runs-on: macos-13
steps:
- uses: actions/checkout@v2
- name: Select Xcode 14.2
run: sudo xcode-select -s /Applications/Xcode_14.2.app
- name: Tap
run: brew tap pointfreeco/formulae
- uses: actions/checkout@v4
- name: Select Xcode
run: sudo xcode-select -s /Applications/Xcode_15.0.app
- name: Install
run: brew install Formulae/swift-format@5.7
run: brew install swift-format
- name: Format
run: make format
- uses: stefanzweifel/git-auto-commit-action@v4
Expand Down
16 changes: 8 additions & 8 deletions Examples/Demo/Demo/CodeSyntaxHighlightView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,14 @@ struct CodeSyntaxHighlightView: View {
}

private func copyToClipboard(_ string: String) {
#if os(macOS)
if let pasteboard = NSPasteboard.general {
pasteboard.clearContents()
pasteboard.setString(string, forType: .string)
}
#elseif os(iOS)
UIPasteboard.general.string = string
#endif
#if os(macOS)
if let pasteboard = NSPasteboard.general {
pasteboard.clearContents()
pasteboard.setString(string, forType: .string)
}
#elseif os(iOS)
UIPasteboard.general.string = string
#endif
}
}

Expand Down
10 changes: 10 additions & 0 deletions Sources/MarkdownUI/DSL/Inlines/SoftBreak.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,13 @@ public struct SoftBreak: InlineContentProtocol {
.init(inlines: [.softBreak])
}
}

extension SoftBreak {
public enum Mode {
/// Treat a soft break as a space
case space

/// Treat a soft break as a line break
case lineBreak
}
}
2 changes: 1 addition & 1 deletion Sources/MarkdownUI/Parser/InlineNode.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Foundation

enum InlineNode: Hashable {
enum InlineNode: Hashable, Sendable {
case text(String)
case softBreak
case lineBreak
Expand Down
18 changes: 15 additions & 3 deletions Sources/MarkdownUI/Renderer/AttributedStringInlineRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ extension InlineNode {
func renderAttributedString(
baseURL: URL?,
textStyles: InlineTextStyles,
softBreakMode: SoftBreak.Mode,
attributes: AttributeContainer
) -> AttributedString {
var renderer = AttributedStringInlineRenderer(
baseURL: baseURL,
textStyles: textStyles,
softBreakMode: softBreakMode,
attributes: attributes
)
renderer.render(self)
Expand All @@ -21,12 +23,19 @@ private struct AttributedStringInlineRenderer {

private let baseURL: URL?
private let textStyles: InlineTextStyles
private let softBreakMode: SoftBreak.Mode
private var attributes: AttributeContainer
private var shouldSkipNextWhitespace = false

init(baseURL: URL?, textStyles: InlineTextStyles, attributes: AttributeContainer) {
init(
baseURL: URL?,
textStyles: InlineTextStyles,
softBreakMode: SoftBreak.Mode,
attributes: AttributeContainer
) {
self.baseURL = baseURL
self.textStyles = textStyles
self.softBreakMode = softBreakMode
self.attributes = attributes
}

Expand Down Expand Up @@ -67,10 +76,13 @@ private struct AttributedStringInlineRenderer {
}

private mutating func renderSoftBreak() {
if self.shouldSkipNextWhitespace {
switch softBreakMode {
case .space where self.shouldSkipNextWhitespace:
self.shouldSkipNextWhitespace = false
} else {
case .space:
self.result += .init(" ", attributes: self.attributes)
case .lineBreak:
self.renderLineBreak()
}
}

Expand Down
14 changes: 12 additions & 2 deletions Sources/MarkdownUI/Renderer/TextInlineRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ extension Sequence where Element == InlineNode {
baseURL: URL?,
textStyles: InlineTextStyles,
images: [String: Image],
softBreakMode: SoftBreak.Mode,
attributes: AttributeContainer
) -> Text {
var renderer = TextInlineRenderer(
baseURL: baseURL,
textStyles: textStyles,
images: images,
softBreakMode: softBreakMode,
attributes: attributes
)
renderer.render(self)
Expand All @@ -24,18 +26,21 @@ private struct TextInlineRenderer {
private let baseURL: URL?
private let textStyles: InlineTextStyles
private let images: [String: Image]
private let softBreakMode: SoftBreak.Mode
private let attributes: AttributeContainer
private var shouldSkipNextWhitespace = false

init(
baseURL: URL?,
textStyles: InlineTextStyles,
images: [String: Image],
softBreakMode: SoftBreak.Mode,
attributes: AttributeContainer
) {
self.baseURL = baseURL
self.textStyles = textStyles
self.images = images
self.softBreakMode = softBreakMode
self.attributes = attributes
}

Expand Down Expand Up @@ -72,10 +77,14 @@ private struct TextInlineRenderer {
}

private mutating func renderSoftBreak() {
if self.shouldSkipNextWhitespace {
switch self.softBreakMode {
case .space where self.shouldSkipNextWhitespace:
self.shouldSkipNextWhitespace = false
} else {
case .space:
self.defaultRender(.softBreak)
case .lineBreak:
self.shouldSkipNextWhitespace = true
self.defaultRender(.lineBreak)
}
}

Expand Down Expand Up @@ -104,6 +113,7 @@ private struct TextInlineRenderer {
inline.renderAttributedString(
baseURL: self.baseURL,
textStyles: self.textStyles,
softBreakMode: self.softBreakMode,
attributes: self.attributes
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ extension Font {
case .system(let design):
font = .system(size: size, design: design)
case .custom(let name):
font = .custom(name, size: size)
font = .custom(name, fixedSize: size)
}

switch fontProperties.familyVariant {
Expand Down
73 changes: 27 additions & 46 deletions Sources/MarkdownUI/Utility/Deprecations.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ extension View {
@available(
*,
deprecated,
message:
"""
message: """
Use the version of this function that takes a closure receiving a generic 'Configuration'
value.
"""
Expand All @@ -62,8 +61,7 @@ extension View {
@available(
*,
deprecated,
message:
"""
message: """
Use the version of this function that takes a closure receiving a generic 'Configuration'
value.
"""
Expand All @@ -85,8 +83,7 @@ extension Theme {
@available(
*,
deprecated,
message:
"""
message: """
Use the version of this function that takes a closure receiving a 'BlockConfiguration'
value.
"""
Expand All @@ -102,8 +99,7 @@ extension Theme {
@available(
*,
deprecated,
message:
"""
message: """
Use the version of this function that takes a closure receiving a 'BlockConfiguration'
value.
"""
Expand All @@ -119,8 +115,7 @@ extension Theme {
@available(
*,
deprecated,
message:
"""
message: """
Use the version of this function that takes a closure receiving a 'BlockConfiguration'
value.
"""
Expand All @@ -136,8 +131,7 @@ extension Theme {
@available(
*,
deprecated,
message:
"""
message: """
Use the version of this function that takes a closure receiving a 'BlockConfiguration'
value.
"""
Expand All @@ -153,8 +147,7 @@ extension Theme {
@available(
*,
deprecated,
message:
"""
message: """
Use the version of this function that takes a closure receiving a 'BlockConfiguration'
value.
"""
Expand All @@ -170,8 +163,7 @@ extension Theme {
@available(
*,
deprecated,
message:
"""
message: """
Use the version of this function that takes a closure receiving a 'BlockConfiguration'
value.
"""
Expand All @@ -187,8 +179,7 @@ extension Theme {
@available(
*,
deprecated,
message:
"""
message: """
Use the version of this function that takes a closure receiving a 'BlockConfiguration'
value.
"""
Expand All @@ -204,8 +195,7 @@ extension Theme {
@available(
*,
deprecated,
message:
"""
message: """
Use the version of this function that takes a closure receiving a 'BlockConfiguration'
value.
"""
Expand All @@ -221,8 +211,7 @@ extension Theme {
@available(
*,
deprecated,
message:
"""
message: """
Use the version of this function that takes a closure receiving a 'CodeBlockConfiguration'
value.
"""
Expand All @@ -240,8 +229,7 @@ extension Theme {
@available(
*,
deprecated,
message:
"""
message: """
Use the version of this function that takes a closure receiving a 'BlockConfiguration'
value.
"""
Expand All @@ -257,8 +245,7 @@ extension Theme {
@available(
*,
deprecated,
message:
"""
message: """
Use the version of this function that takes a closure receiving a 'BlockConfiguration'
value.
"""
Expand All @@ -274,8 +261,7 @@ extension Theme {
@available(
*,
deprecated,
message:
"""
message: """
Use the version of this function that takes a closure receiving a 'BlockConfiguration'
value.
"""
Expand All @@ -291,8 +277,7 @@ extension Theme {
@available(
*,
deprecated,
message:
"""
message: """
Use the version of this function that takes a closure receiving a 'BlockConfiguration'
value.
"""
Expand Down Expand Up @@ -330,11 +315,10 @@ public typealias InlineCode = Code
@available(
*,
unavailable,
message:
message: """
"MarkdownImageHandler" has been superseded by the "ImageProvider" protocol and its conforming
types "DefaultImageProvider" and "AssetImageProvider".
"""
"MarkdownImageHandler" has been superseded by the "ImageProvider" protocol and its conforming
types "DefaultImageProvider" and "AssetImageProvider".
"""
)
public struct MarkdownImageHandler {
public static var networkImage: Self {
Expand All @@ -353,11 +337,10 @@ extension Markdown {
@available(
*,
unavailable,
message:
message: """
"MarkdownImageHandler" has been superseded by the "ImageProvider" protocol and its conforming
types "DefaultImageProvider" and "AssetImageProvider".
"""
"MarkdownImageHandler" has been superseded by the "ImageProvider" protocol and its conforming
types "DefaultImageProvider" and "AssetImageProvider".
"""
)
public func setImageHandler(
_ imageHandler: MarkdownImageHandler,
Expand All @@ -381,11 +364,10 @@ extension View {
@available(
*,
unavailable,
message:
message: """
"MarkdownStyle" and its subtypes have been superseded by the "Theme", "TextStyle", and
"BlockStyle" types.
"""
"MarkdownStyle" and its subtypes have been superseded by the "Theme", "TextStyle", and
"BlockStyle" types.
"""
)
public struct MarkdownStyle: Hashable {
public struct Font: Hashable {
Expand Down Expand Up @@ -501,11 +483,10 @@ extension View {
@available(
*,
unavailable,
message:
message: """
"MarkdownStyle" and its subtypes have been superseded by the "Theme", "TextStyle", and
"BlockStyle" types.
"""
"MarkdownStyle" and its subtypes have been superseded by the "Theme", "TextStyle", and
"BlockStyle" types.
"""
)
public func markdownStyle(_ markdownStyle: MarkdownStyle) -> some View {
self
Expand Down
Loading

0 comments on commit a68a7b5

Please sign in to comment.