0

I am trying to help format this questions code:

https://stackoverflow.com/posts/22767772/edit

Specifically I'm trying to make it code format for this section.

var svg = d3.select("#body").append("div")
      .attr("class", "chart")
      .style("width", w + "px")
      .style("height", h + "px")
      .append("svg:svg")
      .attr("width", w)
      .attr("height", h)
      .append("svg:g")
      .attr("transform", "translate(.5,.5)");

When I do it though, it seems to have a weird effect of simply indenting it and removing styles from some of the other code.

I just tried copy and pasting it here and it works fine so I'm not sure why it will not work when I try to edit it. Not sure if this is a bug or if it's just me. Tagging as bug for now but maybe someone could see if they are having the same problem as me? Thanks.

  • 1
    See my edit. I stopped the list numbering by adding a non-numbered paragraph. – user102937 Mar 31 '14 at 17:34
  • It's because there's a list right in front of the code. Sucks, but there are only workarounds, no real solutions. – Jeroen Vannevel Mar 31 '14 at 17:36
  • Thanks for the reference post. Sorry for posting a duplicate! I can't delete my question because there's an answer but I'll also vote to close. – aug Mar 31 '14 at 18:02
1

This is because the parser assumes the code was part of the list, under the 2nd point. As a part of a list, you need to indent the code using 8 spaces instead of the normal 4. Alternatively you can place a normal row of text in between like Robert Harvey's edit to your post.

|improve this answer|||||
  • I have no idea what a "nice" html solution is, but if you put for example </> (or some nonsense tag) in place of "Code follows:" it renders as the OP desires. – OGHaza Mar 31 '14 at 17:53
  • 1
    (cc @OGHaza) The best way to do it is an empty HTML comment <!-- -->. – michaelb958--GoFundMonica Mar 31 '14 at 21:04

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