MCPcopy Index your code
hub / github.com/python/cpython / _format_line

Method _format_line

Lib/difflib.py:1911–1935  ·  view source on GitHub ↗

Returns HTML markup of "from" / "to" text lines side -- 0 or 1 indicating "from" or "to" text flag -- indicates if difference on line linenum -- line number (used for line number column) text -- line text to be marked up

(self,side,flag,linenum,text)

Source from the content-addressed store, hash-verified

1909 return fromlist,tolist,flaglist
1910
1911 def _format_line(self,side,flag,linenum,text):
1912 """Returns HTML markup of "from" / "to" text lines
1913
1914 side -- 0 or 1 indicating "from" or "to" text
1915 flag -- indicates if difference on line
1916 linenum -- line number (used for line number column)
1917 text -- line text to be marked up
1918 """
1919 try:
1920 linenum = '%d' % linenum
1921 id = ' id="%s%s"' % (self._prefix[side],linenum)
1922 except TypeError:
1923 # handle blank lines where linenum is '>' or ''
1924 id = ''
1925 # replace those things that would get confused with HTML symbols
1926 text=text.replace("&","&amp;").replace(">","&gt;").replace("<","&lt;")
1927
1928 # make space non-breakable so they don't get compressed or line wrapped
1929 text = text.replace(' ','&nbsp;').rstrip()
1930
1931 # add a class to the td tag if there is a difference on the line
1932 css_class = ' class="diff_changed" ' if flag else ' '
1933
1934 return f'<td class="diff_header"{id}>{linenum}</td>' \
1935 + f'<td{css_class}nowrap="nowrap">{text}</td>'
1936
1937 def _make_prefix(self):
1938 """Create unique anchor prefixes"""

Callers 1

_collect_linesMethod · 0.95

Calls 2

replaceMethod · 0.45
rstripMethod · 0.45

Tested by

no test coverage detected