Skip to content

Commit 2585236

Browse files
committed
feat: share original content with post-transforms
1 parent 8da499b commit 2585236

File tree

5 files changed

+23
-7
lines changed

5 files changed

+23
-7
lines changed

src/base/Sveltex.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ export class Sveltex<
444444
// Apply the post-transformers
445445
html = applyTransformations(
446446
html,
447-
frontmatter ?? {},
447+
{ ...(frontmatter ?? {}), original: content },
448448
markdownHandler.configuration.transformers.post,
449449
);
450450
/* eslint-enable @typescript-eslint/no-unnecessary-condition */

src/handlers/CodeHandler.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ export class CodeHandler<B extends CodeBackend> extends Handler<
141141
if (transformers.post) {
142142
processed = applyTransformations(
143143
processed,
144-
mergedOpts,
144+
{ ...mergedOpts, original: code },
145145
transformers.post,
146146
);
147147
}

src/handlers/MathHandler.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,21 @@ export class MathHandler<B extends MathBackend> extends Handler<
4242
await this.handleCss();
4343

4444
// Apply pre-transformers
45-
tex = applyTransformations(
45+
const pretransformed = applyTransformations(
4646
tex,
4747
{ inline: options?.inline !== false },
4848
this._configuration.transformers.pre,
4949
);
5050

5151
const res = await super.process(
52-
tex,
52+
pretransformed,
5353
options ?? ({} as MathProcessOptions<B>),
5454
);
5555

5656
// Apply post-transformers
5757
res.processed = applyTransformations(
5858
res.processed,
59-
{ inline: options?.inline !== false },
59+
{ inline: options?.inline !== false, original: tex },
6060
this._configuration.transformers.post,
6161
);
6262

src/handlers/VerbatimHandler.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,11 @@ export class VerbatimHandler<C extends CodeBackend> extends Handler<
261261
typeAssert(is<FullVerbEnvConfigNoop>(config));
262262
}
263263

264-
processed = applyTransformations(processed, options, post);
264+
processed = applyTransformations(
265+
processed,
266+
{ ...options, original: innerContent },
267+
post,
268+
);
265269

266270
// If `component !== 'none'`, wrap the processed content in the
267271
// output tag, so that `processed` now stores the _outer_ content.

src/types/handlers/Handler.ts

+13-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,19 @@ export interface Transformers<Options extends object> {
5656
* - 2-tuple: `transformed = content.replaceAll(...transformation)`
5757
* - Function: `transformed = transformation(content, opts)`
5858
*/
59-
post?: Transformer<Options> | Transformer<Options>[] | undefined | null;
59+
post?:
60+
| Transformer<Options & WithOriginal>
61+
| Transformer<Options & WithOriginal>[]
62+
| undefined
63+
| null;
64+
}
65+
66+
interface WithOriginal {
67+
/**
68+
* The original content that was passed to the backend for processing. This
69+
* is before pre-transformations were applied, too.
70+
*/
71+
original: string;
6072
}
6173

6274
/**

0 commit comments

Comments
 (0)