# -*- coding: utf-8 -*-

# Copyright 2013 Vincent Jacques
# vincent@vincent-jacques.net

# This file is part of RecursiveDocument. http://jacquev6.github.com/RecursiveDocument

# RecursiveDocument is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License
# as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

# RecursiveDocument is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.

# You should have received a copy of the GNU Lesser General Public License along with RecursiveDocument.  If not, see <http://www.gnu.org/licenses/>.

import textwrap


class Container:
    def __init__(self):
        self.__contents = []

    def add(self, newContent):
        self.__contents.append(newContent)
        return self

    def _formatContents(self, prefix):
        return "\n\n".join(c._format(prefix) for c in self.__contents)

class Paragraph:
    def __init__(self, text):
        self.__text = text

    def _format(self, prefix):
        return "\n".join(textwrap.wrap(self.__text, initial_indent=prefix, subsequent_indent=prefix))


class Section(Container):
    def __init__(self, title):
        Container.__init__(self)
        self.__title = title

    def _format(self, prefix):
        return "\n".join(textwrap.wrap(self.__title + ":", initial_indent=prefix, subsequent_indent=prefix)) + "\n" + self._formatContents(prefix + "  ")


class Document(Container):
    def format(self):
        return self._formatContents("") + "\n"

@@ -861,24 +861,144 @@
 xtwrap%0D%0A%0D%0A%0D%0A
+def _wrap(text, prefix):%0D%0A    return %22%5Cn%22.join(textwrap.wrap(text, initial_indent=prefix, subsequent_indent=prefix))%0D%0A%0D%0A
 class Contai
@@ -1403,93 +1403,33 @@
 urn 
-%22%5Cn%22.join(textwrap.wrap(self.__text, initial_indent=prefix, subsequent_indent=prefix)
+_wrap(self.__text, prefix
 )%0D%0A%0D
@@ -1603,35 +1603,17 @@
  return 
-%22%5Cn%22.join(textwrap.
+_
 wrap(sel
@@ -1633,56 +1633,14 @@
 :%22, 
-initial_indent=prefix, subsequent_indent=prefix)
+prefix
 ) + 

Refactor wrapping