From cf1bf7d9e2aeebf1aa776a6d07f4c51199094454 Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Sat, 27 Aug 2016 21:13:07 +0100 Subject: [PATCH] add ansi to html converter client side --- package.json | 1 + pelicanconf.py | 1 + plugins/filters.py | 4 ++++ theme/static/src/js/app.js | 9 ++++++++- theme/static/src/scss/index.scss | 4 ++++ 5 files changed, 18 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index c48be1e..40ddb36 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,7 @@ }, "dependencies": { "animate.css": "=3.5.1", + "ansi_up": "=1.3.0", "bootstrap-sass": "=3.3.7", "font-awesome": "=4.6.3", "jquery": "=2.2.3", diff --git a/pelicanconf.py b/pelicanconf.py index e880f4e..91843aa 100644 --- a/pelicanconf.py +++ b/pelicanconf.py @@ -98,4 +98,5 @@ JINJA_FILTERS = { "datetime": filters.format_datetime, "category_find": filters.category_find, "limit": filters.limit, + "ansi2html": filters.ansi2html } diff --git a/plugins/filters.py b/plugins/filters.py index 2950233..adb838f 100644 --- a/plugins/filters.py +++ b/plugins/filters.py @@ -19,3 +19,7 @@ def limit(line, length): return " ".join(line.split(" ")[:length]) + '...' elif isinstance(line, list): return line[:length] + + +def ansi2html(content): + return "
{0}
".format(content) diff --git a/theme/static/src/js/app.js b/theme/static/src/js/app.js index 6afacca..adfebec 100644 --- a/theme/static/src/js/app.js +++ b/theme/static/src/js/app.js @@ -1,6 +1,8 @@ import './creative'; +import ansi_up from 'ansi_up'; -$('.image').each(function () { + +$('.image').each(function () { // setup div-image hybrids const ele = $(this); if (ele.data('image')) { ele.css('background-image', 'url(' + ele.data('image') + ')'); @@ -8,3 +10,8 @@ $('.image').each(function () { ele.removeClass('image'); } }); + +$('.ansi-up').each(function () { + const ele = $(this); + ele.html(ansi_up.ansi_to_html(ele.html())); +}); diff --git a/theme/static/src/scss/index.scss b/theme/static/src/scss/index.scss index 1f76502..55e2be7 100644 --- a/theme/static/src/scss/index.scss +++ b/theme/static/src/scss/index.scss @@ -83,3 +83,7 @@ p a { height: 40vh; } } + +.highlight.ansi-up { + font-weight: 600; +}