pycontribs / ansi2html Goto Github PK
View Code? Open in Web Editor NEWConvert text with ansi color codes to HTML
License: GNU Lesser General Public License v3.0
Convert text with ansi color codes to HTML
License: GNU Lesser General Public License v3.0
There are significant issues with linkification if passed input containing two or more occurrences of the same URL. Even worse, if the input has many occurrences of the same URL it can easily eat up all memory on the system! 🙀
>>> from ansi2html import Ansi2HTMLConverter
>>> converter = Ansi2HTMLConverter(linkify=True)
>>> s = 'http://www.github.com http://www.github.com'
>>> converter.convert(s, full=False)
'<a href="<a href="http://www.github.com">http://www.github.com</a>"><a href="http://www.github.com">http://www.github.com</a></a> <a href="<a href="http://www.github.com">http://www.github.com</a>"><a href="http://www.github.com">http://www.github.com</a></a>'
Note the incorrectly nested <a href="<a href=
. This example shows that an input with two occurrences of a URL creates incorrect output with eight occurrences of the same URL.
The exponential expansion can quickly cause memory issues. The following code uses over 16gb of memory!
>>> s = '\n'.join(['http://www.github.com'] * 30)
>>> converter.convert(s, full=False)
There are also issues if one URL is a substring of the other:
>>> s = '''
... http://www.github.com/ralphbean/ansi2html
... http://www.github.com
... '''
>>> print(converter.convert(s, full=False))
<a href="<a href="http://www.github.com">http://www.github.com</a>/ralphbean/ansi2html"><a href="http://www.github.com">http://www.github.com</a>/ralphbean/ansi2html</a>
<a href="http://www.github.com">http://www.github.com</a>
So people are not forced to use utf-8.
hi,
I am trying to convert the karma testing result to HTML.
Here is the karma report saved in txt file
> [email protected] gulp /usr/rd/leocornus-nodejs-sandbox
> gulp
[12:57:01] Using gulpfile /usr/rd/leocornus-nodejs-sandbox/gulpfile.js
[12:57:01] Starting 'karma'...
[12:57:01] Starting 'karma.jquery'...
[12:57:01] Starting 'jasmine'...
^[[32mINFO [karma]: ^[[39mKarma v0.12.37 server started at http://localhost:9876/
^[[32mINFO [launcher]: ^[[39mStarting browser Firefox
^[[32m.^[[0m
1 spec, 0 failures
Finished in 0 seconds
[12:57:01] Finished 'jasmine' after 89 ms
^[[33mWARN [karma]: ^[[39mPort 9876 in use
^[[32mINFO [karma]: ^[[39mKarma v0.12.37 server started at http://localhost:9877/
^[[32mINFO [launcher]: ^[[39mStarting browser Firefox
^[[32mINFO [Firefox 30.0.0 (Ubuntu 0.0.0)]: ^[[39mConnected on socket eMzdhfb30orKKWXBiMlS with id 97169530
^[[32mINFO [Firefox 30.0.0 (Ubuntu 0.0.0)]: ^[[39mConnected on socket WomLA0aSM7sr7wiSiMlG with id 72190175
^[[4m^[[1mStart:^[[22m^[[24m
^[[1m A suite^[[22m
^[[32m ^[[32m✔^[[32m contains a pect with an expectation^[[39m
.
Firefox 30.0.0 (Ubuntu 0.0.0): Executed 1 of 1 SUCCESS (0.003 secs / 0.001 secs)
^[[32mFinished in 0.003 secs / 0.001 secs^[[39m
^[[4m^[[1mSUMMARY:^[[22m^[[24m
^[[32m^[[32m✔^[[32m 1 test completed^[[39m
[12:57:05] Finished 'karma' after 3.74 s
^[[4m^[[1mStart:^[[22m^[[24m
^[[1m Testing Bootstrap Form^[[22m
^[[32m ^[[32m✔^[[32m testing query and search^[[39m
^[[1m try the sub section of a spec^[[22m
^[[32m ^[[32m✔^[[32m testing query and add class^[[39m
^[[1m Testing Bootstrap Modal^[[22m
^[[32m ^[[32m✔^[[32m testing show and hide modal^[[39m
^[[1m Testing Bootstrap Basic^[[22m
^[[32m ^[[32m✔^[[32m testing find method^[[39m
^[[32m ^[[32m✔^[[32m testing data-toggle^[[39m
^[[1m Testing jquery from HTML fixture^[[22m
^[[32m ^[[32m✔^[[32m testing jquery selector^[[39m
^[[32m ^[[32m✔^[[32m testing jquery functions^[[39m
^[[1m Testing jQuery Basic^[[22m
^[[32m ^[[32m✔^[[32m simple jquery object^[[39m
^[[32m ^[[32m✔^[[32m simple DOM element^[[39m
^[[32m ^[[32m✔^[[32m some jQuery method^[[39m
LOG: 'desc: sandbox plugin'
LOG: 'id: divid'
ALERT: 'div inner html'
^[[1m simple jquery plugin test^[[22m
^[[32m ^[[32m✔^[[32m testing plugin click event^[[39m
^[[32mFinished in 0.127 secs / 0.123 secs^[[39m
^[[4m^[[1mSUMMARY:^[[22m^[[24m
^[[32m^[[32m✔^[[32m 11 tests completed^[[39m
[12:57:05] Finished 'karma.jquery' after 3.85 s
[12:57:05] Starting 'default'...
[12:57:05] Finished 'default' after 9.64 μs
My code is very simple
>>> npm_file = open('/tmp/npm.txt', 'r')
>>> npm = " ".join(npm_file.read())
>>> npm_html = conv.convert(npm);
>>> npm_file = open('/tmp/npm.html', 'w')
>>> try:
... npm_file.write(npm_html)
... finally:
... npm_file.close()
I got the following error message:
Failed example:
npm_html = conv.convert(npm);
Exception raised:
Traceback (most recent call last):
File "/usr/lib/python2.7/doctest.py", line 1315, in __run
compileflags, 1) in test.globs
File "<doctest README.rst[18]>", line 1, in <module>
npm_html = conv.convert(npm);
File "/usr/rd/cfgrepo/sample/python/eggs/ansi2html-1.1.0-py2.7.egg/ansi2html/converter.py", line 428, in convert
'output_encoding' : self.output_encoding,
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 1854: ordinal not in range(128)
could anybody help solve this issue?
thanks,
Sean
The formula for 6x6x6 color cube seems different from what most terminals use.
See discussion here:
https://stackoverflow.com/questions/27159322/rgb-values-of-the-colors-in-the-ansi-extended-colors-index-17-255 (section "Default RGB values")
Also see function sixd_to_16bit
in https://git.suckless.org/st/file/x.c.html.
I'm not sure if it's even really feasible at all, but here is an example:
Here's what it looks like in my terminal:
Here's the corresponding output once passed in ansi2html:
Here is the raw output:
https://gist.github.com/15467055821752207b566421a0ac664c
Any idea?
BTW, thanks for this fine lib. I love the solarized theme :)
Currently, is only closed when 0 is found. It would probably be more robust to close each time there is a change of foreground, background or anything and re-open a new one. This will probably generate more data, but the result will match real terminal output more closely.
Currently unicode support in python2 is "works for me" at best.
The code uses mixed operations involving str
and unicode
all the time and relies on python2 doing the same no matter what (and it normally does):
>>> 'a%sc' % u'b'
u'abc'
>>> u'a%sc' % 'b'
u'abc'
Some inconsistencies I encountered:
main()
goes a very long way to ensure that the input to convert()
is unicode
yet there are some unittests which give it str
and some which give it unicode
.
The _html_template
is a unicode
yet _latex_template
is a str
.
This leads to the following:
>>> Ansi2HTMLConverter().convert("abc", full=False) # this returns `str`
>>> Ansi2HTMLConverter().convert("abc", full=True) # this returns `unicode`
I think, we should clarify what to expect from convert()
.
Does it accept str
and unicode
or just unicode
?
When given a str
, should it also return a str
or always a unicode
?
I know unicode support in python2 is hard and annoying but if we want to support it, we should
support it properly.
Hi,
I get the following error while installing this library :
Traceback (most recent call last):
...
File "C:\Python27\lib\distutils\command\install_data.py", line 58, in run
dir = convert_path(f[0])
File "C:\Python27\lib\distutils\util.py", line 126, in convert_path
raise ValueError, "path '%s' cannot end with '/'" % pathname
ValueError: path 'share/man/man1/' cannot end with '/'
It seems this error is linked to
data_files=[
('share/man/man1/', [
'man/ansi2html.1',
]),
],
in the setup.py
Any idea how to fix it ?
Thanks for your help :)
JC
It seems header.mak is not being included when ansi2html is installed via easy_install on Python 2.6, which results in:
File "/Library/Python/2.6/site-packages/tw2.core-2.0b4-py2.6.egg/tw2/core/dottedtemplatelookup.py", line 103, in __load self.template_cache[template_name] = Template(open(filename).read(), IOError: [Errno 2] No such file or directory: u'/Users/ana/.python-eggs/ansi2html-0.6.0-py2.6.egg-tmp/ansi2html/templates/header.mak'
When I look in the directory it's trying to search:
$ tree /Users/ana/.python-eggs/ansi2html-0.6.0-py2.6.egg-tmp/ansi2html/ /Users/ana/.python-eggs/ansi2html-0.6.0-py2.6.egg-tmp/ansi2html/ └── templates └── full.mak
Installing via pip or from source seems to fix this, and the setup.py and MANIFEST.in files look fine to me, so this is probably more of an easy_install issue, but maybe releasing an egg for 2.6 instead of source would be a simple workaround? Or maybe explicitly listing the template files instead of a wildcard?
Note this was reported to me here:
http://discuss.dexy.it/index.php?p=/discussion/13/ioerror-errno-2-no-such-file-or-directory-...-header.mak
And I have just come across this issue myself on a new machine (OSX 10.6.7) running Python 2.6.1
Consider merging the nodeps
branch into master and releasing 0.8.0
The 1.0.7 source tarball release on pypi contains ./tests/__pycache__/test_ansi2html.cpython-33.pyc
, which causes attempts to build using stdeb to fail.
When converting to LaTeX in non-inline mode, ansi2html
produces commands like \textcolor{ansi33}
, although ansi*
colors are not defined.
Maybe just use \textcolor[HTML]{aa5500}
like in inline mode?
Hello,
I need to process a really big file (8GB) with ansi2html like:
cat -u output | ansi2html -l -p > ../out.html
I understand that the input file is really large... but I was wondering if it would be possible to make ansi2html process line by line instead of trying to process the whole one... or maybe in chunks. I have 16GB of memory but, it is true that, I see that ansi2html tries to use 100% of memory just before dying with:
$ cat output | ansi2html -p ../out.html
Traceback (most recent call last):
File "/usr/lib/python-exec/python3.4/ansi2html", line 11, in
load_entry_point('ansi2html==1.2.0', 'console_scripts', 'ansi2html')()
File "/usr/lib64/python3.4/site-packages/ansi2html/converter.py", line 548, in main
output = conv.convert("".join(sys.stdin.readlines()), full=full, ensure_trailing_newline=True)
MemoryError
Thanks
In some tests, main() is directly called, and args from nosetests are kept. It's preventing any argument to be used with nosetests. A solution would be to either to clear sys.argv before main() call. Or main() could take arguments in parameters.
$ nosetests --verbosity=1
.Usage:
$ ls --color=always | ansi2html > directories.html
$ sudo tail /var/log/messages | ccze -A | ansi2html > logs.html
$ task burndown | ansi2html > burndown.html
nosetests: error: no such option: --verbosity
E.............
======================================================================
ERROR: test_conversion_as_command (test_ansi2html.TestAnsi2HTML)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/usr/lib64/python2.7/site-packages/mock.py", line 1224, in patched
return func(*args, **keywargs)
File "/var/tmp/portage/dev-python/ansi2html-0.9.1/work/ansi2html-0.9.1/tests/test_ansi2html.py", line 57, in test_conversion_as_command
main()
File "/var/tmp/portage/dev-python/ansi2html-0.9.1/work/ansi2html-0.9.1/ansi2html/converter.py", line 275, in main
opts, args = parser.parse_args()
File "/usr/lib64/python2.7/optparse.py", line 1401, in parse_args
self.error(str(err))
File "/usr/lib64/python2.7/optparse.py", line 1583, in error
self.exit(2, "%s: error: %s\n" % (self.get_prog_name(), msg))
File "/usr/lib64/python2.7/optparse.py", line 1573, in exit
sys.exit(status)
SystemExit: 2
----------------------------------------------------------------------
Ran 15 tests in 0.108s
FAILED (errors=1)
an ansi2html special-mode that splits console-color-codes off to separate .css-file, and applies semantic tags to taskwarrior report fields, for later manipulation via javascript.
task list | tw2html > task-list.html
I attempted to build ansi2html against Python 3.3.0b1 (as part of https://fedoraproject.org/wiki/Features/Python_3.3 ) but ran into intermittent failures in the selftest suite due to an implicit reliance on dict ordering - hash randomization is enabled by default with Python 3.3
I was able to reliably force these failures to happen on x86_64 with PYTHONHASHSEED=1 python3 setup.py test
I have a patch which I'll link to shortly
======================================================================
FAIL: test_conversion (test_ansi2html.TestAnsi2HTML)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/david/coding/python3.3/python-ansi2html/ansi2html-0.9.1/tests/test_ansi2html.py", line 46, in test_conversion
self.assertEqual(expected, actual)
AssertionError: '.body_foreground > .bold,.bold > .body_foreground, body.body_foreground > pre > [truncated]... != '.body_foreground > .bold,.bold > .body_foreground, body.body_foreground > pre > [truncated]...
- .body_foreground > .bold,.bold > .body_foreground, body.body_foreground > pre > .bold { color: #FFFFFF; font-weight: normal; }
? ----------------
+ .body_foreground > .bold,.bold > .body_foreground, body.body_foreground > pre > .bold { font-weight: normal; color: #FFFFFF; }
? ++++++++++++++++
======================================================================
FAIL: test_conversion_as_command (test_ansi2html.TestAnsi2HTML)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/usr/lib/python3.3/site-packages/mock.py", line 1224, in patched
return func(*args, **keywargs)
File "/home/david/coding/python3.3/python-ansi2html/ansi2html-0.9.1/tests/test_ansi2html.py", line 62, in test_conversion_as_command
eq_(html, expected_data, "Strings are not the same.")
File "/usr/lib/python3.3/site-packages/nose/tools.py", line 31, in eq_
assert a == b, msg or "%r != %r" % (a, b)
AssertionError: Strings are not the same.
======================================================================
FAIL: test_produce_headers (test_ansi2html.TestAnsi2HTML)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/david/coding/python3.3/python-ansi2html/ansi2html-0.9.1/tests/test_ansi2html.py", line 148, in test_produce_headers
self.assertEqual(expected, actual)
AssertionError: '.body_foreground > .bold,.bold > .body_foreground, body.body_foreground > pre > [truncated]... != '.body_foreground > .bold,.bold > .body_foreground, body.body_foreground > pre > [truncated]...
- .body_foreground > .bold,.bold > .body_foreground, body.body_foreground > pre > .bold { color: #FFFFFF; font-weight: normal; }
? ----------------
+ .body_foreground > .bold,.bold > .body_foreground, body.body_foreground > pre > .bold { font-weight: normal; color: #FFFFFF; }
? ++++++++++++++++
----------------------------------------------------------------------
Ran 15 tests in 0.223s
FAILED (failures=3)
Hi!
I use a buildbot running ansi2html with lettuce's default output to serve some test on a website and I noticed a swap between body_foreground & ansi30 css' colors (#000 and #AAA respectively here).
Also, since I upgraded of 0.6.x (if I remember correctly) to latest release, I had to patch the code to add an encode('utf-8') to the final print statement to make the program run without "ansi" decode error.
I am running python2.6 and the content of my environment is:
USER=fab31
LOGNAME=fab31
HOME=/home/fab31
PATH=/home/fab31/.pythonbrew/bin:/home/fab31/pyenv/bbot/bin:/home/fab31/utils:/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/games:/home/fab31/.local/bin:/sbin:/usr/sbin:/usr/local/bin:/opt/java/jre/bin
MAIL=/var/mail/fab31
SHELL=/bin/zsh
SSH_CLIENT=79.84.236.37 53268 22
SSH_CONNECTION=79.84.236.37 53268 88.190.18.171 22
SSH_TTY=/dev/pts/4
TERM=xterm
LANG=fr_FR.UTF-8
SHLVL=1
PWD=/home/fab31/pyenv/bbot/master
OLDPWD=/home/fab31/pyenv/bbot/slave
G_BROKEN_FILENAMES=1
LC_NUMERIC=C
CLICOLOR=1
SVN_EDITOR=~/utils/svn_editor.sh
GDK_USE_XFT=1
PAGER=less
X2=x2x -west -to :0 -west
VISUAL=vim
EDITOR=vim
PYTHONSTARTUP=/home/fab31/.pystartup
HG_REPOS=/home/fab31/prog/hg-stable
PS1=(bbot)%n@%m:%~%#
LS_COLORS=no=00:fi=00:di=01;34:ln=01;36:pi=40;33:so=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:ex=01;32:*.cmd=01;32:*.exe=01;32:*.com=01;32:*.btm=01;32:*.bat=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.zip=01;31:*.bz2=01;31:*.rpm=01;31:*.deb=01;31:*.z=01;31:*.Z=01;31:*.gz=01;31:*.jpg=01;35:*.gif=01;35:*.bmp=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.mpg=01;37:*.avi=01;37:*.mov=01;37:*.tbz=01;31:*.zip=01;31:*.mp3=00;34:*.png=01;35:*.89t=00;33
VIRTUALENVWRAPPER_VIRTUALENV_ARGS=--no-site-packages
WORKON_HOME=/home/fab31/pyenv
VIRTUALENVWRAPPER_LOG_DIR=/home/fab31/pyenv
PROJECT_HOME=/home/fab31/pyenv
PIP_VIRTUALENV_BASE=/home/fab31/pyenv
PIP_RESPECT_VIRTUALENV=true
VIRTUAL_ENV=/home/fab31/pyenv/bbot
_=/usr/bin/env
Hi!
Latest release 1.5.1 specifies in setup.py
:
"Programming Language :: Python :: 2",
"Programming Language :: Python :: 2.6",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.1",
"Programming Language :: Python :: 3.2",
"Programming Language :: Python :: 3.3",
.travis.yml
tests against:
python:
- "2.7"
- "3.5"
- "3.6"
It would be tool to get them in sync, support for Python 3.7 added, leftovers of 2.6 and 3.{1..4} be dropped, and supported versions documented in README.rst
as well. Thank you!
Could you please post a new version to PyPI?
Last release was in December and some key commits that fix Windows installation have been made since then.
Hi,
First of all, thanks for your software.
Would it be possible for you to create a new release and publish it on Pypi? That would make installation much easier than installing from source.
Thank you,
Mathieu
Commit 61f4b53 is great for reducing the size of the output, but unfortunately it no longer includes the CSS styles for specifying the background colors.
Demo:
$ echo -e 'one\ntwo\nthree' | ansi2html --partial # fine with --partial
one
two
three
$ echo -e 'one\ntwo\nthree' | ansi2html --inline # fine with --inline
one
two
three
$ echo -e 'one\ntwo\nthree' | ansi2html | grep -vE '^[<\\.]' | sed '/^$/d' # spaces inserted
one
two
three
I'll send a patch candidate by mail in a minute.
hi,
pytest-dev/pytest-html#96 has just brought this to my attention,
as things are pytest-html would have to drop usage and/or implement an sub-process communication to keep using ansi2html while also keeping its own license terms
i would like to solve this by just version-bumping the ansi2html dependency but i can understand if you want to keep the gpl
Please consider adding backtick (or similar) conversion to <code>
or <pre>
.
root@szerver4:~/hc/_bck/megacp-vitalblog# cat file
`code block
multiple lines`
Some colors are during conversion made by ansi2html as the terminal output looks very different than the produced html file.
#!/usr/bin/env bash
echo -e "\x1B[31m foobar \x1B[0m"
echo -e "\x1B[32m foobar \x1B[0m"
echo -e "\x1B[96m foobar \x1B[0m"
echo -e "\x1B[01;96m foobar \x1B[0m"
echo -e "\x1B[01;95m foobar \x1B[0m"
echo -e "\x1B[01;94m foobar \x1B[0m"
echo -e "\x1B[01;93m foobar \x1B[0m"
echo -e "\x1B[01;91m foobar \x1B[0m"
echo -e "\x1B[01;90m foobar \x1B[0m"
echo -e "\x1B[01;89m foobar \x1B[0m"
echo -e "\x1B[01;36m foobar \x1B[0m"
This shell script illustrates this:
#!/bin/sh
printf "\e[37;41m00\e[0m \e[37;44m01\e[0m \e[30;42m02\e[0m \e[30;45m03\e[0m \e[30;46m04\e[0m \e[30;43m05\e[0m \e[30;47m06\e[0m \e[37;101m07\e[0m \e[37;104m08\e[0m \e[30;102m09\e[0m \e[30;105m10\e[0m \e[30;106m11\e[0m \e[30;103m12\e[0m\n"
This shows 12 colors, 6 of which are rendered correctly when piped through ansi2html. It appears the non-functioning colors are the "bright background" colors.
Take another stab at packaging an RPM.
--markup-lines
option should make line numbers visible and clickable, just like travis. This would allow users to share bookmarks pointing to specific line.
I also think that the bookmark name should be as short at possible in order to avoid increasing the size of the generated document, if possible just the line number, if not prefixed by a capital L.
Bookmarks should look like: http://example.com/my.log#123
or http://example.com/my.log#L123
This is not an issue, but a feature:
Another cool feature would be to make it do any of two things:
--linkify : where it sees ://, make hrefs out of them.
--has-html: where it sees html tags, render rather than escape them.
Not a big deal, but might be cool for some ;)
Nima
A continuation of #25. Here's a (for me) non-working example using the latest development branch of ansi2html
:
$ virtualenv ansi2html && cd ansi2html
$ source bin/activate
$ pip install https://github.com/ralphbean/ansi2html/archive/develop.zip
$ wget https://gist.github.com/echristopherson/4090959/raw/cd0eecca036cb1d2edc0e5a5e9f81ed3e31cf0fa/vimcat.sh
$ sh vimcat.sh bin/ansi2html # shows colored output
$ sh vimcat.sh bin/ansi2html | ansi2html --partial
<span class="ansi38-238 ansi48-231"></span><span class="ansi38-102">#!/Users/ich/ansi2html/bin/python2.7
</span
<span class="ansi38-238 ...
And the last closing span tag misses a >
.
I use Python 2.7, virtualenv 1.9.1 and bash-3.2 in this example.
I ran across this processing the output from pytest. Its collection phase prints several messages, separating by carriage returns (0D). In the terminal, each of these lines overwrites the previous one, until it gets to the end of the phase, and then in does a line feed (0A). As a result, only the final line is visible. (I believe this only completely works because the lines are padded with spaces.)
When I feed this to ansi2html, every line is visible, as if they were all separated with line feeds.
I started this bug report all gung-ho about "We should fix it, I'll try to submit a pull request" but now that I more fully understand what's going on, I think the prudent thing would be to just document this behavior.
Edit: I talked to someone else, and actually, this might be doable. I'll try to hack something over the weekend.
We already support it anyways. :)
I use centos 7, when I try install i had error:
sudo yum install ansi2html
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
- base: ftp.riken.jp
- epel: ftp.riken.jp
- extras: ftp.riken.jp
- updates: ftp.riken.jp
No package ansi2html available.
Error: Nothing to do
(virtenv) mocksoul@mocksoul-notebook ~ws/repos/pkg/testpack % ls -la | ansi2html-3.2 -p
total 44 drwxr-xr-x 4 mocksoul users 4096 Aug 9 17:28 . drwxr-xr-x 11 mocksoul users 4096 Aug 9 16:50 .. drwxr-xr-x 6 mocksoul users 4096 Aug 8 19:47 build -rw-r--r-- 1 mocksoul users 2219 Aug 1 00:34 cat -rw-r--r-- 1 mocksoul users 872 Aug 9 17:13 PKGBUILD drwxr-xr-x 2 mocksoul users 4096 Jul 26 17:39 __pycache__ -rw-r--r-- 1 mocksoul users 18084 Aug 9 18:01 res.html %```
ansi2html eat my lines! =)
This is expected output:
```bash
(virtenv) mocksoul@mocksoul-notebook ~ws/repos/pkg/testpack % ls -la --color=always | ansi2html-2.7 -p
total 44
drwxr-xr-x 4 mocksoul users 4096 Aug 9 17:28 <span class="ansi1 ansi34">.</span>
drwxr-xr-x 11 mocksoul users 4096 Aug 9 16:50 <span class="ansi1 ansi34">..</span>
drwxr-xr-x 6 mocksoul users 4096 Aug 8 19:47 <span class="ansi1 ansi34">build</span>
-rw-r--r-- 1 mocksoul users 2219 Aug 1 00:34 cat
-rw-r--r-- 1 mocksoul users 872 Aug 9 17:13 PKGBUILD
drwxr-xr-x 2 mocksoul users 4096 Jul 26 17:39 <span class="ansi1 ansi34">__pycache__</span>
-rw-r--r-- 1 mocksoul users 18084 Aug 9 18:01 res.html```
This is a very fine script!
Could you please handle reset?
# tput sgr0|hexdump -C
00000000 1b 28 42 1b 5b 6d |.(B.[m|
% echo "안"| PYTHONPATH=/home/dbravender/oprojects/ansi2html/ scripts/ansi2html-convert
Traceback (most recent call last):
File "scripts/ansi2html-convert", line 10, in
html = conv.convert(ansi)
File "/home/dbravender/oprojects/ansi2html/ansi2html/ansi2html.py", line 109, in convert
return self.template(full).render(**self.prepare(ansi))
File "/home/dbravender/oprojects/ansi2html/.env/lib/python2.7/site-packages/mako/template.py", line 296, in render
return runtime.render(self, self.callable, args, data)
File "/home/dbravender/oprojects/ansi2html/.env/lib/python2.7/site-packages/mako/runtime.py", line 661, in _render
return context._pop_buffer().getvalue()
File "/home/dbravender/oprojects/ansi2html/.env/lib/python2.7/site-packages/mako/util.py", line 134, in getvalue
return self.delim.join(self.data).encode(self.encoding, self.errors)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xec in position 0: ordinal not in range(128)
Hi,
due the lack of certain syntax highlighting in pygments, I found vimcat.sh
which works as expected, but when I pipe it through ansi2html
, it returns no highlighted HTML.
less
has no issues to show the colors. Although I'm currently using the fish
shell, I can reproduce the behavior with the regular bash. Here's the raw output:
�[0;38;5;238;48;5;231m�[K�[0;38;5;31m. �[0;38;5;238;48;5;231m~/.config/fish/export
�[0;38;5;238;48;5;231m�[K�[0;38;5;31m. �[0;38;5;238;48;5;231m~/.config/fish/prompt
�[0;38;5;238;48;5;231m�[K�[0;38;5;31m. �[0;38;5;238;48;5;231m~/.config/fish/alias
�[0;38;5;238;48;5;231m�[K�[0;38;5;238;48;5;231m
�[0;38;5;238;48;5;231m�[K�[0;38;5;25mset�[0;38;5;238;48;5;231m �[0;38;5;238m-x�[0;38;5;238;48;5;231m CLICOLOR �[0;38;5;208m1
�[0;38;5;238;48;5;231m�[K�[0;38;5;25mset�[0;38;5;238;48;5;231m �[0;38;5;238m-x�[0;38;5;238;48;5;231m TERM xterm-256color
�[0;38;5;238;48;5;231m�[K�[0;38;5;238;48;5;231m
�[0;38;5;238;48;5;231m�[K�[0;38;5;102m# curl vulnerability, http://curl.haxx.se/docs/adv_20130206.html
�[0;38;5;238;48;5;231m�[K�[0;38;5;25mset�[0;38;5;238;48;5;231m �[0;38;5;238m-x�[0;38;5;238;48;5;231m �[0;38;5;160mCURLOPT_REDIR_PROTOCOLS�[0m=�[0;38;5;208m0
�[0;38;5;238;48;5;231m�[K�[0;38;5;25mset�[0;38;5;238;48;5;231m �[0;38;5;238m-x�[0;38;5;238;48;5;231m �[0;38;5;160mCURLOPT_PROTOCOLS�[0m=�[0;38;5;208m0�[0m
(appearantly, GitHub does not show the ESC character, so here's the actual output:
Bildschirmfoto 2013-03-02 um 18 17 03)
Hello, I am trying to figure out what is wrong with my source string. I am note sure if the escape sequences are quite right.
from ansi2html import Ansi2HTMLConverter
a = """
\e[0m\e[1mRefreshing Terraform state in-memory prior to plan...\e[0m\nThe refreshed state will be used to calculate this plan, but will not be\npersisted to local or remote state storage.\n\e[0m\n\e[0m\e[1mdata.vsphere_datacenter.dc: Refreshing state...\e[0m\n\e[0m\e[1mdata.vsphere_network.network: Refreshing state...\e[0m\n\e[0m\e[1mdata.vsphere_resource_pool.pool: Refreshing state...\e[0m\n\e[0m\e[1mdata.vsphere_virtual_machine.template: Refreshing state...\e[0m\n\e[0m\e[1mdata.vsphere_datastore.datastore: Refreshing state...\e[0m\n\n------------------------------------------------------------------------\n\nAn execution plan has been generated and is shown below.\nResource actions are indicated with the following symbols:\n \e[32m+\e[0m create\n\e[0m\nTerraform will perform the following actions:\n\n\e[32m \e[32m+\e[0m \e[32mvsphere_virtual_machine.vm\n\e[0m id: <computed>\n boot_retry_delay: \"10000\"\n change_version: <computed>\n clone.#: \"1\"\n clone.0.customize.#: \"1\"\n clone.0.customize.0.linux_options.#: \"1\"\n clone.0.customize.0.linux_options.0.domain: \"guest.corp.lan\"\n clone.0.customize.0.linux_options.0.host_name: \"the-test\"\n clone.0.customize.0.linux_options.0.hw_clock_utc: \"true\"\n clone.0.customize.0.network_interface.#: \"1\"\n clone.0.customize.0.timeout: \"10\"\n clone.0.template_uuid: \"4231ae3d-64fc-fab5-cd50-022d3b5ffd4b\"\n clone.0.timeout: \"30\"\n cpu_limit: \"-1\"\n cpu_share_count: <computed>\n cpu_share_level: \"normal\"\n datastore_id: \"datastore-312\"\n default_ip_address: <computed>\n disk.#: \"1\"\n disk.0.attach: \"false\"\n disk.0.device_address: <computed>\n disk.0.disk_mode: \"persistent\"\n disk.0.disk_sharing: \"sharingNone\"\n disk.0.eagerly_scrub: \"false\"\n disk.0.io_limit: \"-1\"\n disk.0.io_reservation: \"0\"\n disk.0.io_share_count: \"0\"\n disk.0.io_share_level: \"normal\"\n disk.0.keep_on_remove: \"false\"\n disk.0.key: \"0\"\n disk.0.name: \"the-test.vmdk\"\n disk.0.size: \"10\"\n disk.0.thin_provisioned: \"false\"\n disk.0.unit_number: \"0\"\n disk.0.write_through: \"false\"\n ept_rvi_mode: \"automatic\"\n firmware: \"bios\"\n force_power_off: \"true\"\n guest_id: \"ubuntu64Guest\"\n guest_ip_addresses.#: <computed>\n host_system_id: <computed>\n hv_mode: \"hvAuto\"\n imported: <computed>\n memory: \"2048\"\n memory_limit: \"-1\"\n memory_share_count: <computed>\n memory_share_level: \"normal\"\n migrate_wait_timeout: \"30\"\n name: \"the-test\"\n network_interface.#: \"1\"\n network_interface.0.adapter_type: \"vmxnet3\"\n network_interface.0.bandwidth_limit: \"-1\"\n network_interface.0.bandwidth_reservation: \"0\"\n network_interface.0.bandwidth_share_count: <computed>\n network_interface.0.bandwidth_share_level: \"normal\"\n network_interface.0.device_address: <computed>\n network_interface.0.key: <computed>\n network_interface.0.mac_address: <computed>\n network_interface.0.network_id: \"dvportgroup-202\"\n num_cores_per_socket: \"1\"\n num_cpus: \"1\"\n reboot_required: <computed>\n resource_pool_id: \"resgroup-12\"\n run_tools_scripts_after_power_on: \"true\"\n run_tools_scripts_after_resume: \"true\"\n run_tools_scripts_before_guest_shutdown: \"true\"\n run_tools_scripts_before_guest_standby: \"true\"\n scsi_controller_count: \"1\"\n scsi_type: \"lsilogic\"\n shutdown_wait_timeout: \"3\"\n swap_placement_policy: \"inherit\"\n uuid: <computed>\n vmware_tools_status: <computed>\n vmx_path: <computed>\n wait_for_guest_net_timeout: \"5\"\n\e[0m\n\e[0m\n\e[0m\e[1mPlan:\e[0m 1 to add, 0 to change, 0 to destroy.\e[0m\n\n------------------------------------------------------------------------\n\nThis plan was saved to: plan\n\nTo perform exactly these actions, run the following command to apply:\n terraform apply \"plan\"\n
"""
conv = Ansi2HTMLConverter(escaped=False)
html = conv.convert(a)
print(html)
The problem is that the installation script tries to save the man pages in a system place even if I installing ansi2html only on my local virtualenv.
(my_venv)$ pip install ansi2html
[lots of stuff...]
copying man/ansi2html.1 -> /usr/share/man/man1/
error: /usr/share/man/man1/ansi2html.1: Permission denied
I couldn't find a best practices regarding to this. I saw some people recommend that man pages should be dealt only by distribution packages, not by python...
Seems like stuff is being encoded to ASCII right now so all my unicode is being trashed.
Is there a good reason for this?
I would love to be able to "script" using ansi2html, using css or yaml-like description to be able to execute some templating operations (adding/removing/editing content).
An option could be provided to pass a .js file as argument, so one could but a piece of javascript that will process the
informationful generated html (via templating) and augment the output. Here is a draft language to explain some kind of things I would like to do:
'1' { // matches an exact line number
insert_content: "<div id=\"summary\" />"
}
'span.ansi37,span.ansi32' { // matches a sequence of spans
// template-like execution, with some smart global variables
append_content: "<a class=\"errors\" name={{matchcount}}>anchor number {{span.parent.text.split('\n',2)[0]}}</a>"
}
I have a git hook that converts the diff to HTML and displays it in preparation of writing a good change log.
With Python 3.4, I get the follow error:
Traceback (most recent call last):
File ".git/hooks/prepare-commit-msg", line 108, in <module>
output_file_path = create_pretty_html_diff()
File ".git/hooks/prepare-commit-msg", line 90, in create_pretty_html_diff
html = html_converter.convert(output, full=False)
File "/.../.virtualenvs/odev/lib/python3.4/site-packages/ansi2html/converter.py", line 415, in convert
attrs = self.prepare(ansi, ensure_trailing_newline=ensure_trailing_newline)
File "/.../.virtualenvs/odev/lib/python3.4/site-packages/ansi2html/converter.py", line 395, in prepare
body = self.apply_regex(ansi)
File "/.../.virtualenvs/odev/lib/python3.4/site-packages/ansi2html/converter.py", line 238, in apply_regex
parts = self._collapse_cursor(parts)
File "/.../.virtualenvs/odev/lib/python3.4/site-packages/ansi2html/converter.py", line 371, in _collapse_cursor
for part in parts:
File "/.../.virtualenvs/odev/lib/python3.4/site-packages/ansi2html/converter.py", line 266, in _apply_regex
ansi = ansi.replace(pattern, special)
TypeError: 'str' does not support the buffer interface
From http://stackoverflow.com/questions/5471158/typeerror-str-does-not-support-the-buffer-interface it appears there needs to be a conversion to bytes.
I'm not totally sure why but this file I have doesn't render correctly:
It just spins forever.
I liked to use ansi2html on a system with only python 2.4 support, so I added python 2.4 support in my branch
https://github.com/JensTimmerman/ansi2html/tree/develop/ansi2html
Should I switch this to a feature branch and make a pull request?
Python3 support would be sweet as.
We can use rst2man
for this.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.