swiftcommonmark


## Introduction


Welcome to the documentation for the **SwiftCommonMark** framework! Here, you’ll find detailed information about this powerful library and how to make the most of its features.


## What is SwiftCommonMark?


SwiftCommonMark is a Swift package that enables you to parse and render Markdown using the CommonMark specification. It provides a convenient and efficient way to work with Markdown documents in your Swift projects.


## Features


– **Markdown Parsing**: SwiftCommonMark allows you to parse Markdown documents into an abstract syntax tree (AST), making it easy to extract and manipulate the document’s elements.
– **Markdown Rendering**: Render Markdown documents into HTML, allowing you to display them in your app or website.
– **Customization**: SwiftCommonMark provides various customization options, enabling you to control the rendering output and behavior according to your specific requirements.
– **Performance**: SwiftCommonMark is designed to be fast and efficient, ensuring smooth performance even when working with large Markdown documents.


## Installation


To start using SwiftCommonMark in your project, follow these installation steps:


### Requirements


– Swift 5.1 or later
– macOS 10.14 or later
– iOS 13.0 or later
– tvOS 13.0 or later
– watchOS 6.0 or later


### Package Manager


To incorporate SwiftCommonMark into your project using Swift Package Manager, follow these steps:

1. Open your project in Xcode.
2. Navigate to **File** > **Swift Packages** > **Add Package Dependency**.
3. Enter the URL of the SwiftCommonMark repository: `https://github.com/CommonMark/SwiftCommonMark.git`.
4. Select the appropriate rules for adding the package, depending on your requirements.
5. Click **Finish** to initiate the package resolution and incorporation process.


## Usage


Once you have successfully integrated SwiftCommonMark into your project, you can start using its features. Below, we provide examples demonstrating some of the key functionalities:


### Parsing Markdown


To parse a Markdown document into an abstract syntax tree (AST), you can use the following code:


“`swift
import SwiftCommonMark

let markdown = “””
# Hello, Markdown!

This is a sample paragraph in Markdown.
“””

if let ast = try CommonMarkParser().parse(document: markdown) {
// Handle the parsed AST
}
“`


### Rendering Markdown


To render a Markdown document into HTML, you can utilize the following code snippet:


“`swift
import SwiftCommonMark

let markdown = “””
# Hello, Markdown!

This is a sample paragraph in Markdown.
“””

let html = try CommonMarkRenderer().render(document: markdown)

// Use or display the HTML as desired
“`


## Customization


SwiftCommonMark provides various customization options to tailor the Markdown rendering according to your preferences. You can control aspects such as heading style, link behavior, list bullet types, etc. For detailed customization instructions, please refer to the [SwiftCommonMark GitHub repository](https://github.com/CommonMark/SwiftCommonMark).


## Additional Resources


For additional information on using SwiftCommonMark, refer to the following resources:

– Official Documentation: [https://github.com/CommonMark/SwiftCommonMark](https://github.com/CommonMark/SwiftCommonMark)
– CommonMark Specification: [https://commonmark.org/](https://commonmark.org/)
– Swift Package Index: [https://swiftpackageindex.com/CommonMark/SwiftCommonMark](https://swiftpackageindex.com/CommonMark/SwiftCommonMark)


## Conclusion


With SwiftCommonMark, parsing and rendering Markdown becomes straightforward and efficient. Whether you need to parse Markdown documents or convert them into HTML, SwiftCommonMark has you covered. The customizable options further enhance your control over the rendering output. Start using SwiftCommonMark today and take advantage of its powerful capabilities!