Skip to content

Commit

Permalink
fix: resolves wrong transformer args
Browse files Browse the repository at this point in the history
  • Loading branch information
bent10 committed Nov 3, 2023
1 parent 752aaea commit a690bb1
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 14 deletions.
2 changes: 1 addition & 1 deletion packages/code-preview/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ Yields:

### `transformer?: Transformer`

The transformer function for modifying code before replacing the `preview` placeholder.
The transformer function for modifying preview code before replacing the `{preview}` placeholder.

Default transformer:

Expand Down
18 changes: 7 additions & 11 deletions packages/code-preview/src/transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export function transform(token: Tokens.Generic, options: TransformOptions) {
const dataInterpolation = {
...data,
...attrs,
preview: token.text
preview: transformer(token.text, attrs, data)
}

const acc: Array<Tokens.Code | Tokens.Generic | Tokens.HTML | Tokens.Space> =
Expand All @@ -46,16 +46,12 @@ export function transform(token: Tokens.Generic, options: TransformOptions) {
if (type === 'placeholder') {
acc.push(token)
} else if (type === 'text') {
const interpolatedText = pupa(
normalizeCodeText(text),
dataInterpolation,
{
ignoreMissing: true
}
)
const transformedText = transformer(interpolatedText, attrs, data)

acc.push(createHtmlToken(interpolatedText, transformedText))
const normalizedText = normalizeCodeText(text)
const interpolatedText = pupa(normalizedText, dataInterpolation, {
ignoreMissing: true
})

acc.push(createHtmlToken(normalizedText, interpolatedText))
}
}

Expand Down
4 changes: 2 additions & 2 deletions packages/code-preview/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ export interface Options {
template?: string

/**
* The transformer function for modifying code before replacing the
* `preview` placeholder.
* The transformer function for modifying preview code before replacing the
* `{preview}` placeholder.
*
* @default (code) => code
*/
Expand Down

0 comments on commit a690bb1

Please sign in to comment.