File tree Expand file tree Collapse file tree 3 files changed +17
-2
lines changed Expand file tree Collapse file tree 3 files changed +17
-2
lines changed Original file line number Diff line number Diff line change @@ -90,6 +90,7 @@ export function tokensToHast(
9090
9191 const {
9292 structure = 'classic' ,
93+ tabindex = '0' ,
9394 } = options
9495
9596 let preNode : Element = {
@@ -98,7 +99,11 @@ export function tokensToHast(
9899 properties : {
99100 class : `shiki ${ options . themeName || '' } ` ,
100101 style : options . rootStyle || `background-color:${ options . bg } ;color:${ options . fg } ` ,
101- tabindex : '0' ,
102+ ...( tabindex !== false && tabindex != null )
103+ ? {
104+ tabindex : tabindex . toString ( ) ,
105+ }
106+ : { } ,
102107 ...Object . fromEntries (
103108 Array . from (
104109 Object . entries ( options . meta || { } ) ,
Original file line number Diff line number Diff line change @@ -48,6 +48,7 @@ it('hasfocus support', async () => {
4848 const code = await codeToHtml ( snippet , {
4949 lang : 'php' ,
5050 theme : 'vitesse-light' ,
51+ tabindex : false ,
5152 transformers : [
5253 {
5354 code ( node ) {
@@ -67,7 +68,7 @@ it('hasfocus support', async () => {
6768
6869 expect ( code )
6970 . toMatchInlineSnapshot ( `
70- "<pre class="shiki vitesse-light" style="background-color:#ffffff;color:#393a34" tabindex="0" ><code class="language-php"><span class="line"><span style="color:#999999">$</span><span style="color:#B07D48">foo</span><span style="color:#999999"> =</span><span style="color:#B5695977"> "</span><span style="color:#B56959">bar</span><span style="color:#B5695977">"</span><span style="color:#999999">;</span></span>
71+ "<pre class="shiki vitesse-light" style="background-color:#ffffff;color:#393a34"><code class="language-php"><span class="line"><span style="color:#999999">$</span><span style="color:#B07D48">foo</span><span style="color:#999999"> =</span><span style="color:#B5695977"> "</span><span style="color:#B56959">bar</span><span style="color:#B5695977">"</span><span style="color:#999999">;</span></span>
7172 <span class="line" data-has-focus="true"><span style="color:#999999">$</span><span style="color:#B07D48">test</span><span style="color:#999999"> =</span><span style="color:#B5695977"> "</span><span style="color:#B56959">owo</span><span style="color:#B5695977">"</span><span style="color:#999999">;</span><span style="color:#A0ADA0"></span></span>
7273 <span class="line"><span style="color:#999999">$</span><span style="color:#B07D48">bar</span><span style="color:#999999"> =</span><span style="color:#B5695977"> "</span><span style="color:#B56959">baz</span><span style="color:#B5695977">"</span><span style="color:#999999">;</span></span></code></pre>"
7374 ` )
Original file line number Diff line number Diff line change @@ -153,6 +153,15 @@ export interface CodeToHastOptionsCommon<Languages extends string = string>
153153 * @default 'classic'
154154 */
155155 structure ?: 'classic' | 'inline'
156+
157+ /**
158+ * Tab index of the root `<pre>` element.
159+ *
160+ * Set to `false` to disable tab index.
161+ *
162+ * @default 0
163+ */
164+ tabindex ?: number | string | false
156165}
157166
158167export interface CodeOptionsMeta {
You can’t perform that action at this time.
0 commit comments