# GolfScript - 243 characters

I translated my CoffeeScript answer into GolfScript, which is much more suited to the string manipulations.

Entirely golfed:

    ..0="HL"?2+3%:o 2%1\-.@="CDEFGAB"?7o*+:k 2%45 32if:r;
    1+.2$,<{=}{;;r}if:a;
    [" "5*:|" --- ":g]4*[|"-"5*]5*+[|g|]+.
    [k<~]\[k>([0=:w a 79r w]''+\~]
    +17k<1k+18if<9k>k 9if:j>:t;
    13k>.2*1+:x;
    4,1>{k j-\2${+}{-}if}%\;
    {.t<\t>(:v[x<'|'+1x+v>+]\++:t;}
    /t-1%n*

With comments:

    # extract octave
    ..0="HL"?2+3%:o

    # extract note
    2%1\-.@="CDEFGAB"?7o*+:k

    # line spacer
    2%45 32if:r;

    # extract accidental
    1+.2$,<{=}{;;r}if:a;

    # staff
    [" "5*:|" --- ":g]4*[|"-"5*]5*+[|g|]+.

    # lines below
    [k<~]\

    # note line and above
    [k>([0=:w a 79r w]''+\~]+

    # cut off just what we need
    17k<1k+18if<
    9k>k 9if:j>:t;

    # and the note stem
    13k>.2*1+:x;4,1>{k j-\2${+}{-}if}%\;

    {
      .t<\
      t>(:v[x<'|'+1x+v>+]\++:t;
    }/

    # now output the note
    t-1%n*