Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add formatter for Pango Markup #1727

Merged
merged 6 commits into from Mar 5, 2021
Merged

Add formatter for Pango Markup #1727

merged 6 commits into from Mar 5, 2021

Conversation

PhilippImhof
Copy link
Contributor

New formatter for Pango Markup as described in https://developer.gnome.org/pango/stable/pango-Markup.html

Using Pango, the output of this formatter can then be converted to an SVG file.

Together with https://github.com/ManimCommunity/manim, the output can also be used to create fancy animations.
from pygments import highlight
from pygments.lexers import JavascriptLexer
from pygments.formatters import PangoMarkupFormatter

code = """
function bla(n, m) {
   console.log(n*m);
}
"""
print(highlight(code, JavascriptLexer(), PangoMarkupFormatter()))

yields

<tt><span fgcolor="#008000"><b>function</b></span> bla(n, m) {
   console.log(n<span fgcolor="#666666">*</span>m);
}
</tt>

and with this one can do

from manim import *
from manimpango import *

class TestCode(Scene):
    def construct(self):
        text = MarkupText(
            """<tt><span fgcolor="#008000"><b>function</b></span> bla(n, m) {
   console.log(n<span fgcolor="#666666">*</span>m);
}
</tt>""")
        self.play(Write(text))
        self.wait()

to get:

TestCode.mp4

Copy link
Collaborator

@Anteru Anteru left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please add a minimal test case for this?

pygments/formatters/pangomarkup.py Outdated Show resolved Hide resolved
@PhilippImhof
Copy link
Contributor Author

Yes, I will prepare a test case.

tests/test_pangomarkup_formatter.py Outdated Show resolved Hide resolved
@PhilippImhof PhilippImhof requested a review from Anteru March 1, 2021 10:43
@Anteru Anteru merged commit fea3b53 into pygments:master Mar 5, 2021
@Anteru
Copy link
Collaborator

Anteru commented Mar 5, 2021

Merged, thanks a lot!

@Anteru Anteru added this to the 2.9 milestone Mar 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants