Hi,
For training purposes, we would like to color python syntax inside a label. The pygments python package would work the best for me.
What are some best methods to import this package into ignition? (Linux and Windows)
Below is an example on how to use the pygments package.
# Import packages!
from pygments import highlight
from pygments.lexers import get_lexer_by_name
from pygments.formatters import HtmlFormatter
# Lets get our python lexer.
lexer = get_lexer_by_name("python", stripall=True)
# Lets setup our Html Formatter.
formatter = HtmlFormatter(linenos=False, noclasses=True, nobackground=True)
# We can read code from any source (file or query...ect.).
code = 'print \'this is a test\''
# Format the python code for HTML
result = highlight(code, lexer, formatter)
# Copy and paste into Ignition Label
print('<HTML>'+result+'</HTML>')
RESULT (Can be copied and pasted into an ignition object to color syntax)
<HTML><div class="highlight"><pre style="line-height: 125%"><span></span><span style="color: #008000; font-weight: bold">print</span> <span style="color: #BA2121">'this is a test'</span>
</pre></div>
</HTML>