### Custom Image Style with Animation Source: https://github.com/shaps80/markdowntext/blob/main/README.md Implement a custom style for images to control their loading behavior and appearance. This example applies a scale-up transition as the image loads. ```swift struct ScaledImageStyle: ImageMarkdownStyle { // image will scale up as its loaded, moving content out of the way func makeBody(configuration: Configuration) -> some View { configuration.label .transition(.scale) } } ``` -------------------------------- ### Swift Package Manager Installation Source: https://github.com/shaps80/markdowntext/blob/main/README.md Add the MarkdownText library to your project using Swift Package Manager by including the specified package URL and version constraint in your Package.swift file. ```swift .package(url: "https://github.com/shaps80/MarkdownText.git", .upToNextMinor(from: "1.0.0")) ``` -------------------------------- ### Customize Strikethrough Inline Style Source: https://context7.com/shaps80/markdowntext/llms.txt Customize strikethrough text using `markdownStrikethroughStyle`. The `GrayStrikethroughStyle` example applies a gray strikethrough to text. ```swift import SwiftUI import MarkdownText struct GrayStrikethroughStyle: StrikethroughMarkdownStyle { func makeBody(configuration: Configuration) -> Text { configuration.content .strikethrough(true, color: .gray) .foregroundColor(.gray) } } struct StrikethroughDemoView: View { var body: some View { MarkdownText("Available and ~~discontinued item~~ and available.") .markdownStrikethroughStyle(GrayStrikethroughStyle()) } } ``` -------------------------------- ### Apply Multiple Markdown Styles in SwiftUI Source: https://context7.com/shaps80/markdowntext/llms.txt This example shows how to apply various style and visibility modifiers to MarkdownText. These modifiers compose freely and inherit through the SwiftUI environment, enabling global theming or targeted overrides. ```swift import SwiftUI import MarkdownText struct ThemedMarkdownView: View { let content: String var body: some View { NavigationView { ScrollView { MarkdownText(content, paragraphSpacing: 14) .padding() } .navigationTitle("Document") } // Block element styles .markdownHeadingStyle(ColoredHeadingStyle()) .markdownQuoteStyle(InsetQuoteStyle()) .markdownCodeStyle(ThemedCodeStyle()) .markdownThematicBreakStyle(DottedBreakStyle()) // Image styles .markdownImageStyle(.automatic) // Inline styles .markdownStrongStyle(ColoredBoldStyle()) .markdownInlineLinkStyle(UnderlinedLinkStyle()) .markdownInlineCodeStyle(HighlightedInlineCodeStyle()) // List bullet styles .markdownUnorderedListBulletStyle(ChevronBulletStyle()) .markdownOrderedListBulletStyle(CircledNumberBulletStyle()) .markdownCheckListBulletStyle(StarChecklistBulletStyle()) // Visibility .markdownThematicBreak(.hidden) } } ``` -------------------------------- ### Customize Bold (Strong) Inline Style Source: https://context7.com/shaps80/markdowntext/llms.txt Use `markdownStrongStyle` to change how bold text is rendered. The `ColoredBoldStyle` example applies a red color to bold text while keeping it bold. ```swift import SwiftUI import MarkdownText struct ColoredBoldStyle: StrongMarkdownStyle { func makeBody(configuration: Configuration) -> Text { configuration.content .bold() .foregroundColor(.red) } } struct StrongDemoView: View { var body: some View { MarkdownText("Regular and **bold red** and regular again.") .markdownStrongStyle(ColoredBoldStyle()) } } ``` -------------------------------- ### Custom Unordered List Bullet Style Source: https://github.com/shaps80/markdowntext/blob/main/README.md Define a custom view for unordered list bullets to change their appearance. This example sets the bullet color to blue. ```swift struct CustomUnorderedBullets: UnorderedListBulletMarkdownStyle { func makeBody(configuration: Configuration) -> some View { // you can also provide a completely new View if preferred 👍 configuration.label .foregroundColor(.blue) } } ``` -------------------------------- ### Customize Italic (Emphasis) Inline Style Source: https://context7.com/shaps80/markdowntext/llms.txt The `markdownEmphasisStyle` modifier customizes the appearance of italic text. The `TealItalicStyle` example renders italic text in teal. ```swift import SwiftUI import MarkdownText struct TealItalicStyle: EmphasisMarkdownStyle { func makeBody(configuration: Configuration) -> Text { configuration.content .italic() .foregroundColor(.teal) } } struct EmphasisDemoView: View { var body: some View { MarkdownText("Normal and _teal italic_ and normal.") .markdownEmphasisStyle(TealItalicStyle()) } } ``` -------------------------------- ### Customize Inline Code Style Source: https://context7.com/shaps80/markdowntext/llms.txt The `markdownInlineCodeStyle` modifier customizes the rendering of inline code spans. The `HighlightedInlineCodeStyle` example applies a purple color to inline code. ```swift import SwiftUI import MarkdownText struct HighlightedInlineCodeStyle: InlineCodeMarkdownStyle { func makeBody(configuration: Configuration) -> Text { Text(configuration.code) .font(.system(.body, design: .monospaced)) .foregroundColor(.purple) } } struct InlineCodeDemoView: View { var body: some View { MarkdownText("Call `viewDidLoad()` or use `@State` in SwiftUI.") .markdownInlineCodeStyle(HighlightedInlineCodeStyle()) } } ``` -------------------------------- ### Customize Checklist Bullet Style Source: https://context7.com/shaps80/markdowntext/llms.txt The `markdownCheckListBulletStyle` modifier allows customization of checkbox icons for checklist items. The `StarChecklistBulletStyle` example replaces the default checkbox with a star icon. ```swift import SwiftUI import MarkdownText struct StarChecklistBulletStyle: CheckListBulletMarkdownStyle { func makeBody(configuration: Configuration) -> some View { Image(systemName: configuration.isChecked ? "star.fill" : "star") .foregroundColor(configuration.isChecked ? .yellow : .gray) .frame(minWidth: 25) } } struct ChecklistDemoView: View { var body: some View { MarkdownText("- [x] Done\n- [ ] Pending\n- [x] Also done") .markdownCheckListBulletStyle(StarChecklistBulletStyle()) } } ``` -------------------------------- ### Customize Ordered List Bullet Style Source: https://context7.com/shaps80/markdowntext/llms.txt Use `markdownOrderedListBulletStyle` to define a custom appearance for ordered list item bullets. The `CircledNumberBulletStyle` example shows how to create a circled number bullet. ```swift import SwiftUI import MarkdownText struct CircledNumberBulletStyle: OrderedListBulletMarkdownStyle { func makeBody(configuration: Configuration) -> some View { Text("\(configuration.order)") .font(.caption.weight(.bold)) .foregroundColor(.white) .frame(width: 20, height: 20) .background(Color.accentColor) .clipShape(Circle()) .frame(minWidth: 25) } } struct OrderedBulletDemoView: View { var body: some View { MarkdownText("1. First\n2. Second\n3. Third") .markdownOrderedListBulletStyle(CircledNumberBulletStyle()) } } ``` -------------------------------- ### Custom Image Style with Animation Source: https://context7.com/shaps80/markdowntext/llms.txt Applies an animated scale-up and fade-in transition to images as they load. ```swift import SwiftUI import MarkdownText // Animated scale-up transition on load struct AnimatedImageStyle: ImageMarkdownStyle { func makeBody(configuration: Configuration) -> some View { configuration.label .transition(.scale.combined(with: .opacity)) .animation(.spring(), value: configuration.source) } } struct ImageDemoView: View { var body: some View { VStack { // Remote image MarkdownText("![A photo](https://picsum.photos/400/200)") .markdownImageStyle(AnimatedImageStyle()) // SF Symbol fallback MarkdownText("![](star.fill)") .markdownImageStyle(.symbol) } } } ``` -------------------------------- ### Basic Markdown Rendering with MarkdownText Source: https://context7.com/shaps80/markdowntext/llms.txt Renders a Markdown string as a SwiftUI VStack. Supports common Markdown elements and custom paragraph spacing. ```swift import SwiftUI import MarkdownText struct ContentView: View { let markdown = """# Hello, World!\n\nThis is **bold**, _italic_, and ~~strikethrough~~ text.\nHere is some `inline code` and a [link](https://example.com).\n\n> A block quote with *emphasis*.\n\n1. First item\n2. Second item\n - Nested unordered\n - Another nested\n\n- [x] Task complete\n- [ ] Task pending\n\n```swift\nlet x = 42\n```\n\n---\n" var body: some View { ScrollView { MarkdownText(markdown, paragraphSpacing: 16) .padding() } } } ``` -------------------------------- ### Basic MarkdownText Usage Source: https://github.com/shaps80/markdowntext/blob/main/README.md Render simple Markdown text directly using the MarkdownText view. This is the most straightforward way to display formatted text. ```swift MarkdownText("Some **markdown** text") ``` -------------------------------- ### Custom List Container Style Source: https://context7.com/shaps80/markdowntext/llms.txt Wraps list content in a container with padding, a background color, and rounded corners. ```swift import SwiftUI import MarkdownText struct CardListStyle: ListMarkdownStyle { func makeBody(configuration: Configuration) -> some View { configuration.label .padding(12) .background(Color(.systemGray6)) .cornerRadius(10) } } struct ListDemoView: View { var body: some View { MarkdownText("- Alpha\n- Beta\n - Nested\n- Gamma") .markdownListStyle(CardListStyle()) } } ``` -------------------------------- ### Custom Heading Appearance with markdownHeadingStyle Source: https://context7.com/shaps80/markdowntext/llms.txt Customizes the appearance of all heading elements (H1-H6) using a style protocol. Styles are injected via the SwiftUI environment. ```swift import SwiftUI import MarkdownText struct ColoredHeadingStyle: HeadingMarkdownStyle { func makeBody(configuration: Configuration) -> some View { configuration.label .foregroundColor(configuration.level == 1 ? .accentColor : .primary) .padding(.bottom, configuration.level == 1 ? 8 : 4) } } struct HeadingDemoView: View { var body: some View { MarkdownText("# Title\n## Subtitle\n### Section") .markdownHeadingStyle(ColoredHeadingStyle()) } } ``` -------------------------------- ### Custom Paragraph Appearance with markdownParagraphStyle Source: https://context7.com/shaps80/markdowntext/llms.txt Customizes the appearance of paragraph blocks using a style protocol. The configuration exposes a label view for the attributed text. ```swift import SwiftUI import MarkdownText struct SpacedParagraphStyle: ParagraphMarkdownStyle { func makeBody(configuration: Configuration) -> some View { configuration.label .lineSpacing(6) .foregroundColor(.secondary) } } struct ParagraphDemoView: View { var body: some View { MarkdownText("First paragraph.\n\nSecond paragraph with more text.") .markdownParagraphStyle(SpacedParagraphStyle()) } } ``` -------------------------------- ### Custom Code Block Style Source: https://context7.com/shaps80/markdowntext/llms.txt Creates a custom style for fenced code blocks, adding padding, a background color, rounded corners, and displaying the language. ```swift import SwiftUI import MarkdownText struct ThemedCodeStyle: CodeMarkdownStyle { func makeBody(configuration: Configuration) -> some View { ScrollView(.horizontal, showsIndicators: false) { configuration.label .padding(12) } .background(Color(.systemGray6)) .cornerRadius(8) .overlay( Group { if let lang = configuration.language { Text(lang.uppercased()) .font(.caption2.monospaced()) .foregroundColor(.secondary) .padding(4) } }, alignment: .topTrailing ) } } // Built-in shorthand for default scrollable style: // .markdownCodeStyle(.default(.horizontal, showsIndicators: true)) struct CodeDemoView: View { var body: some View { MarkdownText("```swift\nlet answer = 42\nprint(answer)\n```") .markdownCodeStyle(ThemedCodeStyle()) } } ``` -------------------------------- ### markdownInlineLinkStyle(_:) Source: https://context7.com/shaps80/markdowntext/llms.txt Customizes the visual appearance of inline links like `[link](url)`. Links are rendered as display-only and non-interactive. ```APIDOC ## markdownInlineLinkStyle(_:) ### Description Customizes the visual appearance of `[link](url)` inline text. Links are **non-interactive** (display only). Returns `Text`. ### Method `markdownInlineLinkStyle(_:)` ### Parameters - `style`: An object conforming to `InlineLinkMarkdownStyle` that defines the appearance. ### Request Example ```swift import SwiftUI import MarkdownText struct UnderlinedLinkStyle: InlineLinkMarkdownStyle { func makeBody(configuration: Configuration) -> Text { configuration.content .foregroundColor(.blue) .underline(true, color: .blue) } } MarkdownText("Visit [Swift.org](https://swift.org) for more info.") .markdownInlineLinkStyle(UnderlinedLinkStyle()) ``` ``` -------------------------------- ### Add MarkdownText Dependency to Package.swift Source: https://context7.com/shaps80/markdowntext/llms.txt Add MarkdownText as a dependency in your Swift Package Manager configuration. ```swift // Package.swift dependencies: [ .package( url: "https://github.com/shaps80/MarkdownText.git", .upToNextMinor(from: "1.0.0") ) ], targets: [ .target(name: "MyApp", dependencies: ["MarkdownText"]) ] ``` -------------------------------- ### Apply Markdown Styling and Visibility Modifiers Source: https://github.com/shaps80/markdowntext/blob/main/README.md Apply various markdown styling and visibility modifiers to a MarkdownText view within a SwiftUI hierarchy. These modifiers can be chained and applied globally. ```swift NavigationView { MarkdownText(markdown) } // Styling .markdownQuoteStyle(.inset) .markdownOrderedListBulletStyle(.tinted) .markdownImageStyle(.animated) // Visibility .markdownCode(.visible) .markdownThematicBreak(.hidden) ``` -------------------------------- ### markdownThematicBreakStyle(_:) Source: https://context7.com/shaps80/markdowntext/llms.txt Customizes the rendering of thematic breaks (horizontal rules, `---`). The default implementation renders a SwiftUI `Divider`. ```APIDOC ## markdownThematicBreakStyle(_:) ### Description Customizes the rendering of `---` horizontal rules. The default renders a SwiftUI `Divider`. ### Method `markdownThematicBreakStyle(_:)` ### Parameters - `style`: An object conforming to `ThematicBreakMarkdownStyle` that defines the appearance. ### Request Example ```swift import SwiftUI import MarkdownText struct DottedBreakStyle: ThematicBreakMarkdownStyle { func makeBody(configuration: Configuration) -> some View { HStack { ForEach(0..<20, id: \.self) { Circle() .fill(Color.secondary.opacity(0.4)) .frame(width: 4, height: 4) } } .frame(maxWidth: .infinity) .padding(.vertical, 4) } } MarkdownText("Above the break\n\n---\n\nBelow the break") .markdownThematicBreakStyle(DottedBreakStyle()) ``` ``` -------------------------------- ### LazyMarkdownText for Performance Source: https://github.com/shaps80/markdowntext/blob/main/README.md Utilize LazyMarkdownText for rendering large amounts of Markdown text to improve scrolling and loading performance. Views are loaded lazily. ```swift LazyMarkdownText(someMassiveMarkdownText) ``` -------------------------------- ### Lazy Markdown Rendering with LazyMarkdownText Source: https://context7.com/shaps80/markdowntext/llms.txt Uses LazyVStack for performance-sensitive use cases, rendering elements as they scroll into view. Requires iOS 14+. ```swift import SwiftUI import MarkdownText struct LargeDocumentView: View { let massiveMarkdown: String // e.g. a 500-section document var body: some View { ScrollView { LazyMarkdownText(massiveMarkdown, paragraphSpacing: 20) .padding(.horizontal) } } } ``` -------------------------------- ### Customize Inline Link Style Source: https://context7.com/shaps80/markdowntext/llms.txt Applies a custom style to inline links within MarkdownText. Links are non-interactive and only for display. ```swift import SwiftUI import MarkdownText struct UnderlinedLinkStyle: InlineLinkMarkdownStyle { func makeBody(configuration: Configuration) -> Text { configuration.content .foregroundColor(.blue) .underline(true, color: .blue) } } struct LinkDemoView: View { var body: some View { MarkdownText("Visit [Swift.org](https://swift.org) for more info.") .markdownInlineLinkStyle(UnderlinedLinkStyle()) } } ``` -------------------------------- ### Custom Unordered List Bullet Style Source: https://context7.com/shaps80/markdowntext/llms.txt Replaces default unordered list bullets with a custom chevron icon. ```swift import SwiftUI import MarkdownText struct ChevronBulletStyle: UnorderedListBulletMarkdownStyle { func makeBody(configuration: Configuration) -> some View { Image(systemName: "chevron.right") .font(.caption.weight(.bold)) .foregroundColor(.accentColor) .frame(minWidth: 25) } } struct UnorderedBulletDemoView: View { var body: some View { MarkdownText("- First\n- Second\n - Nested") .markdownUnorderedListBulletStyle(ChevronBulletStyle()) } } ``` -------------------------------- ### Control Markdown Element Visibility Source: https://context7.com/shaps80/markdowntext/llms.txt Hides specific Markdown block elements like headings, quotes, and code blocks using visibility modifiers. Use `.hidden` to conceal elements. ```swift import SwiftUI import MarkdownText struct FilteredMarkdownView: View { let markdown = """ # Heading (hidden) Paragraph visible. > Quote hidden. ``` Code hidden. ``` - List visible - Another item - [x] Checklist hidden """ var body: some View { ScrollView { MarkdownText(markdown) // Hide specific block types .markdownHeading(.hidden) .markdownQuote(.hidden) .markdownCode(.hidden) // Hide checklist bullets but keep item text .markdownCheckListItemBullet(.hidden) // Hide unordered list item bullets only // .markdownList(.hidden) // hides entire list .padding() } } } ``` -------------------------------- ### Custom Block Quote Style Source: https://context7.com/shaps80/markdowntext/llms.txt Defines a custom style for block quotes by adding leading padding and a colored vertical bar. ```swift import SwiftUI import MarkdownText struct InsetQuoteStyle: QuoteMarkdownStyle { func makeBody(configuration: Configuration) -> some View { configuration.label .padding(.leading, 12) .overlay( Rectangle() .frame(width: 3) .foregroundColor(.accentColor), alignment: .leading ) .padding(.vertical, 4) } } struct QuoteDemoView: View { var body: some View { MarkdownText("> The quick brown fox jumps over the lazy dog.") .markdownQuoteStyle(InsetQuoteStyle()) } } ``` -------------------------------- ### Customize Thematic Break Style Source: https://context7.com/shaps80/markdowntext/llms.txt Renders thematic breaks (horizontal rules) with a custom visual style instead of the default divider. ```swift import SwiftUI import MarkdownText struct DottedBreakStyle: ThematicBreakMarkdownStyle { func makeBody(configuration: Configuration) -> some View { HStack { ForEach(0..<20, id: \.self) { Circle() .fill(Color.secondary.opacity(0.4)) .frame(width: 4, height: 4) } } .frame(maxWidth: .infinity) .padding(.vertical, 4) } } struct ThematicDemoView: View { var body: some View { MarkdownText("Above the break\n\n---\n\nBelow the break") .markdownThematicBreakStyle(DottedBreakStyle()) } } ``` -------------------------------- ### Visibility Modifiers Source: https://context7.com/shaps80/markdowntext/llms.txt Controls the visibility of various Markdown block and sub-element types using `.automatic` or `.hidden` values. ```APIDOC ## Visibility Modifiers ### Description All block and sub-element types can be toggled visible or hidden using `.automatic` / `.hidden` visibility values from `SwiftUIBackports`. Modifiers can be placed anywhere in the view hierarchy. ### Available Modifiers | Modifier | |---| | `.markdownHeading(_:)` | | `.markdownQuote(_:)` | | `.markdownCode(_:)` | | `.markdownImage(_:)` | | `.markdownList(_:)` | | `.markdownThematicBreak(_:)` | | `.markdownCheckListItem(_:)` | | `.markdownCheckListItemBullet(_:)` | ### Request Example ```swift import SwiftUI import MarkdownText struct FilteredMarkdownView: View { let markdown = """ # Heading (hidden) Paragraph visible. > Quote hidden. ``` Code hidden. ``` - List visible - Another item - [x] Checklist hidden """ var body: some View { ScrollView { MarkdownText(markdown) // Hide specific block types .markdownHeading(.hidden) .markdownQuote(.hidden) .markdownCode(.hidden) // Hide checklist bullets but keep item text .markdownCheckListItemBullet(.hidden) .padding() } } } ``` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.