All Projects → gonzalezreal → Markup

gonzalezreal / Markup

Licence: mit
Lightweight markup text formatting in Swift

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to Markup

Corexlsx
Excel spreadsheet (XLSX) format parser written in pure Swift
Stars: ✭ 481 (+446.59%)
Mutual labels:  parser, tvos
Leanbacktvsample
Leanback Demo
Stars: ✭ 85 (-3.41%)
Mutual labels:  tvos
F90nml
A Python module and command line tool for working with Fortran namelists
Stars: ✭ 79 (-10.23%)
Mutual labels:  parser
Internettools
XPath/XQuery 3.1 interpreter for Pascal with compatibility modes for XPath 2.0/XQuery 1.0/3.0, custom and JSONiq extensions, XML/HTML parsers and classes for HTTP/S requests
Stars: ✭ 82 (-6.82%)
Mutual labels:  parser
Expostal
Elixir binding for Libpostal - a library for parsing/normalizing street addresses around the world. Powered by statistical NLP and open geo data.
Stars: ✭ 80 (-9.09%)
Mutual labels:  parser
Blockchain Parser
The simpliest script for parsing Bitcoin blockchain. It made convertion of blk*****.dat files to the simple text.
Stars: ✭ 84 (-4.55%)
Mutual labels:  parser
Solidity Antlr4
Solidity grammar for ANTLR4
Stars: ✭ 79 (-10.23%)
Mutual labels:  parser
Linereader
Reading a text file line by line aka block wise.
Stars: ✭ 87 (-1.14%)
Mutual labels:  parser
Redrun
✨🐌 🐎✨ fastest npm scripts runner
Stars: ✭ 85 (-3.41%)
Mutual labels:  parser
Hpq
Utility to parse and query HTML into an object shape
Stars: ✭ 82 (-6.82%)
Mutual labels:  parser
Php Mt940
A mt940 parser in PHP
Stars: ✭ 80 (-9.09%)
Mutual labels:  parser
Unmix
Undo the so-called mix lingo, a code-mixing style (Bahasa Jaksel)
Stars: ✭ 81 (-7.95%)
Mutual labels:  parser
Codecharta
CodeCharta visualizes multiple code metrics using 3D tree maps.
Stars: ✭ 85 (-3.41%)
Mutual labels:  parser
Rs Monkey Lang
Monkey Programming Language written in Rust.
Stars: ✭ 80 (-9.09%)
Mutual labels:  parser
Beanbun Parser
beanbun-parser 是 Beanbun 的数据抽取插件。抽取规则的选择器语法类似于 jQuery,使用简单。
Stars: ✭ 86 (-2.27%)
Mutual labels:  parser
Videoparse
这个可能不再维护了,音乐可以参考KMusic
Stars: ✭ 79 (-10.23%)
Mutual labels:  parser
Lodestone Nodejs
Character tracking and parser library for nodejs
Stars: ✭ 81 (-7.95%)
Mutual labels:  parser
Host.swift
*Host.swift is no longer maintained*, please use Hostess.swift: https://github.com/rjstelling/Hostess.swift. A Swift implementation of NSHost that works on iOS, OS X and tvOS. Host.swift is safe to use in a framework because it does not require a bridging header.
Stars: ✭ 83 (-5.68%)
Mutual labels:  tvos
Activityrings
An attempt to recreate the ring controls in Apple’s Activity app
Stars: ✭ 88 (+0%)
Mutual labels:  tvos
Commoncrypto
CommonCrypto Swift module
Stars: ✭ 87 (-1.14%)
Mutual labels:  tvos

Markup

Swift 5.1 Platforms Swift Package Manager Carthage Compatible CocoaPods Twitter: @gonzalezreal

Markup generates attributed strings using a familiar markup syntax:

  • To emphasize words or sentences, you can surround the text with *asterisks* to create bold text or _underscores_ for italic text.
  • To show corrections in the text, surround the text with ~tildes~ to strike out the text.
  • You can combine formatting options.

For example, the following text:

The *quick*, ~red~ brown fox jumps over a _*lazy dog*_.

will be formatted like this:

The quick, red brown fox jumps over a lazy dog.

Just to give you an idea, here is a screenshot of the sample application displaying the markup text and the resulting attributed string:

Screenshot

Examples

Render an attributed string

You can use MarkupRenderer to generate an attributed string from a given markup text:

import Markup

let renderer = MarkupRenderer(baseFont: .systemFont(ofSize: 16))
let attributedText = renderer.render(text: "The *quick*, ~red~ brown fox jumps over a _*lazy dog*_.")

Access the markup syntax tree

Use MarkupParser to generate an abstract syntax tree for a markup text:

let nodes = MarkupParser.parse(text: "The *quick*, ~red~ brown fox jumps over a _*lazy dog*_")
dump(nodes)

// Outputs:
[
  .text("The "),
  .strong([
    .text("quick")
  ]),
  .text(", "),
  .delete([
    .text("red")
  ]),
  .text(" brown fox jumps over a "),
  .emphasis([
    .strong([
       .text("lazy dog")
    ])
  ])
]

Performance

Both the parsing and the rendering will take linear time to complete.

This post explains how Markup internally works, in case you are curious about the implementation.

Installation

Using the Swift Package Manager

Add Markup as a dependency to your Package.swift file. For more information, see the Swift Package Manager documentation.

.package(url: "https://github.com/gonzalezreal/Markup", from: "2.3.0")

Using Carthage

Add github "gonzalezreal/Markup" to your Cartfile

Using CocoaPods

Add pod Markup to your Podfile

Help & Feedback

  • Open an issue if you need help, if you found a bug, or if you want to discuss a feature request.
  • Open a PR if you want to make some change to Markup.
  • Contact @gonzalezreal on Twitter.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].