Skip to content
\n
\n \n\n \n \n \n \n
export function withAccessModel(accessModel: FsAccessModel): BeforeBuildFn {
\n
\n
\n

\n

You can also use the {map,unmap,reset}Shadow function to manipulate any text or binary file data for typst compiler. They will shadow the file access from provided access model directly in memory.

\n

\n
\n

\n typst.ts/packages/typst.ts/src/compiler.mts\n

\n

\n Lines 69 to 95\n in\n 4ef85dc\n

\n
\n
\n \n\n \n \n \n \n\n \n \n \n \n\n \n \n \n \n\n \n \n \n \n\n \n \n \n \n\n \n \n \n \n\n \n \n \n \n\n \n \n \n \n\n \n \n \n \n\n \n \n \n \n\n \n \n \n \n\n \n \n \n \n\n \n \n \n \n\n \n \n \n \n\n \n \n \n \n\n \n \n \n \n\n \n \n \n \n\n \n \n \n \n\n \n \n \n \n\n \n \n \n \n\n \n \n \n \n\n \n \n \n \n\n \n \n \n \n\n \n \n \n \n\n \n \n \n \n\n \n \n \n \n\n \n \n \n \n
/**
* Add a source file to the compiler.
* @param {string} path - The path of the source file.
* @param {string} source - The source code of the source file.
*
*/
addSource(path: string, source: string): void;
/**
* Add a shadow file to the compiler.
* @param {string} path - The path to the shadow file.
* @param {Uint8Array} content - The content of the shadow file.
*
*/
mapShadow(path: string, content: Uint8Array): void;
/**
* Remove a shadow file from the compiler.
* @param {string} path - The path to the shadow file.
*/
unmapShadow(path: string): void;
/**
* Reset the shadow files.
* Note: this function is independent to the {@link reset} function.
*/
resetShadow(): void;
\n
\n
\n

\n

The mapShadow(path: string, content: Uint8Array): void; resembles addSource(path: string, source: string): void;, but retrieves some binary data without guessing the underlying encoding.

\n

Example usage:

\n
const encoder = new TextEncoder();\n// add a json file (utf8)\ncompiler.mapShadow('/assets/data.json', encoder.encode(jsonData));\n// remove a json file\ncompiler.unmapShadow('/assets/data.json');\n// clean up all shadow files (Note: this function will also clean all files added by `addSource`)\ncompiler.resetShadow();\n\n// add an image file\nconst pngData = await fetch(...).arrayBuffer();\ncompiler.mapShadow('/assets/tiger.png', new Uint8Array(pngData));
","upvoteCount":1,"url":"https://github.com/Myriad-Dreamin/typst.ts/discussions/376#discussioncomment-7269226"}}}

Data upload via external file like the json,csv? #376

Discussion options

You must be logged in to vote

Hi, you could add files to your access model, which can then get read by typst compiler. The access model refers to

export function withAccessModel(accessModel: FsAccessModel): BeforeBuildFn {

You can also use the {map,unmap,reset}Shadow function to manipulate any text or binary file data for typst compiler. They will shadow the file access from provided access model directly in memory.

/**
* Add a source file to the compiler.
* @param {string} path - The path of the source file.
* @param {string} source -…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by Myriad-Dreamin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #375 on October 13, 2023 02:32.