Tutorial: Reference code from the repository
From this tutorial, you will learn how to reference the code example from the repository without copy-pasting it into documentation and how to add a check it is valid so that it always stays in sync with the actual solution.
Reference the code example from the repository
To include the code example from another file in the repository:
Specify the name of the directory where you will place the code files in the
snippets
attribute of the writerside.cfg file.<snippets src="directoryName"/>Use the
src
attribute to specify the filename.```kotlin ``` {src="newTest.kt"}(Optionally) Use the
include-lines
attribute to specify a line range or a comma-separated list of lines to include.(Optionally) Use the
include-symbol
attribute to specify a specific code construct, like, method or class, to include.
Check the markup examples below.
Add code validation
On the help page, a user can copy the code block in a single click to try it out right away. Add validation to the code snippet to check if it is valid.
Set
validate
attribute totrue
to validate the code in a snippet. It works only for the IntelliJ-supported set of languages.If the code example is invalid, Writerside will display an error in the preview area.
In this tutorial, we have included a code example from another file and added a check for its validity.
Check what other attributes you can apply to the code block in Code snippets.