Edit online

Show Consecutive DITA Code Blocks in Separate Tabs

Contributed by: Radu Coravu on 9 Mar 2022

When inserting <codeblock> elements in DITA content with code from various languages, you can use the @outputclass attribute to provide syntax highlighting for each codeblock in the generated WebHelp and PDF outputs: https://www.oxygenxml.com/doc/ug-editor/topics/add-syntax-highlights-codeblocks-x.html.

Suppose you have consecutive <codeblock> elements, each one of them displaying how something can be accomplished in a particular programming language, like this:
<codeblock xml:space="preserve" outputclass="ruby">require 'rest-client'
require 'json'

headers = {
  'Content-Type' =&gt; 'application/octet-stream',
  'Accept' =&gt; 'application/json',
  'Authorization' =&gt; 'Bearer {access-token}'
    <codeblock xml:space="preserve" outputclass="python">import requests
headers = {
  'Content-Type': 'application/octet-stream',
  'Accept': 'application/json',
  'Authorization': 'Bearer {access-token}'

You can install this open-source DITA Open Toolkit plugin to display codeblocks as separate tabs in the published WebHelp output: https://github.com/oxygenxml/dita-wh-codeblock-tabs.

The WebHelp output should look like this: