Skip to main content
February 14, 2013
Question

Level rules for nested codeblocks

  • February 14, 2013
  • 1 reply
  • 1226 views

I am trying to modify the level rules to apply indentation to codeblock elements, which I have allowed for nesting so we can create good code samples.

I have my level rules set up like this, but everything is still flush with the left margin when I am authoring:

Text format rules

If level is: 1

Basic properties

Indents

First indent: 0

Else, if level is: 2

Basic properties

Indents

Move first indent by: +0.5”

Else, if level is: 3

Basic properties

Indents

Move first indent by: +0.10”

Else, if level is: 4

Basic properties

Indents

Move first indent by: +0.15”

Anyone who's done this more often than me have any ideas? I have tried with both a FirstIndent, FirstIndentChange, LeftIndent, and LeftIndent change and whenever I apply the element definitions to my topic it still does not work.

This topic has been closed for replies.

1 reply

ScottPrentice
Inspiring
February 14, 2013

Hi Kel/y_H ..

In theory, what you're showing should work, so it may be the "Count Ancestors Named" value that's not right. Are you really nesting clodeblocks? Is this DITA (DITA doesn't allow codeblock to contain another codeblock)? Or are you referring to codeblocks nested within some other element (like a list) that you're trying to indent?

I assume that you're not doing this to add indenting to lines within a code sample .. right? Some people try to apply a codeblock tag to each line in a code sample, then use styling to adjust the indent ..

[codeblock]first line[/codeblock]

[codeblock]next line[/codeblock]

[codeblock]last line[/codeblock]

If you're doing this, you might look into putting all of the code into a single codeblock and use forced line breaks (SHIFT+ENTER) to separate the lines ..

[codeblock]first line

next line

last line[/codeblock]

Any indenting within the codeblock would be handled by adding the proper number of leading spaces to each line.

Give us more info about what you're doing, and we might be able to help.

Cheers,

...scott

February 15, 2013

Thanks, Scott! This was helpful.

Yes, we are really nesting codeblocks - we (read: me) modified the EDD to make it allowable, which I suppose could be part of the problem. It works great when we generate our output - we just apply a margin in the CSS and it does all the work to indent everything properly as long as its nested structure is correct. The problem comes in where people are authoring, because they can't get a good look of what their code samples look like, and we're doing API documentation so we have a lot of code samples.

Any indenting within the codeblock would be handled by adding the proper number of leading spaces to each line.

In FrameMaker, we can't add tabs or more than one space (which I personally like; space characters aren't a great solution), so adding leading space characters wouldn't work well either I imagine.

March 1, 2013

I've not heard of people having issues with needing more elements for code samples. In general, it's just a copy/paste into a codeblock, and all's well. It doesn't seem like the author should be spending much time messing with the code samples.

With DITA 1.2 you can use the coderef element, which lets you just insert a reference to an external code file, and the contents of that file are displayed within the codeblock. Unfortunately, in FM10 and FM11, Adobe hasn't quite implemented this feature properly so it doesn't work as it should .. but in concept this is a great feature.

Cheers,

...scott


Thanks, Scott! I am going to keep exploring, but the coderef could be a good solution for us. I would love to hear from other people using DITA (and specifically structured FrameMaker) for API reference doc.

And I agree, we should not be messing with the code samples. I've been advocating that for awhile!