Skip to content
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
4 changes: 2 additions & 2 deletions Sources/MarkdownView/Caches/Cacheable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import Foundation

protocol Cacheable {
associatedtype CacheKey: Hashable
var cacheKey: CacheKey { get }
associatedtype Key: Hashable
var cacheKey: Key { get }

init?(fromCache value: any Cacheable)
}
Expand Down
148 changes: 0 additions & 148 deletions Sources/MarkdownView/Configurations/MarkdownListConfiguration.swift

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// AnyOrderedListMarkerProtocol.swift
// MarkdownView
//
// Created by Yanan Li on 2025/10/27.
//

import Foundation

struct AnyOrderedListMarkerProtocol: OrderedListMarkerProtocol {
private var _marker: AnyHashable
var monospaced: Bool {
(_marker as! (any OrderedListMarkerProtocol)).monospaced
}

init<T: OrderedListMarkerProtocol>(_ marker: T) {
self._marker = AnyHashable(marker)
}

public func marker(at index: Int, listDepth: Int) -> String {
(_marker as! (any OrderedListMarkerProtocol)).marker(at: index, listDepth: listDepth)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// OrderedListIncreasingDigitsMarker.swift
// MarkdownView
//
// Created by Yanan Li on 2025/10/27.
//

import Foundation

/// An auto-increasing digits marker for ordered list items.
public struct OrderedListIncreasingDigitsMarker: OrderedListMarkerProtocol {
public func marker(at index: Int, listDepth: Int) -> String {
String(index + 1) + "."
}

public var monospaced: Bool { false }
}

extension OrderedListMarkerProtocol where Self == OrderedListIncreasingDigitsMarker {
/// An auto-increasing digits marker for ordered list items.
static public var increasingDigits: OrderedListIncreasingDigitsMarker { .init() }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//
// OrderedListIncreasingLettersMarker.swift
// MarkdownView
//
// Created by Yanan Li on 2025/10/27.
//

import Foundation

/// An auto-increasing letters marker for ordered list items.
public struct OrderedListIncreasingLettersMarker: OrderedListMarkerProtocol {
public func marker(at index: Int, listDepth: Int) -> String {
let base = 26
var index = index
var result = ""

// If index is smaller than 26, use single letter, otherwise, use double letters.
if index < base {
result = String(UnicodeScalar("a".unicodeScalars.first!.value + UInt32(index))!)
} else {
index -= base
let firstLetterIndex = index / base
let secondLetterIndex = index % base
let firstLetter = UnicodeScalar("a".unicodeScalars.first!.value + UInt32(firstLetterIndex))!
let secondLetter = UnicodeScalar("a".unicodeScalars.first!.value + UInt32(secondLetterIndex))!
result.append(Character(firstLetter))
result.append(Character(secondLetter))
}

return result + "."
}

public var monospaced: Bool { false }
}

extension OrderedListMarkerProtocol where Self == OrderedListIncreasingLettersMarker {
/// An auto-increasing letters marker for ordered list items.
static public var increasingLetters: OrderedListIncreasingLettersMarker { .init() }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// OrderedListMarkerProtocol.swift
// MarkdownView
//
// Created by Yanan Li on 2025/10/27.
//

import Foundation

/// A type that represents the marker for ordered list items.
public protocol OrderedListMarkerProtocol: Hashable {
/// Returns a marker for a specific index of ordered list item. Index starting from 0.
func marker(at index: Int, listDepth: Int) -> String

/// A boolean value indicates whether the marker should be monospaced, default value is `true`.
var monospaced: Bool { get }
}

extension OrderedListMarkerProtocol {
public var monospaced: Bool {
true
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// AnyUnorderedListMarkerProtocol.swift
// MarkdownView
//
// Created by Yanan Li on 2025/10/27.
//

import Foundation

struct AnyUnorderedListMarkerProtocol: UnorderedListMarkerProtocol {
private var _marker: AnyHashable
var monospaced: Bool {
(_marker as! (any UnorderedListMarkerProtocol)).monospaced
}

init<T: UnorderedListMarkerProtocol>(_ marker: T) {
self._marker = AnyHashable(marker)
}

public func marker(listDepth: Int) -> String {
(_marker as! (any UnorderedListMarkerProtocol)).marker(listDepth: listDepth)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// UnorderedListBulletMarker.swift
// MarkdownView
//
// Created by Yanan Li on 2025/10/27.
//

import Foundation

/// A bullet marker for unordered list items.
public struct UnorderedListBulletMarker: UnorderedListMarkerProtocol {
public func marker(listDepth: Int) -> String {
"•"
}
}

extension UnorderedListMarkerProtocol where Self == UnorderedListBulletMarker {
/// A bullet marker for unordered list items.
static public var bullet: UnorderedListBulletMarker { .init() }
}
Loading