io.display.code
Displays a block of code to the action user.
Usage
- TypeScript
- JavaScript
- Python Experimental
await io.display.code("Check out the source code", {
code: 'console.log("Hello world!")',
language: "javascript",
});
await io.display.code("Check out the source code", {
code: 'console.log("Hello world!")',
language: "javascript",
});
await io.display.code("Check out the source code",
code='console.log("Hello world!")',
language="javascript",
)
interval.com
Props
- TypeScript
- JavaScript
- Python Experimental
code
Required
string
The text for the source code to display.
language
Optional
string
The language of the source code for syntax highlighing. Supported values are "bash", "c", "cpp", "csharp", "css", "diff", "go", "ini", "java", "javascript", "json", "kotlin", "less", "lua", "makefile", "markdown", "objectivec", "perl", "php", "php-template", "plaintext", "python", "python-repl", "r", "ruby", "rust", "scss", "shell", "sql", "swift", "typescript", "vbnet", "xml", and "yaml".
Returns
null
code
Required
string
The text for the source code to display.
language
Optional
string
The language of the source code for syntax highlighing. Supported values are "bash", "c", "cpp", "csharp", "css", "diff", "go", "ini", "java", "javascript", "json", "kotlin", "less", "lua", "makefile", "markdown", "objectivec", "perl", "php", "php-template", "plaintext", "python", "python-repl", "r", "ruby", "rust", "scss", "shell", "sql", "swift", "typescript", "vbnet", "xml", and "yaml".
Returns
null
code
Required
str
The text for the source code to display.
language
Optional
str
The language of the source code for syntax highlighing. Supported values are "bash", "c", "cpp", "csharp", "css", "diff", "go", "ini", "java", "javascript", "json", "kotlin", "less", "lua", "makefile", "markdown", "objectivec", "perl", "php", "php-template", "plaintext", "python", "python-repl", "r", "ruby", "rust", "scss", "shell", "sql", "swift", "typescript", "vbnet", "xml", and "yaml".
Returns
None
Examples
Displaying code from a file
- TypeScript
- JavaScript
- Python Experimental
// At top-level module scope
import fs from "fs";
// In your action
await io.display.code("Check out the source code", {
code: fs.readFileSync("./path/to/file.ts", { encoding: "utf8" }),
language: "typescript",
});
// At top-level module scope
import fs from "fs";
// In your action
await io.display.code("Check out the source code", {
code: fs.readFileSync("./path/to/file.ts", { encoding: "utf8" }),
language: "typescript",
});
await io.display.code("Check out the source code", {
code: open("./path/to/file.py", "r", encoding="utf-8").read(),
language: "python",
});
Was this section useful?