Skip to content
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

Code Refactor #37

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// Markdown.ListConfiguration.swift
// MarkdownView
//
// Created by LiYanan2004 on 2024/12/11.
//

import SwiftUI

public struct MarkdownListConfiguration: Sendable, Hashable {
var listIndent: CGFloat = 12
var unorderedListBullet: String = "•"
}
27 changes: 27 additions & 0 deletions Sources/MarkdownView/Configuration/MarkdownView.Role.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// MarkdownView.Role.swift
// MarkdownView
//
// Created by LiYanan2004 on 2024/12/11.
//

import Foundation

extension MarkdownView {
/// The role of MarkdownView, which affects how MarkdownView is rendered.
public enum Role: Sendable, Hashable {
/// The normal role.
///
/// A role that makes the view take the space it needs and center contents, like a normal SwiftUI View.
case normal
/// The editor role.
///
/// A role that makes the view take the maximum space
/// and align its content in the top-leading, just like an editor.
///
/// A Markdown Editor typically use this mode to provide a Live Preview.
///
/// - note: Editor mode is unsupported on watchOS.
case editor
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// RendererConfiguration.Environment.swift
// MarkdownView
//
// Created by LiYanan2004 on 2024/12/11.
//

import Foundation
import SwiftUI

struct MarkdownRendererConfigurationKey: @preconcurrency EnvironmentKey {
@MainActor static var defaultValue: MarkdownView.RendererConfiguration = .init()
}

extension EnvironmentValues {
var markdownRendererConfiguration: MarkdownView.RendererConfiguration {
get { self[MarkdownRendererConfigurationKey.self] }
set { self[MarkdownRendererConfigurationKey.self] = newValue }
}
}
44 changes: 44 additions & 0 deletions Sources/MarkdownView/Configuration/RendererConfiguration.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//
// RendererConfiguration.swift
// MarkdownView
//
// Created by LiYanan2004 on 2024/12/11.
//

import Foundation
import SwiftUI

extension MarkdownView {
struct RendererConfiguration: Equatable {
var role: MarkdownView.Role = .normal
var renderingMode: MarkdownRenderingMode = .immediate

// Spacing
var lineSpacing: CGFloat? = nil
var componentSpacing: CGFloat = 8

mutating func withLineSpacing(_ lineSpacing: CGFloat) {
self.lineSpacing = lineSpacing
}

// Tint
var inlineCodeTintColor: Color = .accentColor
var blockQuoteTintColor: Color = .accentColor

// Font & Foreground style
var fontGroup: AnyMarkdownFontGroup = .init(.automatic)
var foregroundStyleGroup: AnyMarkdownForegroundStyleGroup = .init(.automatic)

// Code Block
var codeBlockTheme: CodeHighlighterTheme = .init(
lightModeThemeName: "xcode", darkModeThemeName: "dark"
)

// List
var listConfiguration: MarkdownListConfiguration = .init()

// Renderer
var blockDirectiveRenderer: BlockDirectiveRenderer = .init()
var imageRenderer: ImageRenderer = .init()
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -33,29 +33,3 @@ public struct CodeHighlighterTheme: Equatable, Sendable {
self.darkModeThemeName = darkModeThemeName
}
}

struct CodeHighlighterThemeKey: EnvironmentKey {
static let defaultValue: CodeHighlighterTheme = CodeHighlighterTheme(
lightModeThemeName: "xcode", darkModeThemeName: "dark"
)
}

extension EnvironmentValues {
var codeHighlighterTheme: CodeHighlighterTheme {
get { self[CodeHighlighterThemeKey.self] }
set { self[CodeHighlighterThemeKey.self] = newValue }
}
}

extension View {
/// Sets the theme of the code highlighter.
///
/// For more information of available themes, see ``CodeHighlighterTheme``.
///
/// - Parameter theme: The theme for highlighter.
///
/// - note: Code highlighting is not available on watchOS.
public func codeHighlighterTheme(_ theme: CodeHighlighterTheme) -> some View {
environment(\.codeHighlighterTheme, theme)
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import SwiftUI

/// A type-erased MarkdownFontGroup value.
public struct AnyMarkdownFontGroup: Sendable {
public struct AnyMarkdownFontGroup: Sendable, Hashable {
var _h1: Font
var _h2: Font
var _h3: Font
Expand Down
61 changes: 0 additions & 61 deletions Sources/MarkdownView/Customization/Font/FontModifiers.swift

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import Foundation

public enum MarkdownTextType: Equatable, CaseIterable {
case h1,h2,h3,h4,h5,h6
case h1, h2, h3, h4, h5, h6
case body
case codeBlock,blockQuote
case tableHeader,tableBody
case codeBlock, blockQuote
case tableHeader, tableBody
}

This file was deleted.

43 changes: 0 additions & 43 deletions Sources/MarkdownView/Customization/LayoutRole.swift

This file was deleted.

Loading