Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(docs): allow raw code interpolation #2447

Merged
merged 1 commit into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 6 additions & 10 deletions docs/docs/dev_docs/getting_started/sandbox.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,22 +132,18 @@ Add a `tsconfig.json` file into the project root, here is an example:
yarn add @aztec/aztec.js @aztec/noir-contracts
```

7. Create an `index.ts` file in the `src` directory and add the following imports:

#include_code imports /yarn-project/end-to-end/src/e2e_sandbox_example.test.ts typescript

Below the imports, set up a function in which we'll add the logic to interact with the Sandbox.
7. Create an `index.ts` file in the `src` directory with the following sandbox connection setup:

```ts
async function main() {}
#include_code imports /yarn-project/end-to-end/src/e2e_sandbox_example.test.ts raw

async function main() {
Maddiaa0 marked this conversation as resolved.
Show resolved Hide resolved
#include_code setup /yarn-project/end-to-end/src/e2e_sandbox_example.test.ts raw
}

main();
```

and the following setup code goes in the `main` function:

#include_code setup /yarn-project/end-to-end/src/e2e_sandbox_example.test.ts typescript

8. Finally, run the package:

```sh
Expand Down
8 changes: 5 additions & 3 deletions docs/src/preprocess/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,16 +221,18 @@ async function processMarkdownFilesInDir(rootDir, docsDir, regex) {
);

const relativeCodeFilePath = path.resolve(rootDir, codeFilePath);

const url = `https://github.com/AztecProtocol/aztec-packages/blob/master/${relativeCodeFilePath}#L${startLine}-L${endLine}`;

const title = noTitle ? "" : `title="${identifier}"`;
const lineNumbers = noLineNumbers ? "" : "showLineNumbers";
const source = noSourceLink
? ""
: `\n> [<sup><sub>Source code: ${url}</sub></sup>](${url})`;
const replacement = `\`\`\`${language} ${title} ${lineNumbers} \n${codeSnippet}\n\`\`\`${source}\n`;

let replacement = codeSnippet;
if (language !== "raw") {
// if we aren't raw mode, wrap in a code block
replacement = `\`\`\`${language} ${title} ${lineNumbers} \n${codeSnippet}\n\`\`\`${source}\n`;
}
// Replace the include tag with the code snippet
updatedContent = updatedContent.replace(fullMatch, replacement);
} catch (error) {
Expand Down