### Use default Markdown reader Source: https://context7.com/loopwerk/sagaparsleymarkdownreader/llms.txt Initialize the default reader with standard options including unsafe HTML, hard breaks, and smart quotes. ```swift import Saga import SagaParsleyMarkdownReader // Use the default reader with standard options let reader = Reader.parsleyMarkdownReader // Process a markdown file let result = try await reader.convert(Path("content/blog/my-post.md")) // Access parsed content print(result.title) // "My Blog Post" (from first H1 or frontmatter) print(result.body) // "
HTML content...
" print(result.frontmatter) // ["date": "2025-06-23", "tags": "swift, web"] ``` -------------------------------- ### Configure custom Markdown reader Source: https://context7.com/loopwerk/sagaparsleymarkdownreader/llms.txt Create a reader with specific parsing options and syntax extensions for fine-grained control. ```swift import Parsley import Saga import SagaParsleyMarkdownReader // Create reader with safe mode (no raw HTML) and no extensions let safeReader = Reader.parsleyMarkdownReader( markdownOptions: [.safe], syntaxExtensions: [] ) // Create reader with hard breaks for poetry/formatted text let poetryReader = Reader.parsleyMarkdownReader( markdownOptions: [.hardBreaks], syntaxExtensions: [] ) // Create reader with smart quotes for typography let typographyReader = Reader.parsleyMarkdownReader( markdownOptions: [.smartQuotes], syntaxExtensions: [] ) // Create reader with all options for full-featured parsing let fullReader = Reader.parsleyMarkdownReader( markdownOptions: [.unsafe, .hardBreaks, .smartQuotes], syntaxExtensions: SyntaxExtension.defaultExtensions ) // Process content with custom reader let result = try await safeReader.convert(Path("content/article.md")) ``` -------------------------------- ### Configure Package.swift dependencies Source: https://context7.com/loopwerk/sagaparsleymarkdownreader/llms.txt Add the package to your Swift project dependencies and target configuration. ```swift // Package.swift import PackageDescription let package = Package( name: "MyWebsite", platforms: [ .macOS(.v14), ], dependencies: [ .package(url: "https://github.com/loopwerk/Saga", from: "2.0.3"), .package(url: "https://github.com/loopwerk/SagaParsleyMarkdownReader", from: "0.5.0"), ], targets: [ .target( name: "MyWebsite", dependencies: ["Saga", "SagaParsleyMarkdownReader"] ), ] ) ``` -------------------------------- ### Handle Errors in Swift Source: https://context7.com/loopwerk/sagaparsleymarkdownreader/llms.txt Wraps the conversion process in a do-catch block to manage file access or parsing failures. ```swift import Saga import SagaParsleyMarkdownReader let reader = Reader.parsleyMarkdownReader do { let result = try await reader.convert(Path("/tmp/nonexistent-file.md")) print(result.body) } catch { // Handle file not found or parsing errors print("Error processing markdown: \(error)") } ``` -------------------------------- ### Configure Hard Breaks in Swift Source: https://context7.com/loopwerk/sagaparsleymarkdownreader/llms.txt Enables the .hardBreaks option to convert source line breaks intoLine one
\nLine two
\nLine three
Line one\nLine two\nLine three
" ``` -------------------------------- ### Parse Frontmatter-Only Files with Swift Source: https://context7.com/loopwerk/sagaparsleymarkdownreader/llms.txt Handles files containing only YAML frontmatter, useful for configuration or data-only files. ```swift import Saga import SagaParsleyMarkdownReader // Example markdown file: content/metadata.md // --- // title: Only Frontmatter // author: Test Author // --- let reader = Reader.parsleyMarkdownReader let result = try await reader.convert(Path("content/metadata.md")) print(result.title) // nil (no H1 in content) print(result.body.isEmpty) // true print(result.frontmatter?[\"title\"]) // "Only Frontmatter" print(result.frontmatter?[\"author\"]) // "Test Author" ``` -------------------------------- ### Integrate with Saga Pipeline in Swift Source: https://context7.com/loopwerk/sagaparsleymarkdownreader/llms.txt Registers the reader within a Saga site generator pipeline to process specific folders. ```swift import Saga import SagaParsleyMarkdownReader import HTML struct ArticleMetadata: Metadata { let title: String let date: Date let tags: [String] let summary: String } @main struct MyWebsite { static func main() async throws { try await Saga(input: "content", output: "deploy") // Register markdown files with the Parsley reader .register( folder: "articles", metadata: ArticleMetadata.self, readers: [.parsleyMarkdownReader], writers: [ .listWriter(template: articlesTemplate), .itemWriter(template: articleTemplate) ] ) .run() } } ``` -------------------------------- ### Define BlogPost Structure in Swift Source: https://github.com/loopwerk/sagaparsleymarkdownreader/blob/main/Tests/SagaParsleyMarkdownReaderTests/test-content.md Defines a Swift struct to represent a blog post, including its title, content, and tags. Useful for data modeling in Swift applications. ```swift struct BlogPost { let title: String let content: String let tags: [String] } ``` -------------------------------- ### Reader.parsleyMarkdownReader(markdownOptions:syntaxExtensions:) Source: https://context7.com/loopwerk/sagaparsleymarkdownreader/llms.txt Creates a customized Markdown reader allowing fine-grained control over parsing behavior and syntax extensions. ```APIDOC ## Reader.parsleyMarkdownReader(markdownOptions:syntaxExtensions:) ### Description Creates a customized Markdown reader with specific parsing options and syntax extensions. ### Parameters - **markdownOptions** (Array) - Optional - A list of Parsley Markdown options (e.g., .safe, .unsafe, .hardBreaks, .smartQuotes). - **syntaxExtensions** (Array) - Optional - A list of syntax extensions to enable (e.g., SyntaxExtension.defaultExtensions). ### Usage ```swift let customReader = Reader.parsleyMarkdownReader( markdownOptions: [.safe], syntaxExtensions: [] ) let result = try await customReader.convert(Path("content/article.md")) ``` ``` -------------------------------- ### Parse Content-Only Markdown with Swift Source: https://context7.com/loopwerk/sagaparsleymarkdownreader/llms.txt Extracts the title from the first H1 heading and returns an empty frontmatter dictionary when no frontmatter is present. ```swift import Saga import SagaParsleyMarkdownReader // Example markdown file: content/simple.md // # Simple Title // // Just some **bold** text and a [link](https://example.com). let reader = Reader.parsleyMarkdownReader let result = try await reader.convert(Path("content/simple.md")) // Title extracted from first H1 heading print(result.title) // "Simple Title" print(result.frontmatter) // [:] (empty dictionary) print(result.body) // "Just some bold text and a link.
" ``` -------------------------------- ### Add SagaParsleyMarkdownReader dependency in Package.swift Source: https://github.com/loopwerk/sagaparsleymarkdownreader/blob/main/README.md Include the package in the dependencies and target dependencies of your Swift package manifest. ```swift let package = Package( name: "MyWebsite", dependencies: [ .package(url: "https://github.com/loopwerk/Saga", from: "1.0.0"), .package(url: "https://github.com/loopwerk/SagaParsleyMarkdownReader", from: "0.5.0"), ], targets: [ .target( name: "MyWebsite", dependencies: ["Saga", "SagaParsleyMarkdownReader"]), ] ) ``` -------------------------------- ### Parse Markdown with YAML frontmatter Source: https://context7.com/loopwerk/sagaparsleymarkdownreader/llms.txt Extract metadata from YAML frontmatter and access the converted HTML body content. ```swift import Saga import SagaParsleyMarkdownReader // Example markdown file: content/blog/test-article.md // --- // title: Test Article // date: 2025-06-23 // tags: swift, markdown, testing // summary: This is a test article for unit testing // published: true // --- // # Test Article // // This document tests multiple markdown features together. // // ## Introduction // // Here's some **bold** and *italic* text with `inline code`. let reader = Reader.parsleyMarkdownReader let result = try await reader.convert(Path("content/blog/test-article.md")) // Access frontmatter metadata let frontmatter = result.frontmatter! print(frontmatter["title"]) // "Test Article" print(frontmatter["date"]) // "2025-06-23" print(frontmatter["tags"]) // "swift, markdown, testing" print(frontmatter["summary"]) // "This is a test article for unit testing" print(frontmatter["published"]) // "true" // Access parsed HTML body print(result.body.contains("inline code")) // true
```
--------------------------------
### Enable Smart Quotes in Swift
Source: https://context7.com/loopwerk/sagaparsleymarkdownreader/llms.txt
Uses the .smartQuotes option to automatically convert straight quotes into typographic curly quotes.
```swift
import Parsley
import Saga
import SagaParsleyMarkdownReader
// Example markdown file: content/quotes.md
// "Hello world" and 'single quotes'
let readerWithSmartQuotes = Reader.parsleyMarkdownReader(
markdownOptions: [.smartQuotes],
syntaxExtensions: []
)
let result = try await readerWithSmartQuotes.convert(Path("content/quotes.md"))
// Smart quotes convert " to " " and ' to ' '
print(result.body)
// ""Hello world" and 'single quotes'
" ``` -------------------------------- ### Reader.parsleyMarkdownReader Source: https://context7.com/loopwerk/sagaparsleymarkdownreader/llms.txt The default Markdown reader configured with standard options including .unsafe, .hardBreaks, and .smartQuotes, along with default syntax extensions. ```APIDOC ## Reader.parsleyMarkdownReader ### Description Provides a pre-configured reader instance for processing .md and .markdown files with standard Markdown features enabled. ### Method Static Property ### Usage ```swift let reader = Reader.parsleyMarkdownReader let result = try await reader.convert(Path("content/blog/my-post.md")) ``` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.