Skip to main content

Markup terms in text

Project description

.

Turn your text into hypertext. With anchorman you can markup anything, create anchors, links, annotate abbreviations or just highlight specific areas.

.

Example

>>> import anchorman
>>> text = "The quick brown fox jumps over the lazy dog."
>>> links = [{'fox': {'value': '/wiki/fox'}},
             {'dog': {'value': '/wiki/dog'}}]
>>> a = anchorman.add(text, links)
>>> print a
The quick brown <a href="/wiki/fox" class="anchorman">fox</a> jumps over
the lazy <a href="/wiki/dog" class="anchorman">dog</a>.

See more examples section at bottom.

.

Installation

Install anchorman via pip

pip install anchorman

or from source code

git clone https://github.com/tarnacious/anchorman.git && cd anchorman
python setup.py install

test it in a virtual environment

virtualenv .
./bin/pip install -r requirements.txt
./bin/py.test test

.

More examples

Links with specific attributes Define general attribute value pairs on markup_format level and more specific attributes at the level of each link element.

>>> markup_format = {
        'tag': 'a',
        'value_key': 'href',
        'attributes': [
            ('style', 'color:blue;cursor:pointer;'),
            ('class', 'anchorman')
        ]
     }
>>> links = [{
        'red fox': {
            'value': '/redfox',
            'attributes': [
                ('class', 'animal'),
                ('style', 'font-size:23px;background:red'),
                ('title', 'Fix und Foxi')
            ]
        }
    }]
>>> a = anchorman.add(text, links, markup_format=markup_format)
The quick brown fox jumps over the lazy dog while the <a href="/redfox"
style="color:blue;cursor:pointer; font-size:23px;background:red"
class="anchorman animal" title="Fix und Foxi">red fox</a> sleeps.

.

Highlighting context Highlighting a term with pre- and postfix, e.g. variables in templates or low level tags.

>>> links = [{'fox': {}}]
>>> markup_format = {
        'highlighting': {
            'pre': '${{',
            'post': '}}'
        }
    }
>>> a = anchorman.add(text, links, markup_format=markup_format)
>>> print a
The quick brown ${{fox}} jumps over the lazy dog while the red
${{fox}} sleeps.

.

Parameters

markup_format: tag, value attribute or highlighting with pre- and postfix

replaces_per_item: default is replace all occurences, otherwise int

case-sensitive: default is True, set False to replace: Fox, fox and FOX

rm-identifier: create a specific identifier per set to delete them later on

.

.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

anchorman-0.0.2.tar.gz (7.6 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page