{"_id":"@a-morphous/frontispiece-line-parser","name":"@a-morphous/frontispiece-line-parser","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"@a-morphous/frontispiece-line-parser","version":"1.0.0","description":"Helper package that can parse a line from an ink story into **tokens** that can be used to add additional metadata. See `apps/example` in the root directory for an example of how it's used.","main":"dist/line-parser.module.js","module":"dist/line-parser.module.js","type":"module","types":"dist/index.d.ts","keywords":[],"author":"","license":"ISC","devDependencies":{"@types/moo":"^0.5.5","esbuild":"^0.17.19","json5":"^2.2.3","minimist":"^1.2.8","moo":"^0.5.2","npm-dts":"^1.3.12","vitest":"^0.31.4"},"scripts":{"build":"node build","dryRun":"pnpm publish --dry-run","pub":"pnpm publish --access public","test":"vitest"},"_id":"@a-morphous/frontispiece-line-parser@1.0.0","_integrity":"sha512-s1jF37lo+o/5YMU28CZPa7DJJrQGCyj0VfHfnMnld+hTrqQ1fjfNpDY1Uqr+Kv9cTCQ3S7Jw+fOqbTZHl05kOA==","_resolved":"/private/var/folders/pd/2r2pf8ln2cv61g2b_k9fr5nc0000gn/T/a3e1e296e0d8cba302b6b6103933643b/a-morphous-frontispiece-line-parser-1.0.0.tgz","_from":"file:a-morphous-frontispiece-line-parser-1.0.0.tgz","_nodeVersion":"16.15.1","_npmVersion":"8.11.0","dist":{"integrity":"sha512-s1jF37lo+o/5YMU28CZPa7DJJrQGCyj0VfHfnMnld+hTrqQ1fjfNpDY1Uqr+Kv9cTCQ3S7Jw+fOqbTZHl05kOA==","shasum":"febcb276f0b545a8a1240b667242290f2a0cb370","tarball":"https://registry.npmjs.org/@a-morphous/frontispiece-line-parser/-/frontispiece-line-parser-1.0.0.tgz","fileCount":15,"unpackedSize":109531,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDYBnMBaCmrdLqI+MQqE9afizYxk92RA9b6r28P0fkV6gIgIgVtQWCiDEqyEzP2F5fmp/F+LDqu66ZnQaww+z4YWe4="}]},"_npmUser":{"name":"amorphous","email":"84998015+a-morphous@users.noreply.github.com"},"directories":{},"maintainers":[{"name":"amorphous","email":"84998015+a-morphous@users.noreply.github.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/frontispiece-line-parser_1.0.0_1685913759212_0.23456675245278036"},"_hasShrinkwrap":false}},"time":{"created":"2023-06-04T21:22:39.089Z","1.0.0":"2023-06-04T21:22:39.353Z","modified":"2023-06-04T21:22:39.565Z"},"maintainers":[{"name":"amorphous","email":"84998015+a-morphous@users.noreply.github.com"}],"description":"Helper package that can parse a line from an ink story into **tokens** that can be used to add additional metadata. See `apps/example` in the root directory for an example of how it's used.","keywords":[],"license":"ISC","readme":"# Line Parser\n\nHelper package that can parse a line from an ink story into **tokens** that can be used to add additional metadata. See `apps/example` in the root directory for an example of how it's used.\n\n## Usage\n\n```ts\nimport { parseLineIntoTokens } from \"@a-morphous/frontispiece-line-parser\"\n\nlet tokens = parseLineIntoTokens(text)\nfor (let t of tokens) {\n\tswitch (t.type) {\n\t\tcase \"text\":\n\t\t\tstr += t.text\n\t\t\tbreak\n\t\tcase \"tag\":\n\t\t\tif (t.isClosingTag) {\n\t\t\t\tstr += `</span>`\n\t\t\t} else {\n\t\t\t\tstr += `<span class=\"ink-${t.param}\">`\n\t\t\t}\n\t\t\tbreak\n\t\t...\n\t}\n}\n\n```\n\n`line-parser` will transform the string into a *flat* array of tokens; besides text tokens, most of them will have an opening token and closing token to mark tags. It's then the developer's responsibility to transform those tokens into the final line.\n\n## Markup\n\n### Text\n\nAny text that doesn't match any other markup is represented as a `TextToken`.\n\n### Tags\n\nTags can be used to make custom HTML or other markup, and have the following syntax:\n\n```\n<<tagname>>Content of the tag <</tagname>>\n\nYou can also have <<tag>>generic<</>> endings, which will nest them in order.\n```\n\nTags will produce `TagTokens`:\n\n```ts\ntype TagToken = {\n\ttype: 'tag'\n\tparam: string\n\tisClosingTag?: boolean // set to true if it's used as a closing tag.\n}\n```\n\n### Links\n\nLinks are represented similarly to inline links in Markdown, and can be used to create a regular external link, or make any other note in the text that could be represented by some metadata.\n\n```\n[This is a link](target or url or link metadata)\n```\n\nThey produce a single `LinkToken`:\n\n```ts\nexport type LinkToken = {\n\ttype: 'link'\n\ttext: string\n\ttarget: string \n}\n```\nLink tokens don't have a closing tag; the text in them is the text rendered inside of the link body.\n\n### Notes\n\nNotes are exactly like links, except they use Markdown's image syntax, with a `!` before the rest of the syntax:\n\n```\n![This is a note](and a possible target).\n```\n\nThey produce a `NoteToken`, and are distinct from links only to allow for different types of functionality.","readmeFilename":"README.md"}