def cell_to_text(self):
        """Return the text representation for the cell"""
        if self.cell_type != 'code':
            self.metadata['cell_type'] = self.cell_type

        active = is_active('py', self.metadata)
        if self.language != self.default_language and 'active' not in self.metadata:
            active = False
        if self.cell_type == 'raw' and 'active' in self.metadata and self.metadata['active'] == '':
            del self.metadata['active']

        options = metadata_to_double_percent_options(self.metadata)
        if options.startswith('%') or not options:
            lines = [self.comment + ' %%' + options]
        else:
            lines = [self.comment + ' %% ' + options]

        if self.cell_type == 'code' and active:
            source = copy(self.source)
            comment_magic(source, self.language, self.comment_magics)
            if source == ['']:
                return lines
            return lines + source

        return lines + comment_lines(self.source, self.comment)