{"id":15707215,"url":"https://github.com/drom/tspan","last_synced_at":"2025-05-12T19:42:37.152Z","repository":{"id":57381778,"uuid":"48524326","full_name":"drom/tspan","owner":"drom","description":"little markup for SVG tspan","archived":false,"fork":false,"pushed_at":"2022-04-22T04:30:20.000Z","size":45,"stargazers_count":6,"open_issues_count":5,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-05-03T02:07:58.974Z","etag":null,"topics":["hacktoberfest"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/drom.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-12-24T04:13:04.000Z","updated_at":"2025-03-21T03:55:50.000Z","dependencies_parsed_at":"2022-09-13T11:20:27.465Z","dependency_job_id":null,"html_url":"https://github.com/drom/tspan","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drom%2Ftspan","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drom%2Ftspan/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drom%2Ftspan/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drom%2Ftspan/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/drom","download_url":"https://codeload.github.com/drom/tspan/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253809558,"owners_count":21967744,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["hacktoberfest"],"created_at":"2024-10-03T20:38:14.647Z","updated_at":"2025-05-12T19:42:37.126Z","avatar_url":"https://github.com/drom.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# \u0026lt;tspan\u0026gt;\n\n[![NPM version](https://img.shields.io/npm/v/tspan.svg)](https://www.npmjs.org/package/tspan)\n[![Build Status](https://travis-ci.org/drom/tspan.svg)](https://travis-ci.org/drom/tspan)\n[![Coverage Status](https://coveralls.io/repos/github/drom/tspan/badge.svg?branch=master)](https://coveralls.io/github/drom/tspan?branch=master)\n\n**tspan** is an JavaScript library designed for a simple way of adding some formated text into SVG documents. It takes text string with some XML style tags and produces an array of `\u003ctspan\u003e` objects in [JsonML](http://www.jsonml.org) format.\n\n### Supported tags:\n\n|format|render|SVG style|\n|------|------|---------|\n|`\u003co\u003eoverline\u003c/o\u003e`|\u003co\u003eoverline\u003c/o\u003e|{'text-decoration': 'overline'}\n|`\u003cins\u003eunderline\u003c/ins\u003e`|\u003cins\u003eunderline\u003c/ins\u003e|{'text-decoration': 'underline'}\n|`\u003csub\u003esubscript\u003c/sub\u003e`|\u003csub\u003esubscript\u003c/sub\u003e|{'baseline-shift': 'sub'}\n|`\u003csup\u003esuperscript\u003c/sup\u003e`|\u003csup\u003esuperscript\u003c/sup\u003e|{'baseline-shift': 'super'}\n|`\u003cb\u003ebold\u003c/b\u003e`|\u003cb\u003ebold\u003c/b\u003e|{'font-weight': 'bold'}\n|`\u003ci\u003eitalic\u003c/i\u003e`|\u003ci\u003eitalic\u003c/i\u003e|{'font-style': 'italic'}\n|`\u003cs\u003estrikethrough\u003c/s\u003e`|\u003cs\u003estrikethrough\u003c/s\u003e|{'text-decoration': 'line-through'}\n|`\u003ctt\u003ecode\u003c/tt\u003e`|\u003ctt\u003ecode\u003c/tt\u003e|{'font-family': 'monospace'}\n\n#### Resulted SVG\n\n![exmaple](https://rawgit.com/drom/tspan/master/test/all.svg)\n\n## Use\n### Node.js\n\n```\nnpm i tspan --save\n```\n\n```js\nvar tspan = require('tspan');\n\nvar source = 'a \u003co\u003elong\u003c/o\u003e \u003ci\u003eand \u003cb\u003ewinding\u003c/i\u003e \u003csub\u003eroad\u003c/sub\u003e';\nvar result = tspan.parse(source);\n\nconsole.log(result);\n// --\u003e\n[\n    ['tspan', {}, 'a '],\n    ['tspan', {'text-decoration': 'overline'}, 'long'],\n    ['tspan', {}, ' '],\n    ['tspan', {'font-style': 'italic'}, 'and '],\n    ['tspan', {'font-style': 'italic', 'font-weight': 'bold'}, 'winding'],\n    ['tspan', {'font-weight': 'bold'}, ' '],\n    ['tspan', {'baseline-shift': 'sub', 'font-size': '.7em', 'font-weight': 'bold'}, 'road']\n]\n```\ntspan array then can be unshifted with a `text` tag, inserted into bigger SVG structure and with a little help of [onml](https://www.npmjs.com/package/onml) package converted into XML form.\n\n```js\nresult.unshift('text', {x: 20, y: 20, 'font-size': 16});\nvar svg = ['svg', {\n    viewBox: '0 0 400 100',\n    width: 400, height: 100,\n    xmlns: 'http://www.w3.org/2000/svg'\n}, result];\n\nvar onml = require('onml');\n\nconsole.log(onml.stringify(svg)));\n// --\u003e\n\u003csvg viewBox=\"0 0 400 100\" width=\"400\" height=\"100\" xmlns=\"http://www.w3.org/2000/svg\"\u003e\n  \u003ctext x=\"20\" y=\"20\" font-size=\"16\"\u003e\n    \u003ctspan\u003ea \u003c/tspan\u003e\n    \u003ctspan text-decoration=\"overline\"\u003elong\u003c/tspan\u003e\n    \u003ctspan\u003e\u003c/tspan\u003e\n    \u003ctspan font-style=\"italic\"\u003eand \u003c/tspan\u003e\n    \u003ctspan font-style=\"italic\" font-weight=\"bold\"\u003ewinding\u003c/tspan\u003e\n    \u003ctspan font-weight=\"bold\"\u003e\u003c/tspan\u003e\n    \u003ctspan baseline-shift=\"sub\" font-size=\".7em\" font-weight=\"bold\"\u003eroad\u003c/tspan\u003e\n  \u003c/text\u003e\n\u003c/svg\u003e\n```\n\nthat will look like:\n\n![exmaple](https://rawgit.com/drom/tspan/master/test/alawr.svg)\n\n### Browser\n\n*Browserify!*\n\n## Testing\n`npm test`\n\n## License\nMIT [LICENSE](https://github.com/drom/tspan/blob/master/LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdrom%2Ftspan","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdrom%2Ftspan","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdrom%2Ftspan/lists"}