{"id":20790708,"url":"https://github.com/markedjs/marked-highlight","last_synced_at":"2025-05-16T06:04:14.255Z","repository":{"id":149511190,"uuid":"621587838","full_name":"markedjs/marked-highlight","owner":"markedjs","description":"Add code highlighting to marked","archived":false,"fork":false,"pushed_at":"2025-05-05T17:20:50.000Z","size":3689,"stargazers_count":103,"open_issues_count":2,"forks_count":11,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-05-05T18:35:35.571Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/marked-highlight","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/markedjs.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2023-03-31T01:08:45.000Z","updated_at":"2025-05-05T17:12:43.000Z","dependencies_parsed_at":null,"dependency_job_id":"e2718054-0775-4d79-b072-6e627d534f48","html_url":"https://github.com/markedjs/marked-highlight","commit_stats":null,"previous_names":[],"tags_count":20,"template":false,"template_full_name":"markedjs/marked-extension-template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markedjs%2Fmarked-highlight","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markedjs%2Fmarked-highlight/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markedjs%2Fmarked-highlight/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markedjs%2Fmarked-highlight/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/markedjs","download_url":"https://codeload.github.com/markedjs/marked-highlight/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254478163,"owners_count":22077675,"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":[],"created_at":"2024-11-17T15:37:03.608Z","updated_at":"2025-05-16T06:04:14.236Z","avatar_url":"https://github.com/markedjs.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# marked-highlight\n\nHighlight code blocks\n\n## Installation\n\n```sh\nnpm install marked-highlight\n```\n\n## Usage\n\nYou will need to provide a function that transforms the `code` to html.\n\n```js\nimport { Marked } from \"marked\";\nimport { markedHighlight } from \"marked-highlight\";\nimport hljs from 'highlight.js';\n\n// or UMD script\n// \u003cscript src=\"https://cdn.jsdelivr.net/npm/marked/lib/marked.umd.js\"\u003e\u003c/script\u003e\n// \u003cscript src=\"https://cdn.jsdelivr.net/npm/marked-highlight/lib/index.umd.js\"\u003e\u003c/script\u003e\n// const { Marked } = globalThis.marked;\n// const { markedHighlight } = globalThis.markedHighlight;\nconst marked = new Marked(\n  markedHighlight({\n\temptyLangClass: 'hljs',\n    langPrefix: 'hljs language-',\n    highlight(code, lang, info) {\n      const language = hljs.getLanguage(lang) ? lang : 'plaintext';\n      return hljs.highlight(code, { language }).value;\n    }\n  })\n);\n\n\nmarked.parse(`\n\\`\\`\\`javascript\nconst highlight = \"code\";\n\\`\\`\\`\n`);\n// \u003cpre\u003e\u003ccode class=\"hljs language-javascript\"\u003e\n//   \u003cspan class=\"hljs-keyword\"\u003econst\u003c/span\u003e highlight = \u003cspan class=\"hljs-string\"\u003e\u0026quot;code\u0026quot;\u003c/span\u003e;\n// \u003c/code\u003e\u003c/pre\u003e\n```\n\nThe `async` option should be set to `true` if the `highlight` function returns a `Promise`.\n\n```js\nimport { Marked } from \"marked\";\nimport { markedHighlight } from \"marked-highlight\";\nimport pygmentize from 'pygmentize-bundled';\n\nconst marked = new Marked(\n  markedHighlight({\n    async: true,\n    highlight(code, lang, info) {\n      return new Promise((resolve, reject) =\u003e {\n        pygmentize({ lang, format: 'html' }, code, function (err, result) {\n          if (err) {\n            reject(err);\n            return;\n          }\n\n          resolve(result.toString());\n        });\n      });\n    }\n  })\n)\n\nawait marked.parse(`\n\\`\\`\\`javascript\nconst highlight = \"code\";\n\\`\\`\\`\n`);\n// \u003cpre\u003e\u003ccode class=\"language-javascript\"\u003e\n//   \u003cdiv class=\"highlight\"\u003e\n//     \u003cpre\u003e\n//       \u003cspan class=\"kr\"\u003econst\u003c/span\u003e \u003cspan class=\"nx\"\u003ehighlight\u003c/span\u003e \u003cspan class=\"o\"\u003e=\u003c/span\u003e \u003cspan class=\"s2\"\u003e\u0026quot;code\u0026quot;\u003c/span\u003e\u003cspan class=\"p\"\u003e;\u003c/span\u003e\n//     \u003c/pre\u003e\n//   \u003c/div\u003e\n// \u003c/code\u003e\u003c/pre\u003e\n```\n\n### `options`\n\n| option |  type  | default | description |\n|--------|--------|---------|:------------|\n| async  | boolean | `false` | If the highlight function returns a promise set this to `true`. Don't forget to `await` the call to `marked.parse` |\n| langPrefix | string | `'language-'` | A prefix to add to the class of the `code` tag. |\n| emptyLangClass | string | `''` | The class to add to the `code` tag if the language is empty. |\n| highlight | function | `(code: string, lang: string) =\u003e {}` | Required. The function to transform the code to html. |\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarkedjs%2Fmarked-highlight","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmarkedjs%2Fmarked-highlight","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarkedjs%2Fmarked-highlight/lists"}