Skip to content

Commit

Permalink
feat(docs): allow raw code interpolation (#2447)
Browse files Browse the repository at this point in the history
Used in sandbox intro.
  • Loading branch information
ludamad authored Sep 21, 2023
1 parent b2243ad commit e078ff4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
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() {
#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

0 comments on commit e078ff4

Please sign in to comment.