{"id":41347236,"url":"https://github.com/jamischarles/codemirror-server-render","last_synced_at":"2026-01-23T07:09:33.727Z","repository":{"id":57685451,"uuid":"488359343","full_name":"jamischarles/codemirror-server-render","owner":"jamischarles","description":"Renders CodeMirror 6 syntax highlighting as a string so you can use it at build time (ie: blog) or server-side.","archived":false,"fork":false,"pushed_at":"2023-02-23T22:11:09.000Z","size":890,"stargazers_count":9,"open_issues_count":0,"forks_count":4,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-09-23T10:01:48.103Z","etag":null,"topics":["codemirror6","server-side-rendering","syntax-highlighting"],"latest_commit_sha":null,"homepage":"","language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jamischarles.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-05-03T20:50:19.000Z","updated_at":"2025-02-23T21:25:16.000Z","dependencies_parsed_at":"2022-09-18T08:31:11.086Z","dependency_job_id":null,"html_url":"https://github.com/jamischarles/codemirror-server-render","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/jamischarles/codemirror-server-render","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamischarles%2Fcodemirror-server-render","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamischarles%2Fcodemirror-server-render/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamischarles%2Fcodemirror-server-render/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamischarles%2Fcodemirror-server-render/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jamischarles","download_url":"https://codeload.github.com/jamischarles/codemirror-server-render/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamischarles%2Fcodemirror-server-render/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28682368,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-23T05:48:07.525Z","status":"ssl_error","status_checked_at":"2026-01-23T05:48:07.129Z","response_time":59,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["codemirror6","server-side-rendering","syntax-highlighting"],"created_at":"2026-01-23T07:09:32.995Z","updated_at":"2026-01-23T07:09:33.722Z","avatar_url":"https://github.com/jamischarles.png","language":"HTML","funding_links":[],"categories":[],"sub_categories":[],"readme":"## TODO:\n1. Make it work with lezer only and latest deps. (latest deps: CHECK) Lezer-only?\n2. Make it work minimal client side with just json (maybe fork it, or make a different repo for that use case...)\n\n\n\n# CodeMirror-server-render (CodeMirror 6)\nRenders CodeMirror 6 syntax highlighting as a string so you can use it at build time (ie: blog) or server-side.\nVerified to work with latest CM6 `0.20` themes.\n\n## Installation\n`npm install codemirror-server-render`\n\n## Usage\n```js\nrenderString( \"alert('hello')\" ); // default theme, default language (js). Returns object\n// -\u003e {code: \u003cdiv class=\"cm-editor \"\u003e\u003cdiv class=\"cm-scroller\"\u003e\u003cdiv class=\"cm-content\"\u003e\u003cdiv class=\"cm-line\"\u003ealert(\u003cspan class=\"Í¼e\"\u003e'hello'\u003c/span\u003e); \u003c/div\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e, css: {...} }\n``` \n\n```js\n var result = renderString(code, oneDarkHighlightStyle, oneDarkTheme, {lineNumbers: true}); // themed for oneDark, and add lineNumbers\n``` \n\n## Return value of `renderString()`\n```js\n{\n  code, // a string of tokenized html, incuding editor wrapper html\n  codeLinesOnly, // a string of tokenized html only, excluding the wrapper elements\n  css: {\n    baseEditorStyles, // string of base styles needed to use the editor. Loaded from './base-theme.css'\n    highlightRules // an array of css rule strings based on the theme you are using (matches the classNames in 'code' prop above)\n  }\n}\n```\n\n## Examples\n### Default styles, default language (JavaScript)\n\u003cimg src=\"./screenshots/default_theme.png\"  width=\"45%\" /\u003e\n\n```js\nimport { renderString } from \"codemirror-server-render\";\n\n var code = `function add(a,b){\n  return a+b;\n} \n// amazing comment!`;\n\nlet result = renderString(code); \n\n\n  const html = `\n    \u003chead\u003e\n      \u003cstyle\u003e${result.css.baseEditorStyles}\u003c/style\u003e\n      \u003cstyle\u003e${result.css.highlightRules.join('\\n')}\u003c/style\u003e\n    \u003c/head\u003e\n\n    \u003cbody\u003e\n      ${result.code}\n  \u003c/body\u003e\n  `\n\n```\n\n### `One-dark` theme and `html` language. LineNumbers enabled\n\u003cimg src=\"./screenshots/dark_theme.png\" width=\"45%\" /\u003e\n\n```js\nimport { htmlLanguage } from '@codemirror/lang-html';\nimport { oneDarkHighlightStyle, oneDarkTheme } from '@codemirror/theme-one-dark'\nimport { renderString } from \"codemirror-server-render\";\n\n var code = `\u003c!DOCTYPE html\u003e\n  \u003cbody\u003e\n    \u003cstyle\u003e\n     .red {color: red;}\n    \u003c/style\u003e\n  \u003c/body\u003e\n`;\n\nvar result = renderString(code, oneDarkHighlightStyle, oneDarkTheme, {lineNumbers: true});\n\nconst html = `\n  \u003chead\u003e\n    \u003cstyle\u003e${result.css.baseEditorStyles}\u003c/style\u003e\n    \u003cstyle\u003e${result.css.highlightRules.join('\\n')}\u003c/style\u003e\n  \u003c/head\u003e\n\n  \u003cbody\u003e\n    ${result.code}\n\u003c/body\u003e\n`\n\n```\n\n## Customizing Editor CSS\nTake a look at base-theme.css in this repo, and go from there.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjamischarles%2Fcodemirror-server-render","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjamischarles%2Fcodemirror-server-render","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjamischarles%2Fcodemirror-server-render/lists"}