def getFragments(self, fragment):
        result = []

        text = fragment.text().replace('\u2028', '\n')

        charFormat = fragment.charFormat()
        style = charFormat.property(QTextFormat.UserProperty)

        href = None
        if style and style[0] == 'link':
            href = charFormat.anchorHref()  #escape(charFormat.anchorHref())
            style = None     # Link implicitly defined by setting href

        isObject = (text.find('\ufffc') != -1)
        if isObject:
            if charFormat.isImageFormat():
                assert(False)   # This condition should never be true anymore - we are reendering images as custom objects

    #===========================================================================
    #             imgFmt = charFormat.toImageFormat()
    #             imgName = tools.os_path_split(imgFmt.name())[-1]
    # 
    #             # If the same image repeats multiple times, it is simply represented by
    #             # yet another object replacement character ...
    #             for img in range(0, len(text)):
    #                 frag = ImageFragment()
    #                 frag.image = imgName
    #                 frag.setHref(href)
    #                 result.append(frag)
    #===========================================================================
            else:
                customObject = charFormat.property(QTextCharFormat.UserProperty+1)
                if type(customObject) is ImageObject:
                    frag = ImageFragment()
                    frag.image = tools.os_path_split(customObject.imageName)[-1]
                    frag.setHref(href)
                    result.append(frag)
                elif type(customObject) is MathFormulaObject:
                    frag = MathFragment()
                    frag.setText(customObject.formula)
                    frag.image = customObject.image
                    result.append(frag)
        else:
            frag = TextFragment(style)
            frag.setHref(href)
            frag.setText(text)
            result.append(frag)

        return result
    def getFragments(self, fragment):
        result = []

        text = fragment.text().replace('\u2028', '\n')

        charFormat = fragment.charFormat()
        style = charFormat.property(QTextFormat.UserProperty)

        href = None
        if style and style[0] == 'link':
            href = charFormat.anchorHref()  #escape(charFormat.anchorHref())
            style = None     # Link implicitly defined by setting href

        isObject = (text.find('\ufffc') != -1)
        if isObject:
            if charFormat.isImageFormat():
                assert(False)   # This condition should never be true anymore - we are reendering images as custom objects
            else:
                customObject = charFormat.property(QTextCharFormat.UserProperty+1)
                if type(customObject) is ImageObject:
                    frag = ImageFragment()
                    frag.image = tools.os_path_split(customObject.imageName)[-1]
                    frag.setHref(href)
                    result.append(frag)
                elif type(customObject) is MathFormulaObject:
                    frag = MathFragment()
                    frag.setText(customObject.formula)
                    frag.image = customObject.image
                    result.append(frag)
        else:
            frag = TextFragment(style)
            frag.setHref(href)

            # Extract possible first and last partial text
            fragStart = fragment.position()
            fragEnd = fragment.position() + fragment.length() - 1
 
            print(" Frag: {}-{}   Sel: {}-{}".format(fragStart, fragEnd, self.selectionStart, self.selectionEnd))

            print("   1Text: {}".format(text))
 
            if self.selectionStart > fragStart:      # partial first fragment
                skipCount = self.selectionStart - fragStart
                text = text[skipCount:]

            print("   2Text: {}".format(text))

            if fragStart > self.selectionEnd:
                self.done = True
                return result

            if fragEnd >= self.selectionEnd:       # partial last fragment (TODO: check condition!)
                count = self.selectionEnd - fragStart
                if count == 0:
                    self.done = True
                    return result
                text = text[:count]
                fragEnd = self.selectionEnd
                self.done = True

            print("   3Text: {}".format(text))


            frag.setText(text)
            result.append(frag)

        return result