Repository: ManimCommunity/manim
File: manim/mobject/text/text_mobject.py (Python)

Code before:

if TYPE_CHECKING:
    from typing import Any

    from typing_extensions import Self

    from manim.typing import Point3D

TEXT_MOB_SCALE_FACTOR = 0.05
DEFAULT_LINE_SPACING_SCALE = 0.3
TEXT2SVG_ADJUSTMENT_FACTOR = 4.8

__all__ = ["Text", "Paragraph", "MarkupText", "register_font"]


def remove_invisible_chars(mobject: VMobject) -> VMobject:
    """Function to remove unwanted invisible characters from some mobjects.

    Parameters
    ----------
    mobject
        Any SVGMobject from which we want to remove unwanted invisible characters.

    Returns
    -------
    :class:`~.SVGMobject`
        The SVGMobject without unwanted invisible characters.
    """
    # TODO: Refactor needed
    iscode = False
    if isinstance(mobject, Text):
        mobject = mobject[:]
    elif isinstance(mobject, Code):
        iscode = True
        code = mobject
        mobject = mobject.code
    mobject_without_dots = VGroup()
    if mobject[0].__class__ == VGroup:
        for i in range(len(mobject)):
            mobject_without_dots.add(VGroup())
            mobject_without_dots[i].add(*(k for k in mobject[i] if k.__class__ != Dot))
    else:
        mobject_without_dots.add(*(k for k in mobject if k.__class__ != Dot))
    if iscode:
        assert isinstance(code, Code)
        code.code = mobject_without_dots
        return code
    return mobject_without_dots


class Paragraph(VGroup):

Review comment (refactor):
It would be nice to have a small PR refactoring this code. I suggest defining an inner function called something like `get_mobject_without_dots(mob)` or `exclude_dots_from_mobject(mob)` and then doing something like:
```py
    if isinstance(mobject, Text):
        submob_group = mobject[:]
        return exclude_dots_from_mobject(submob_group)
    elif isinstance(mobject, Code):
        mobject.code = exclude_dots_from_mobject(mobject.code)
        return mobject
    else:
        return exclude_dots_from_mobject(mobject)
```

Code after:
if TYPE_CHECKING:
    from typing_extensions import Self

    from manim.typing import Point3D

TEXT_MOB_SCALE_FACTOR = 0.05
DEFAULT_LINE_SPACING_SCALE = 0.3
TEXT2SVG_ADJUSTMENT_FACTOR = 4.8

__all__ = ["Text", "Paragraph", "MarkupText", "register_font"]


def remove_invisible_chars(mobject: VMobject) -> VMobject:
    """Function to remove unwanted invisible characters from some mobjects.

    Parameters
    ----------
    mobject
        Any SVGMobject from which we want to remove unwanted invisible characters.

    Returns
    -------
    :class:`~.SVGMobject`
        The SVGMobject without unwanted invisible characters.
    """
    # TODO: Refactor needed
    iscode = False
    if isinstance(mobject, Text):
        mobject = mobject[:]
    elif isinstance(mobject, Code):
        iscode = True
        code = mobject
        mobject = mobject.code
    mobject_without_dots = VGroup()
    if isinstance(mobject[0], VGroup):
        for submob in mobject:
            mobject_without_dots.add(
                VGroup(k for k in submob if not isinstance(k, Dot))
            )
    else:
        mobject_without_dots.add(*(k for k in mobject if not isinstance(k, Dot)))
    if iscode:
        assert isinstance(code, Code)
        code.code = mobject_without_dots
        return code
    return mobject_without_dots


class Paragraph(VGroup):
    r"""Display a paragraph of text.