{ "info": { "author": "Alec Perkins", "author_email": "alec@marquee.by", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", "License :: Public Domain", "Programming Language :: Python :: 2", "Programming Language :: Python :: 3", "Programming Language :: Python :: Implementation :: CPython", "Programming Language :: Python :: Implementation :: PyPy", "Topic :: Internet :: WWW/HTTP :: Dynamic Content", "Topic :: Text Processing :: Markup :: HTML" ], "description": "# NOAT: Non-Overlapping Annotation Tagging\n\nNOAT (\"note\") is a helper class for inserting reference-based annotations as\nHTML tags at arbitary points in text, based on their start and end positions,\nwhile avoiding overlapping open and close tags of different type (invalid HTML).\nThis ensures creating a well-formed HTML document that will yield a properly\nstructured DOM.\n\nThe text is broken into segments, bounded by the start and end points of all of\nthe annotations. It is then reassembled, with opening and closing tags for\nannotations inserted between the segments. Tags are closed and reopened as\nneeded to prevent overlap.\n\nFor example, given:\n\n```python\ntext = \"Duis mollis, est non commodo luctus, nisi erat porttitor ligula, eget lacinia odio sem nec elit.\"\n\nannotations = [{\n 'type': 'emphasis',\n 'start': 5,\n 'end': 30,\n},{\n 'type': 'strong',\n 'start': 20,\n 'end': 50,\n}]\n```\n\nSimply inserting the tags at the given `start` and `end` positions would result\nin invalid HTML:\n\n```html\nDuis mollis, est non commodo luctus, nisi erat por\nttitor ligula, eget lacinia odio sem nec elit.\n```\n\nThe correct output is:\n\n```html\nDuis mollis, est non commodo l uctus, nisi\nerat porttitor ligula, eget lacinia odio sem nec elit.\n```\n\nNote that `` tag before the `strong`'s `end`, to allow the `emphasis`\nannotation to be closed without overlapping the ``. The `strong`\nannotation is then reopened with a `` and then closed at its actual end.\n\n\n\n## Usage\n\nThere are no dependencies. NOAT works in both Python 2 and 3, and PyPy. The\nadding of annotations is lazy, so the actual markup is not generated until the\n`__str__` method is called.\n\n```python\n>>> from noat import NOAT\n>>> some_text = 'Lorem ipsum dolor sit amet.'\n>>> markup = NOAT(some_text)\n>>> markup.add('em', 5, 15)\n>>> markup.add('a', 4, 10, href='http://example.com')\n>>> str(markup)\n'Lorem ipsum dolor sit amet.'\n```\n\n### `NOAT`\n\nThe `NOAT` constructor takes a string and returns a NOAT instance, which can\nthen have annotations added to it.\n\n### `.add`\n\n markup.add(tag, start, [end,] [attributes,] [**attributes])\n\n`tag` can be any string. `start` and `end` are integers describing the start and\nend positions of the annotations (inclusive). `end` is optional, allowing for\n'collapsed' tags, (eg `abcdefgh`). Attributes are a dict of\nkey-value attributes to be added to the tag, eg\n`link`. Keyword arguments can also be provided,\n(which supersede any dict attributes).\n\nFor convenience, since `class` is a reserved word but a common annotation\nattribute, the attribute key `'_class'` will be converted to `'class'`, allowing\nfor keyword arguments to be written as `_class=\"marker\"`.\n\n\n\n\n## Authors\n\n* [Alec Perkins](https://github.com/alecperkins) ([Droptype Inc](http://droptype.com))\n\n\n\n## License\n\nUnlicensed aka Public Domain. See /UNLICENSE for more information.", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/marquee/noat", "keywords": "html tags tagging annotations annotation text", "license": "UNLICENSE", "maintainer": null, "maintainer_email": null, "name": "noat", "package_url": "https://pypi.org/project/noat/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/noat/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://github.com/marquee/noat" }, "release_url": "https://pypi.org/project/noat/1.0.2/", "requires_dist": null, "requires_python": null, "summary": "Non-overlapping annotation HTML tag insertion.", "version": "1.0.2" }, "last_serial": 1138824, "releases": { "1.0.0": [ { "comment_text": "", "digests": { "md5": "3c1c7531f4807ee394a62cf6327442ca", "sha256": "5301b2ef2158b0c26940949ab0f053e715833ccb0c81d49ef7f2f86c4e9a0ca1" }, "downloads": -1, "filename": "noat-1.0.0.tar.gz", "has_sig": false, "md5_digest": "3c1c7531f4807ee394a62cf6327442ca", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5175, "upload_time": "2013-09-03T21:16:39", "url": "https://files.pythonhosted.org/packages/48/c2/b3fac35cceec08bd3b62334af28d7c17baf6ab488b25985d4cae915bbd13/noat-1.0.0.tar.gz" } ], "1.0.1": [ { "comment_text": "", "digests": { "md5": "cc0ed203147b2cd7b2192a7f84506d62", "sha256": "b92419f39bd110e0a0f79132be90c1fafc561868fa49cd89c9ecfa33aec0dbad" }, "downloads": -1, "filename": "noat-1.0.1.tar.gz", "has_sig": false, "md5_digest": "cc0ed203147b2cd7b2192a7f84506d62", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5141, "upload_time": "2013-09-25T20:03:44", "url": "https://files.pythonhosted.org/packages/ac/5f/ef0318dbdb6ecc8fa6f9e2c3cdfdc2ebd205636d0cd210aba8fe637bcf44/noat-1.0.1.tar.gz" } ], "1.0.2": [ { "comment_text": "", "digests": { "md5": "d6bf4e512c3a6dde0373267b21af0fc2", "sha256": "a62ddc3338580d192a98494e51eeeede34ef6bd1c7d11613d012df2d5c8b4b3d" }, "downloads": -1, "filename": "noat-1.0.2.tar.gz", "has_sig": false, "md5_digest": "d6bf4e512c3a6dde0373267b21af0fc2", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5181, "upload_time": "2014-06-26T20:44:48", "url": "https://files.pythonhosted.org/packages/0c/f0/2022fc6bc140cf358e7d50179e23a8de904c884ddbe6433d960d793abed0/noat-1.0.2.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "d6bf4e512c3a6dde0373267b21af0fc2", "sha256": "a62ddc3338580d192a98494e51eeeede34ef6bd1c7d11613d012df2d5c8b4b3d" }, "downloads": -1, "filename": "noat-1.0.2.tar.gz", "has_sig": false, "md5_digest": "d6bf4e512c3a6dde0373267b21af0fc2", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5181, "upload_time": "2014-06-26T20:44:48", "url": "https://files.pythonhosted.org/packages/0c/f0/2022fc6bc140cf358e7d50179e23a8de904c884ddbe6433d960d793abed0/noat-1.0.2.tar.gz" } ] }