• This repository has been archived on 08/Mar/2019
  • Stars
    star
    103
  • Rank 333,046 (Top 7 %)
  • Language Mercury
  • License
    Apache License 2.0
  • Created over 10 years ago
  • Updated over 8 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A Markdown NSAttributedString parser.

XNGMarkdownParser - A Markdown NSAttributedString Parser

Build Status Coverage Status Dependency Status CocoaPods Version CocoaPods License CocoaPods Platform

This is a Markdown => NSAttributedString parser built on top of a flex parser. It takes an NSString and returns an NSAttributedString with markdown tags replaced by CoreText formatting attributes.

This project is a fork of NSAttributedMarkdownParser by NimbusKit: https://github.com/NimbusKit/markdown

Adding it to your Project

Using cocoapods

Add pod 'XNGMarkdownParser' to your Podfile and do a pod install.

Manual

  1. Drag all of the files from the src/ directory into your project.
  2. Import XNGMarkdownParser.h in your project.
  3. Create an instance of the parser object and pass it the string you wish to parse.
  4. Plug the resulting NSAttributedString into your favorite NSAttributedString label implementation (like an UITextView)

Supported Features

*italics*
**bold**
***bold italic***
~~strikethrough~~

# Header 1
## Header 2
### Header 3
#### Header 4
##### Header 5
###### Header 6

Header 1
========

Header 2
--------

