It is very easy to add a code snippet or an output result. All you have to do is indent your code with 4 spaces inside your Markdown document and your code will be rendered like this. Note: this method doesn't highlight code. interface PriceService { Money calcPrice(String cuips, Integer quantity); } # Simple Snippet It is very easy to add a code snippet or an output result. All you have to do is indent your code with 4 spaces inside your Markdown document and your code will be rendered like this. interface PriceService { Money calcPrice(String cuips, Integer quantity); }
You can also specify a language to enable syntax highlighting for your snippet. The following languages/formats are supported: C++ OCaml Python TypeScript Java SQL JSON Protobuf JavaScript Groovy Bash uses prismjs library to provide syntax highlighting. Note that it is not being executed inside the browser, but rather applied during HTML generation. ```javascript import React from 'react' class MyComponent extends React.Component { render() { /// ... } } ``` import React from 'react' class MyComponent extends React.Component { render() { /// ... } } Znai
Use the property to specify a title. title ```javascript {title: "ReactJS Component"} ... ``` import React from 'react' class MyComponent extends React.Component { render() { /// ... } }
When you specify a title, hover mouse over it to see a clickable anchor. Use to override auto generated identifier. anchorId ```javascript {title: "ReactJS Component", anchorId: "my-special-code"} ... ``` import React from 'react' class MyComponent extends React.Component { render() { /// ... } }
Use the option to stretch wide code to occupy as much horizontal real estate as possible. Without the option code will be aligned with the rest of the text and users can use scrollbars. Note: Good placement of a Wide Code element is at the end of a page or a section to show the full version of a code sample. wide ```java {wide: true} class InternationalPriceService implements PriceService { private static void LongJavaInterfaceNameWithSuperFactory createMegaAbstractFactory(final ExchangeCalendarLongerThanLife calendar) { ... } } ``` class InternationalPriceService implements PriceService { private static void LongJavaInterfaceNameWithSuperFactory createMegaAbstractFactory(final ExchangeCalendarLongerThanLife calendar) { ... } } wide class InternationalPriceService implements PriceService { private static void LongJavaInterfaceNameWithSuperFactory createMegaAbstractFactory(final ExchangeCalendarLongerThanLife calendar) { ... } }
Use the option to stretch wide code to occupy as much horizontal real estate as possible. wrap ```java {wrap: true} class InternationalPriceService implements PriceService { private static void LongJavaInterfaceNameWithSuperFactory createMegaAbstractFactory(final ExchangeCalendarLongerThanLife calendar) { ... } } ``` class InternationalPriceService implements PriceService { private static void LongJavaInterfaceNameWithSuperFactory createMegaAbstractFactory(final ExchangeCalendarLongerThanLife calendar) { ... } }
If you have a large code snippet and you want to initially display only a small fraction use the option with an optional option to specify a number of initial lines displayed (default is 8). readMore readMoreVisibleLines ```java {readMore: true, readMoreVisibleLines: 3} public class DocScaffolding { private final Path workingDir; private Map<String, List<String>> fileNameByDirName; ... ``` public class DocScaffolding { private final Path workingDir; private Map<String, List<String>> fileNameByDirName; public DocScaffolding(Path workingDir) { this.workingDir = workingDir; this.fileNameByDirName = new LinkedHashMap<>(); } public void create() { createPages(); createToc(); createMeta(); createIndex(); createLookupPaths(); } private void createLookupPaths() { createFileFromResource("lookup-paths"); } private void createMeta() { createFileFromResource("meta.json"); } }
Use the option to bring readers attention to important lines. Learn More about highlighting options. highlight ```java {highlight: "workingDir"} public class DocScaffolding { private final Path workingDir; private Map<String, List<String>> fileNameByDirName; public DocScaffolding(Path workingDir) { ... } ``` public class DocScaffolding { private final Path workingDir; private Map<String, List<String>> fileNameByDirName; public DocScaffolding(Path workingDir) { ... }