Skip to content

Commit

Permalink
fix: keep element props (#139)
Browse files Browse the repository at this point in the history
* fix: keep element props

* fix: add code.data

* refactor
  • Loading branch information
atomiks authored Dec 19, 2023
1 parent 36ffb2e commit 744ad8a
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Element, ElementContent, Root } from 'hast';
import type { Element, ElementContent, ElementData, Root } from 'hast';
import type { Options, Theme } from '../';
import type { CharsHighlighterOptions } from './types';
import type { Highlighter, CodeToHastOptions } from 'shikiji';
Expand Down Expand Up @@ -54,8 +54,10 @@ function apply(
}: ApplyProps,
) {
element.tagName = inline ? 'span' : 'figure';
// User can replace this with a real Fragment at runtime
element.properties = { 'data-rehype-pretty-code-figure': '' };
element.properties['data-rehype-pretty-code-figure'] = '';

const codeData = element.children[0]?.data as ElementData | undefined;

element.children = [tree]
.map((tree) => {
const pre = tree.children[0];
Expand Down Expand Up @@ -95,6 +97,7 @@ function apply(

code.properties['data-language'] = lang;
code.properties['data-theme'] = themeNamesString;
code.data = codeData;

if (inline) {
if (keepBackground) {
Expand Down

0 comments on commit 744ad8a

Please sign in to comment.