http://google.com urls
[Text] (http://google.com "alt text") urls
[email protected]

Extended Features

  • UTF-8 support
  • Vastly improved speed
  • Extended formatting for paragraphs
  • Support different link fonts
  • Tests and example project
  • Support for CocoaPods

Examples

###Simplest example

XNGMarkdownParser *parser = [[XNGMarkdownParser alloc] init];
NSAttributedString *string = [parser attributedStringFromMarkdownString:@"This is __rad__."];

Further text customization

// this parser initializes only once and customizes fonts, line height and link color
+ (XNGMarkdownParser *)titleMarkdownParser {
    static dispatch_once_t onceToken;
    static XNGMarkdownParser *parser;
    dispatch_once(&onceToken, ^{
        parser = [[XNGMarkdownParser alloc] init];

        parser.paragraphFont = [UIFont xng_14Font];
        parser.boldFontName = [UIFont xng_14Font].fontName;
        parser.linkFontName = [UIFont xng_14Font].fontName;

        const CGFloat lineHeight = 18;
        NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
        paragraphStyle.minimumLineHeight = lineHeight;
        parser.topAttributes = @{
            NSParagraphStyleAttributeName: paragraphStyle,
            NSForegroundColorAttributeName: self.textColor
        };
    });

    return parser;
}

See the included Example project and the tests to check for further options.

Want to collaborate?

If you would like to collaborate with the project by adding features or fixing bugs, you can do it like this:

  • If you need to change the grammar we use to parse Markdown test, you have to change the Lex file grammar/markdown.grammar, used to generate the lexical analizer. If you need to add new tokens, you will need to add them to the files XNGMarkdownTokens.h and XNGMarkdownTokens.cpp, in order to be able to execute actions later when they are detected.
  • If you change the grammar, you need to run the script generate.sh to generate the code for the lexical analyzer.
  • In order to convert the detected text to an NSAttributedString, you will need to perform changes in the file src/XNGMarkdownParser.m, more concisely in the method -consumeToken:text:.

After you have fixed a bug or added a feature, please check the tests and extend them if needed, and you will be ready to create a pull request. Thanks!

More Repositories

1

hops

Universal Development Environment
JavaScript
168
star
2

beetle

High Availability AMQP Messaging With Redundant Queues
Ruby
161
star
3

kubernetes-oom-event-generator

Generate a Kubernetes Event when a Pod's container has been OOMKilled
Go
161
star
4

rails_cursor_pagination

Add cursor pagination to your ActiveRecord backed application
Ruby
112
star
5

kubernetes-deployment-restart-controller

Kubernetes controller that restarts Deployments when referenced ConfigMaps or Secrets change.
Go
100
star
6

paperclip-storage-ftp

Allow Paperclip attachments to be stored on FTP servers
Ruby
53
star
7

mango

A fastlane plugin that lets you execute tasks in a managed docker container
Ruby
51
star
8

XNGPodsSynchronizer

Mirrors the CocoaPods you need to GitHub Enterprise
Ruby
40
star
9

kubernetes-event-forwarder-gelf

Forward Kubernetes Events using the Graylog Extended Log Format
Go
36
star
10

xing-android-sdk

The Official XING API client for Java/Android
Java
34
star
11

racktables_api

REST access to racktables objects
Ruby
33
star
12

calabash-launcher

iOS Calabash Launcher is a macOS app that helps you run and manage Calabash tests on your Mac.
Swift
30
star
13

XNGMacBuildNodeSetup

These are the ansible playbooks we use to configure our Mac machines for usage with Jenkins CI.
Shell
25
star
14

xing-api-samples

Code samples to get started with the XING API
HTML
24
star
15

pandan

Retrieve Xcode dependency information with ease
Ruby
24
star
16

jungle

Complexity metrics for Cocoapods and SwiftPM
Swift
21
star
17

cloudinit-vmware-guestinfo

Python
19
star
18

xing_api

Offical ruby client for the XING-API, providing easy access to all API endpoints and simplifies response parsing, error handling and tries to ease the oauth pain.
Ruby
19
star
19

selector-specificity

Mean selector specificity of a CSS style sheet
Ruby
18
star
20

fpm-fry

deep-fried package builder
Ruby
18
star
21

jira-bookmarklets

A collection of bookmarklets that helps you to print your JIRA tickets
JavaScript
16
star
22

vpim

a clone of the vpim project on rubyforge (patched geolocation support)
Ruby
16
star
23

israkel

Collection of common rake tasks for the iPhone Simulator.
Ruby
15
star
24

oembed_provider_engine

Mountable engine to turn your Rails 3 app into an oembed provider
Ruby
14
star
25

recrep

Generate crash reports with ease 👌
Rust
13
star
26

passenger-prometheus-exporter-app

Passenger application that exports Passenger metrics in a Prometheus format
HTML
11
star
27

mire

A Ruby method usage analyzer
Ruby
10
star
28

pdf_cover

Generate PDF cover images with Paperclip and Carrierwave
Ruby
8
star
29

cross-application-csrf-prevention

Cross-site request forgery prevention done right
8
star
30

jQuery.autocompletr

A new, better and more extensible jQuery plugin for autocompletion and (ajax) suggesting
JavaScript
8
star
31

perl-beetle

High availability AMQP messaging with redundant queues
Perl
8
star
32

UnifiedActionHandling

A sample project for the CocoaHeads HH presentation in January 2018. It shows our approach to handle actions like cell and button taps in a unified way.
Swift
8
star
33

amiando

Amiando Api Ruby implementation
Ruby
8
star
34

rbenv-patchsets

A collection of definitions for ruby-build to install rubies patched from https://github.com/skaes/rvm-patchsets for rbenv
Ruby
7
star
35

slouch

Backbone Scaffolding
Ruby
7
star
36

canarist

TypeScript
7
star
37

gem_version_check

Check gem dependencies of ruby apps and generate report
Ruby
7
star
38

java-beetle

Java version of the Beetle client library
Java
6
star
39

curl-useragent

UserAgent based on libcurl
Perl
6
star
40

rlsr

create npm releses and changelogs from a mono repo
TypeScript
5
star
41

test-spec-script

A script that converts tests from test/spec to Rails 2.3+ standard test syntax
4
star
42

elixir_logjam_agent

Logjam agent implementation for Elixir / Phoenix
Elixir
3
star
43

gearman-server

Gearman C Server
C
3
star
44

XNGOAuth1Client

Objective-C
3
star
45

logjam-agent-go

Golang logjam agent
Go
3
star
46

game_of_life_web

Web visualisation for Game of Life
Elixir
2
star
47

scratcher

Backbone lightweight framework giving simple structure to make life a little easier
JavaScript
2
star
48

XNGAPIClientTester

The client tester for the XINGAPIClient
Objective-C
2
star
49

cookiebara

session access for capybara
Ruby
2
star
50

xing_ad_tracker

Official XNGAdTracker plugin for iOS/Android
Kotlin
2
star
51

actionlint

Actionlint as wasm
JavaScript
1
star
52

rbenv-mygemfile

Tiny rbenv plugin which sets `BUNDLE_GEMFILE` to `Mygemfile` if file exists
Shell
1
star
53

unified_csrf_prevention

Self-healing, stateless and programming language agnostic CSRF prevention library for Rails
Ruby
1
star
54

msteams_hermes

Send messages to any Microsoft Teams' channel as easy as possible
Ruby
1
star
55

icu4r

Ruby Bindings for icu4c (derived from an installed version of icu4r)
C
1
star
56

btn

Bitrise Teams Notifier - Send out messages to MS Teams if Bitrise builds failed, succeeded, were aborted.
Ruby
1
star