Welcome to the documentation of Highlightr, a powerful code syntax highlighter for iOS.
Table of Contents
Installation
Highlightr can be installed using CocoaPods or manually.
Using CocoaPods
To install Highlightr via CocoaPods, add the following line to your Podfile:
pod 'Highlightr'
Then run the following command:
pod install
Manual Installation
To manually install Highlightr, simply download the source code from the GitHub repository and add the Highlightr folder to your Xcode project.
Basic Usage
To use Highlightr in your project, follow these steps:
- Create an instance of `Highlightr`:
- Load the desired syntax theme:
- Highlight the code:
- Render the highlighted code:
let highlightr = Highlightr()
highlightr.setTheme(to: "xcode")
let highlightedCode = highlightr.highlight(code, as: language)
textView.attributedText = highlightedCode
Advanced Usage
Highlightr provides several advanced features to enhance your code syntax highlighting:
- Line Numbers: You can enable line numbers in the highlighted code.
- Line Highlighting: You can highlight specific lines in the code.
- Theme Customization: You can customize the theme colors to match your app’s design.
- Supported Languages: Highlightr supports a wide range of programming languages.
Customization
You can customize the appearance of highlighted code by changing the theme or modifying individual theme colors.
Changing the Theme
To change the theme, simply use the `setTheme(to:)` method:
highlightr.setTheme(to: "monokai-sublime")
Modifying Theme Colors
You can modify individual theme colors using the `setThemeColor(_:to:)` method:
highlightr.setThemeColor(.background, to: UIColor.black)
Troubleshooting
If you encounter any issues while using Highlightr, please refer to the following:
- Issue #1: The code is not highlighted correctly.
- Issue #2: The line numbers are not displayed.
Solution: Ensure that you have set the correct language and theme for the code you want to highlight.
Solution: Enable line numbers using the appropriate method provided by Highlightr.
Contributing
If you would like to contribute to the development of Highlightr, please follow the guidelines outlined in the CONTRIBUTING.md file in the GitHub repository.
License
Highlightr is released under the MIT License. See the LICENSE file for more details.