Short answer: Never (!) copy/paste code into your documentation - as it will be outdated before you hit the save key.

Longer answer (for AsciiDoc):

You can include code fragments be the following scheme:

    [source,groovy]
    ----
    include::{sourcedir}/Sample.groovy[lines=1;7..-1]
    ----

Instead of explicitely giving the line numbers in the include statements, you can annotate the corresponding source files with comment tags, as shown in the following example:

    class Sample {
       // tag::helloMethod[]
       String hello() {
         'Asciidoc rules!'
       }
       // end::helloMethod[]
     }

and then reference this snippet in your documentation as follows:

    [source,groovy]
    ----
    include::Sample.groovy[tags=helloMethod]
    ----

See also the awesome blogpost from mrhaki and another on partial includes