{"id":18449830,"url":"https://github.com/aleksandrhovhannisyan/markdown-it-code-tabindex","last_synced_at":"2025-04-18T00:19:34.762Z","repository":{"id":62639406,"uuid":"560828650","full_name":"AleksandrHovhannisyan/markdown-it-code-tabindex","owner":"AleksandrHovhannisyan","description":"Add tabindex=\"0\" to markdown-it code blocks for keyboard accessibility","archived":false,"fork":false,"pushed_at":"2022-11-03T12:00:11.000Z","size":65,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-15T21:46:13.785Z","etag":null,"topics":["a11y","markdown-codeblock","markdown-it","markdown-it-plugin","tabindex"],"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/AleksandrHovhannisyan.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":"2022-11-02T11:08:40.000Z","updated_at":"2022-11-02T22:30:33.000Z","dependencies_parsed_at":"2022-11-04T10:47:01.042Z","dependency_job_id":null,"html_url":"https://github.com/AleksandrHovhannisyan/markdown-it-code-tabindex","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AleksandrHovhannisyan%2Fmarkdown-it-code-tabindex","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AleksandrHovhannisyan%2Fmarkdown-it-code-tabindex/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AleksandrHovhannisyan%2Fmarkdown-it-code-tabindex/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AleksandrHovhannisyan%2Fmarkdown-it-code-tabindex/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AleksandrHovhannisyan","download_url":"https://codeload.github.com/AleksandrHovhannisyan/markdown-it-code-tabindex/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249161076,"owners_count":21222464,"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":["a11y","markdown-codeblock","markdown-it","markdown-it-plugin","tabindex"],"created_at":"2024-11-06T07:22:19.806Z","updated_at":"2025-04-15T21:46:19.505Z","avatar_url":"https://github.com/AleksandrHovhannisyan.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# markdown-it-code-tabindex\n\nAdd `tabindex=\"0\"` to your fenced code blocks in [`markdown-it`](https://github.com/markdown-it/markdown-it) for keyboard accessibility.\n\n## Installation\n\n```\nnpm i markdown-it-code-tabindex\n```\n\n## Usage\n\nRefer to the [`markdown-it` docs on loading plugins](https://github.com/markdown-it/markdown-it#plugins-load).\n\n### Options\n\n| Name    | Description                                                                                                                                  | Type           | Default |\n| --------- | -------------------------------------------------------------------------------------------------------------------------------------------- | -------------- | ------- |\n| `target` | The HTML tag on which to set `tabindex=\"0\"` for fenced code blocks. Either one is fine, so long as you pick the right one based on your CSS. | `'pre'\\|'code'` | `'pre'` |\n\n### Examples\n\n#### Basic usage\n\n```js\nconst markdownIt = require('markdown-it');\nconst markdownItTabIndex = require('markdown-it-code-tabindex');\n\nconst md = markdownIt().use(markdownItTabIndex, {\n  target: 'code', // or 'pre'\n});\n```\n\n#### Usage with other plugins\n\n```js\nconst markdownIt = require('markdown-it');\nconst markdownItAttributes = require('markdown-it-attrs');\nconst markdownItPrism = require('markdown-it-prism');\nconst markdownItCodeTabIndex = require('markdown-it-code-tabindex');\n\nconst md = \n  markdownIt()\n  .use(markdownItPrism)\n  .use(markdownItAttributes)\n  // Order does not matter; this could go before other plugins\n  .use(markdownItCodeTabIndex, { target: 'code' });\n```\n\n## Motivation\n\nThere are two ways to handle long lines of text in fenced code blocks (and in general):\n\n1. Allow whitespace to wrap to the next line whenever the current line would overflow.\n2. Prevent whitespace from wrapping and set `overflow-x: auto` on your code block.\n\nWhich one you choose comes down to personal preference, but scrollable code blocks tend to be more common. However, there is one drawback to this approach: Scroll regions are not accessible to keyboard users unless they are focusable. And the only way to make them focusable is to set `tabindex=\"0\"` on those scroll containers. However, there isn't a straightforward way to do this in Markdown.\n\nThis plugin automatically adds `tabindex=\"0\"` to all of your fenced code blocks in [`markdown-it`](https://github.com/markdown-it/markdown-it). It does not modify inline code, nor does it remove or modify any other HTML attributes.\n\n## Compatibility with Other `markdown-it` Plugins\n\nThis plugin is compatible with the following `markdown-it` plugins:\n\n- [`markdown-it-attrs`](https://github.com/arve0/markdown-it-attrs)\n- [`markdown-it-prism`](https://github.com/jGleitz/markdown-it-prism)\n\nThe order in which you load these plugins does not matter.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faleksandrhovhannisyan%2Fmarkdown-it-code-tabindex","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faleksandrhovhannisyan%2Fmarkdown-it-code-tabindex","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faleksandrhovhannisyan%2Fmarkdown-it-code-tabindex/lists"}