text-markup: A data structure for mapping metadata to text subsequences

[ bsd3, library, text ] [ Propose Tags ]




Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees


  • No Candidates
Versions [RSS] 0.1
Change log CHANGELOG.md
Dependencies base (>=4.8 && <5.0), containers, text [details]
License BSD-3-Clause
Copyright (c) 2016 Jonathan Daugherty
Author Jonathan Daugherty
Maintainer cygnus@foobox.com
Category Text
Home page https://github.com/jtdaugherty/text-markup/
Bug tracker https://github.com/jtdaugherty/text-markup/issues
Source repo head: git clone git://github.com/jtdaugherty/text-markup.git
Uploaded by JonathanDaugherty at 2016-09-05T19:50:30Z
Reverse Dependencies 1 direct, 0 indirect [details]
Downloads 782 total (3 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2016-09-05 [all 1 reports]

Readme for text-markup-0.1

[back to package description]


This library provides a data structure for associating arbitrary metadata ("markup") with subsequences of text. The motivation for this library is to provide a tool for mapping text attributes to text sequences in terminal applications where we may want to perform many such mappings by searching text with regular expressions or using parsers to do syntax highlighting.

The main interface to the library is through three functions:

  • toMarkup - convert a Text into a Markup a,
  • markRegion - mark a region of the Text with a metadata value of type a, and
  • fromMarkup - recover the subsequences of the text with accompanying metadata.

For example,

> let m = toMarkup (T.pack "some@email.com http://google.com/") Nothing
> fromMarkup $ markRegion 27 18 (Just "url")
             $ markRegion 15 11 (Just "ipv4")
             $ markRegion 0 14 (Just "e-mail") m
[ ("some@email.com"    , Just "e-mail")
, (" "                 , Nothing)
, (""       , Just "ipv4")
, (" "                 , Nothing)
, ("http://google.com/", Just "url")

Applying the same markup to adjacent regions results in a merge:

> let m = toMarkup (T.pack "foobar") Nothing
> fromMarkup $ markRegion 0 3 (Just "token") m
[("foo",Just "token"),("bar",Nothing)]
> fromMarkup $ markRegion 3 3 (Just "token")
             $ markRegion 0 3 (Just "token") m
[("foobar",Just "token")]