5

How to get correct indentation after entering a nested list? I am writing a code review and I could not figure this out by googling. Here is an example of the three formatting styles I tried to use (but none of them works as I would like):

Case 1

The task is to align the last line (see below) "In the first line you use camelCase..." with the last line above the numbered list. In my first attempt, I added a new line (empty line) after the second numbered list item, and then indented by 4 spaces:


  • Variable name casing: See wikipedia article on "Snake Case". In Perl, we use "snake_case" instead of "camelCase", and be consistent. Example:

    1. Line 14: my $testType
    2. Line 18: my $right_frame

    In the first line you use camelCase, whereas in the second you use snake_case.


As you can see, this gives the correct indentation but it introduces a blank line above the first numbered item.

Case 2

In this case I do not add the blank line after the second numbered list item ( but still indent by 4 spaces ):


  • Variable name casing: See wikipedia article on "Snake Case". In Perl, we use "snake_case" instead of "camelCase", and be consistent. Example:
    1. Line 14: my $testType
    2. Line 18: my $right_frame In the first line you use camelCase, whereas in the second you use snake_case.

In this case the line is considered as part of the last list item

Case 3

In this case, I try to add two blank spaces (invisible) at the end of the second list item:


  • Variable name casing: See wikipedia article on "Snake Case". In Perl, we use "snake_case" instead of "camelCase", and be consistent. Example:
    1. Line 14: my $testType
    2. Line 18: my $right_frame
      In the first line you use camelCase, whereas in the second you use snake_case.

In this case the line is considered part of the second item, and hence not correctly indented.

How to achieve the correct indentation?

1 Answer 1

3

It looks like your first try is correct and just suffers from the CSS applied—The first list item text is wrapped in a <p> tag which has a bottom margin but the nested list has no bottom margin and the following <p> has no top margin.

A simple (although not ideal) workaround, add a <br> to the beginning of paragraph following the nested list:

- **Variable name casing**: See [wikipedia article](https://en.wikipedia.org/wiki/Snake_case) on *"Snake Case"*.
In Perl, we use *"snake_case"* instead of *"camelCase"*, and be consistent. Example:

    1. Line 14: `my $testType` 
    2. Line 18: `my $right_frame`

    <br>In the first line you use camelCase, whereas in the second you use     snake_case.

Which is rendered as this:

  • Variable name casing: See wikipedia article on "Snake Case". In Perl, we use "snake_case" instead of "camelCase", and be consistent. Example:

    1. Line 14: my $testType
    2. Line 18: my $right_frame


    In the first line you use camelCase, whereas in the second you use snake_case.


If you really don't want the extra space around the nested list I suppose you could forgo the list formatting and recreate it yourself with manual line breaks and extra spaces, like this:

- **Variable name casing**: See [wikipedia article](https://en.wikipedia.org/wiki/Snake_case) on *"Snake Case"*.
In Perl, we use *"snake_case"* instead of *"camelCase"*, and be consistent. Example:
<br>&nbsp;&nbsp;&nbsp;1. Line 14: `my $testType`
<br>&nbsp;&nbsp;&nbsp;2. Line 18: `my $right_frame`
<br>In the first line you use camelCase, whereas in the second you use     snake_case.

Which is rendered as this:

  • Variable name casing: See wikipedia article on "Snake Case". In Perl, we use "snake_case" instead of "camelCase", and be consistent. Example:
       1. Line 14: my $testType
       2. Line 18: my $right_frame
    In the first line you use camelCase, whereas in the second you use snake_case.

But then your nested list isn't really a list—it just looks a bit like one. I wouldn't really suggest doing this (I would correct this in an edit if I saw it), but it's a possibility.

3
  • Thanks! Is there any way to avoid the extra blank lines added around the numbered list? Like in Case 2 and Case 3? Commented Oct 29, 2016 at 11:09
  • I don't think so. The only reason you don't get them in the other cases is because there is no <p> tags inside the list, but as soon as you have more than one paragraph of text it adds the <p> tags around them
    – Cai
    Commented Oct 29, 2016 at 11:13
  • @HåkonHægland added a way to avoid the extra spacing around the list, I wouldn't advise actually using it though :)
    – Cai
    Commented Oct 29, 2016 at 11:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .