You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have an application where I'd like to do syntax coloring but get the result back as a Text() object that I can do additional operations on. I didn't see anything in the documentation about how to do this, but I did see the highlight() method in the source code which seems to return a Text, just like I wanted. However, it's an instance method rather than a class method, and it takes "code" as an argument. So, I end up with something like:
text_obj=Syntax(code, lexer).highlight(code)
Note that code here has to be passed in twice. Alternately, I can do something ugly like:
text_obj=Syntax('', lexer).highlight(code)
This works because the "code" argument in highlight() seems to take precedence over the one in the constructor. However, neither of these solutions seems right. Also, even though highlilght() is a public method, it's not documented, so I worry it may change in the future.
Is there a better way to do what I'm trying to do here?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
I have an application where I'd like to do syntax coloring but get the result back as a Text() object that I can do additional operations on. I didn't see anything in the documentation about how to do this, but I did see the highlight() method in the source code which seems to return a Text, just like I wanted. However, it's an instance method rather than a class method, and it takes "code" as an argument. So, I end up with something like:
Note that code here has to be passed in twice. Alternately, I can do something ugly like:
This works because the "code" argument in highlight() seems to take precedence over the one in the constructor. However, neither of these solutions seems right. Also, even though highlilght() is a public method, it's not documented, so I worry it may change in the future.
Is there a better way to do what I'm trying to do here?
Beta Was this translation helpful? Give feedback.
All reactions