<spanid="evennia-utils-text2html"></span><h1>evennia.utils.text2html<aclass="headerlink"href="#module-evennia.utils.text2html"title="Permalink to this headline">¶</a></h1>
<p>ANSI -> html converter</p>
<p>Credit for original idea and implementation
goes to Muhammad Alkarouri and his
snippet #577349 on <aclass="reference external"href="http://code.activestate.com">http://code.activestate.com</a>.</p>
<p>(extensively modified by Griatch 2010)</p>
<dlclass="py class">
<dtid="evennia.utils.text2html.TextToHTMLparser">
<emclass="property">class </em><codeclass="sig-prename descclassname">evennia.utils.text2html.</code><codeclass="sig-name descname">TextToHTMLparser</code><aclass="reference internal"href="../_modules/evennia/utils/text2html.html#TextToHTMLparser"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.text2html.TextToHTMLparser"title="Permalink to this definition">¶</a></dt>
<codeclass="sig-name descname">tabstop</code><emclass="property"> = 4</em><aclass="headerlink"href="#evennia.utils.text2html.TextToHTMLparser.tabstop"title="Permalink to this definition">¶</a></dt>
<codeclass="sig-name descname">re_style</code><emclass="property"> = re.compile('(\x1b\\[0m|\x1b\\[4m|\x1b\\[1m|\x1b\\[22m|\x1b\\[7m|\x1b\\[5m|\x1b\\[1;7m|\x1b\\[1;5m|\x1b\\[7;5m|\x1b\\[1;5;7m|\x1b\\[30m|\x1b\\[31m|\x1b\\[32m|\x1b\\[33m|\x1b\\[34m|\x1b\\[35m|\x1b\\[36m|\x1b\\[37m)</em><aclass="headerlink"href="#evennia.utils.text2html.TextToHTMLparser.re_style"title="Permalink to this definition">¶</a></dt>
<codeclass="sig-name descname">re_string</code><emclass="property"> = re.compile('(?P<htmlchars>[<&>])|(?P<tab>[\\t]+)|(?P<lineend>\\r\\n|\\r|\\n)', re.IGNORECASE|re.MULTILINE|re.DOTALL)</em><aclass="headerlink"href="#evennia.utils.text2html.TextToHTMLparser.re_string"title="Permalink to this definition">¶</a></dt>
<codeclass="sig-name descname">re_url</code><emclass="property"> = re.compile('(?<!=")(\\b(?:ftp|www|https?)\\W+(?:(?!\\.(?:\\s|$)|&\\w+;)[^"\\\',;$*^\\\\(){}<>\\[\\]\\s])+)(\\.(?:\\s|$)|&\\w+;|)')</em><aclass="headerlink"href="#evennia.utils.text2html.TextToHTMLparser.re_url"title="Permalink to this definition">¶</a></dt>
<codeclass="sig-name descname">re_protocol</code><emclass="property"> = re.compile('^(?:ftp|https?)://')</em><aclass="headerlink"href="#evennia.utils.text2html.TextToHTMLparser.re_protocol"title="Permalink to this definition">¶</a></dt>
<codeclass="sig-name descname">re_valid_no_protocol</code><emclass="property"> = re.compile('^(?:www|ftp)\\.[-a-zA-Z0-9@:%._\\+~#=]{2,256}\\.[a-z]{2,6}\\b[-a-zA-Z0-9@:%_\\+.~#?&//=]*')</em><aclass="headerlink"href="#evennia.utils.text2html.TextToHTMLparser.re_valid_no_protocol"title="Permalink to this definition">¶</a></dt>
<codeclass="sig-name descname">re_mxplink</code><emclass="property"> = re.compile('\\|lc(.*?)\\|lt(.*?)\\|le', re.DOTALL)</em><aclass="headerlink"href="#evennia.utils.text2html.TextToHTMLparser.re_mxplink"title="Permalink to this definition">¶</a></dt>
<codeclass="sig-name descname">re_mxpurl</code><emclass="property"> = re.compile('\\|lu(.*?)\\|lt(.*?)\\|le', re.DOTALL)</em><aclass="headerlink"href="#evennia.utils.text2html.TextToHTMLparser.re_mxpurl"title="Permalink to this definition">¶</a></dt>
<codeclass="sig-name descname">remove_bells</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">text</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/utils/text2html.html#TextToHTMLparser.remove_bells"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.text2html.TextToHTMLparser.remove_bells"title="Permalink to this definition">¶</a></dt>
<dd><p>Remove ansi specials</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><p><strong>text</strong> (<em>str</em>) – Text to process.</p>
<codeclass="sig-name descname">remove_backspaces</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">text</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/utils/text2html.html#TextToHTMLparser.remove_backspaces"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.text2html.TextToHTMLparser.remove_backspaces"title="Permalink to this definition">¶</a></dt>
<dd><p>Removes special escape sequences</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><p><strong>text</strong> (<em>str</em>) – Text to process.</p>
<codeclass="sig-name descname">convert_linebreaks</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">text</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/utils/text2html.html#TextToHTMLparser.convert_linebreaks"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.text2html.TextToHTMLparser.convert_linebreaks"title="Permalink to this definition">¶</a></dt>
<dd><p>Extra method for cleaning linebreaks</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><p><strong>text</strong> (<em>str</em>) – Text to process.</p>
<codeclass="sig-name descname">convert_urls</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">text</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/utils/text2html.html#TextToHTMLparser.convert_urls"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.text2html.TextToHTMLparser.convert_urls"title="Permalink to this definition">¶</a></dt>
<dd><p>Replace urls (<aclass="reference external"href="http://">http://</a>…) by valid HTML.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><p><strong>text</strong> (<em>str</em>) – Text to process.</p>
<codeclass="sig-name descname">sub_mxp_links</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">match</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/utils/text2html.html#TextToHTMLparser.sub_mxp_links"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.text2html.TextToHTMLparser.sub_mxp_links"title="Permalink to this definition">¶</a></dt>
<dd><p>Helper method to be passed to re.sub,
replaces MXP links with HTML code.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><p><strong>match</strong> (<em>re.Matchobject</em>) – Match for substitution.</p>
<codeclass="sig-name descname">sub_mxp_urls</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">match</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/utils/text2html.html#TextToHTMLparser.sub_mxp_urls"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.text2html.TextToHTMLparser.sub_mxp_urls"title="Permalink to this definition">¶</a></dt>
<codeclass="sig-name descname">sub_text</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">match</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/utils/text2html.html#TextToHTMLparser.sub_text"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.text2html.TextToHTMLparser.sub_text"title="Permalink to this definition">¶</a></dt>
<dd><p>Helper method to be passed to re.sub,
for handling all substitutions.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><p><strong>match</strong> (<em>re.Matchobject</em>) – Match for substitution.</p>
<codeclass="sig-name descname">format_styles</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">text</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/utils/text2html.html#TextToHTMLparser.format_styles"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.text2html.TextToHTMLparser.format_styles"title="Permalink to this definition">¶</a></dt>
<dd><p>Takes a string with parsed ANSI codes and replaces them with
HTML spans and CSS classes.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><p><strong>text</strong> (<em>str</em>) – The string to process.</p>
<codeclass="sig-name descname">parse</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">text</span></em>, <emclass="sig-param"><spanclass="n">strip_ansi</span><spanclass="o">=</span><spanclass="default_value">False</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/utils/text2html.html#TextToHTMLparser.parse"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.text2html.TextToHTMLparser.parse"title="Permalink to this definition">¶</a></dt>
<dd><p>Main access function, converts a text containing ANSI codes
into html statements.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><ulclass="simple">
<li><p><strong>text</strong> (<em>str</em>) – Text to process.</p></li>
<codeclass="sig-prename descclassname">evennia.utils.text2html.</code><codeclass="sig-name descname">parse_html</code><spanclass="sig-paren">(</span><emclass="sig-param">string</em>, <emclass="sig-param">strip_ansi=False</em>, <emclass="sig-param">parser=<evennia.utils.text2html.TextToHTMLparser object></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/utils/text2html.html#parse_html"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.text2html.parse_html"title="Permalink to this definition">¶</a></dt>
<dd><p>Parses a string, replace ANSI markup with html</p>