A data structure for mapping metadata to text subsequences https://github.com/jtdaugherty/text-markup/

Latest on Hackage:0.1

This package is not currently in any snapshots. If you're interested in using it, we recommend adding it to Stackage Nightly. Doing so will make builds more reliable, and allow stackage.org to host generated Haddocks.

BSD3 licensed by Jonathan Daugherty
Maintained by cygnus@foobox.com


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")]



Initial release

Depends on 3 packages:
Used by 1 package:
comments powered byDisqus