{"id":16542411,"url":"https://github.com/tada5hi/bulletin-board-code","last_synced_at":"2025-03-16T19:32:19.923Z","repository":{"id":37085230,"uuid":"500114373","full_name":"tada5hi/bulletin-board-code","owner":"tada5hi","description":"This library provides utitlites to parse BBCodes to HTML and HTML to BBCodes.","archived":false,"fork":false,"pushed_at":"2024-07-15T14:13:34.000Z","size":1376,"stargazers_count":12,"open_issues_count":12,"forks_count":1,"subscribers_count":2,"default_branch":"develop","last_synced_at":"2024-10-21T06:35:48.978Z","etag":null,"topics":["bbcode","bbcode-parser","bbcode-to-html","bulletin-board-code","html-to-bbcode","parse","parser","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/tada5hi.png","metadata":{"files":{"readme":"README.MD","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-06-05T14:05:09.000Z","updated_at":"2024-07-19T23:54:13.000Z","dependencies_parsed_at":"2023-12-23T10:36:01.354Z","dependency_job_id":"31aeec52-198e-45ec-b55e-46cf8bcc0a13","html_url":"https://github.com/tada5hi/bulletin-board-code","commit_stats":{"total_commits":97,"total_committers":3,"mean_commits":"32.333333333333336","dds":"0.35051546391752575","last_synced_commit":"9cf72ddccf8286df42f7e5ab3131d1a827a6902f"},"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tada5hi%2Fbulletin-board-code","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tada5hi%2Fbulletin-board-code/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tada5hi%2Fbulletin-board-code/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tada5hi%2Fbulletin-board-code/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tada5hi","download_url":"https://codeload.github.com/tada5hi/bulletin-board-code/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221667419,"owners_count":16860621,"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":["bbcode","bbcode-parser","bbcode-to-html","bulletin-board-code","html-to-bbcode","parse","parser","typescript"],"created_at":"2024-10-11T18:57:26.736Z","updated_at":"2024-10-27T11:10:42.383Z","avatar_url":"https://github.com/tada5hi.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Bulletin Board Code ⚗️\n\n[![npm version](https://badge.fury.io/js/bulletin-board-code.svg)](https://badge.fury.io/js/bulletin-board-code)\n[![CI](https://github.com/tada5hi/bulletin-board-code/actions/workflows/main.yml/badge.svg)](https://github.com/tada5hi/bulletin-board-code/actions/workflows/main.yml)\n[![codecov](https://codecov.io/gh/Tada5hi/bulletin-board-code/branch/master/graph/badge.svg?token=4KNSG8L13V)](https://codecov.io/gh/Tada5hi/bulletin-board-code)\n[![Known Vulnerabilities](https://snyk.io/test/github/Tada5hi/bulletin-board-code/badge.svg)](https://snyk.io/test/github/Tada5hi/bulletin-board-code)\n[![semantic-release: angular](https://img.shields.io/badge/semantic--release-angular-e10079?logo=semantic-release)](https://github.com/semantic-release/semantic-release)\n\n**B**ulletin **B**oard **Code** (BBCode) is a library to transform a string from:\n- BBCode to HTML\n- HTML to BBCode\n\n**Table of Contents**\n\n- [Installation](#installation)\n- [Features](#features)\n- [Usage](#usage)\n  - [BBCode to HTML](#bbcode-to-html)\n  - [HTML to BBCode](#html-to-bbcode)\n- [Handlers](#handlers)\n  - [Set](#set)\n  - [Unset](#unset)\n- [Types](#types)\n  - [ParserOptions](#parseroptions)\n- [License](#license)\n\n## Installation\n\n```bash\nnpm install bulletin-board-code --save\n```\n\n## Features\n\n- ✨ bidirectional transformation (HTML \u0026 BBCode)\n- 📚 support nested BBCodes\n- 🛠️ automatic repair mode\n- 🧩 set/unset custom handlers for transformation\n\n## Usage\n\nFor an overview of all predefined BBCodes,\ntake a look at the following [file](src/handler/constants.ts).\nTo see them in action, the test directory can be inspected.\n\n### BBCode To HTML\n\n```typescript\nimport { Parser } from 'bulletin-board-code';\n\n// initialize the parser\nconst parser = new Parser();\n\nconsole.log(parser.toHTML('[b]foo[/b]'));\n// \u003cstrong\u003efoo\u003c/strong\u003e\n\n```\n\n### HTML To BBCode\n\n```typescript\nimport { Parser } from 'bulletin-board-code';\n\n// initialize the parser\nconst parser = new Parser();\n\nconsole.log(parser.toBBCode('\u003cstrong\u003efoo\u003c/strong\u003e'));\n// [b]foo[/b]\n```\n\n## Handlers\n\nA handler describes how parsed tokens should be transformed to HTML or BBCode.\nFurthermore, the handler specifies conditions, when to match with a token.\n\n### Set\n\nTo set a (new) handler use the following approach:\n\n```typescript\nimport { Parser } from 'bulletin-board-code';\n\nconst parser = new Parser();\n\nparser.setHandler('lazy', {\n    conditions: [{ attribute: { lazy: null } }],\n    bbcode: '[lazy]{0}[/lazy]',\n    html: '\u003cspan lazy=\"true\"\u003elazy: {0}\u003c/span\u003e'\n});\n\nconsole.log(parser.toHTML('[lazy]foo[/lazy]'));\n// \u003cspan lazy=\"true\"\u003elazy: foo\u003c/span\u003e\n\nconsole.log(parser.toBBCode('\u003cspan lazy=\"true\"\u003elazy: foo\u003c/span\u003e'));\n// [lazy]foo[/lazy]\n```\n\n### Unset\n\nTo unset a handler use the following approach:\n\n```typescript\nimport { Parser, unsetHandler } from 'bulletin-board-code';\n\nconst parser = new Parser();\n\nparser.unsetHandler('h1');\nparser.unsetHandler(['h2', 'h3']);\n\nconsole.log(parser.toHTML('[h1]foo[/h1]'));\n// [h1]foo[/h1]\n\nconsole.log(parser.toBBCode('\u003ch1\u003efoo\u003c/h1\u003e'));\n// \u003ch1\u003efoo\u003c/h1\u003e\n```\n\n## Types\n### ParserOptions\n\nThe following options can be passed to the parser as constructor argument.\n\n```typescript\ndeclare type ParserOptions = {\n    /**\n     * Add a set of handlers to the already predefined ones.\n     *\n     * default: {}\n     */\n    handlers: Record\u003cstring, Handler\u003e,\n\n    /**\n     * If to add a new line before block level elements\n     *\n     * default: false\n     */\n    breakBeforeBlock: boolean,\n\n    /**\n     * If to add a new line after the start of block level elements\n     *\n     * default: false\n     */\n    breakStartBlock: boolean,\n\n    /**\n     * If to add a new line before the end of block level elements\n     *\n     * default: false\n     */\n    breakEndBlock: boolean,\n\n    /**\n     * If to add a new line after block level elements.\n     *\n     * default: true\n     */\n    breakAfterBlock: boolean,\n\n    /**\n     * If to remove empty tags.\n     *\n     * default: true\n     */\n    removeEmptyTags: boolean,\n\n    /**\n     * If to fix invalid nesting, like block level elements inside inline elements.\n     *\n     * default: true\n     */\n    fixInvalidNesting: boolean,\n\n    /**\n     * If to fix invalid children. i.e.\n     * A tag which is inside a parent that doesn’t allow that type of tag as a child.\n     *\n     * default: true\n     */\n    fixInvalidChildren: boolean,\n\n    /**\n     * The default attribute quote type.\n     *\n     * default: QuoteType.auto\n     */\n    quoteType: `${QuoteType}`,\n\n    /**\n     * Lazy transformation without handler.\n     * Otherwise, library will attempt to construct html or bbcode without handler.\n     *\n     * default: true\n     */\n    lazyTransformation: boolean\n};\n```\n\n## License\n\nMade with 💚\n\nPublished under [MIT License](./LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftada5hi%2Fbulletin-board-code","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftada5hi%2Fbulletin-board-code","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftada5hi%2Fbulletin-board-code/lists"}