Code blocks

This page contains:

You will be using blocks of code in almost every type of assessment to capture: request / response pairs, code snippets or fragments of configuration files.

Blocks of code in Dradis

In the Working with notes section of the Working with projects manual we introduced the Textile marker you can use in Dradis to style a block of text as code. A quick refresher:

Reports 47

Results of bc.

We start with normal text.

This would extend
until the first blank line.

Back to normal

Reports 48

Results of bc..

Before the code block, we have normal text.

This will extend
across blank lines until

the next paragraph block

Which you start with the 'p.' signature.

Blocks of code in Word

Dradis reporting engine will detect the code blocks in your content and translate them into the generated Word report. You just need to decide how you want to style them.

Lets start with some dummy text and playing with Word styling options:

Reports 49

We've added a background, borders, some indents, a fixed-width font and a few other niceties. Now we need to save this style as a new Quick Style:

  1. Select the text.
  2. Right-click, Styles, Save Selection as New Quick Style...
  3. Give your new style the Code name (capitalization is important).
Reports 50
Reports 51

You can now delete the dummy text used to create the style from the template. Note how the new Code style now shows in the Styles toolbar:

Reports 52

Lets create an issue to try our new template:

Reports 53

And export to see our Code style in action:

Reports 54

Code highlighting in Dradis

You can also use the code highlighting feature to highlight particular items within a code block.

In Dradis, you do so with the $${{}}$$ markers. For example, the following issue:

#[Title]#
Test issue

#[Description]#
Text goes here

bc. formatted code inside code blocks should be $${{highlighted}}$$

formatted code outside code blocks should be $${{unaffected}}$$

Would look like this in Dradis:

Reports 183

Naturally, this formatting can also be exported into your Word reports.

Note that the $${{}}$$ markers will only apply highlighting within code blocks.

Code highlighting in Word

For the highlighting to carry across into your Word reports, you will need to add the CodeHighlight style, similar to how you added the Code style above. This style will be used for the highlighted code only.

If you like, you can create a new Quick Style from formatting as you did with Code earlier. To do so, modify a section of the text styled as Code to e.g. add highlighting, then Right-click, Styles, Save Selection as New Quick Style... Name the new Quick Style CodeHighlight. Note the capitalization!

Alternatively, it might make more sense to base the new style on the existing Code style, particularly if you are modifying an existing template to add the CodeHighlight feature. To do so:

  1. Open the Styles Gallery by clicking the down arrow on the right of the window.
  2. Select "Create a Style".
  3. Name the new style CodeHighlight. Capitalization matters!
  4. Set "Style type" to Linked (paragraph and character)
  5. Click "Modify", then for "Style based on", select Code.
  6. Set "Style for following paragraph" to CodeHighlight
  7. Select the new styling options to differentiate CodeHighlight from Code, e.g. adding highlighting from Format, Border..., Shading, Fill.
  8. Click OK when you're done, and save your template.
Reports 187 Reports 185 Reports 186

Here's an example of the Code and CodeHighlight styles in action in word:

Reports 182

Next help article: Custom tables →