Skip to content

Instantly share code, notes, and snippets.

@paulirish
Created August 22, 2011 05:26
Show Gist options
  • Star 21 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save paulirish/1161725 to your computer and use it in GitHub Desktop.
Save paulirish/1161725 to your computer and use it in GitHub Desktop.
For converting adium logs to decently sexy HTML

adium log export to HTML

this shit is for exporting this weirdass xml out into some sane HTML.

  • run rename.sh to kill the whitespaces in your xml filenames
    • alternatively fix my htmlify.sh to not break on whitespace'd filenames
      • UPDATE: check this comment on a quick fix to avoid this rename script. BOOM! thx @kwef!
  • run htmlify.sh
    • htmlify has a hardcoded destination directory.
    • htmlify also expects the format-html.* files to be up one folder from it.
  • enjoy a bigass directory of all your logs all together with ugly filenames but at least they have nice styles and happy markup.

yay

/* in the xslt i hotlink my own hosted version of this file.. */
body {
font-family: sans-serif; font-size: 85%;
}
div.event {
color: #222222; background: #EEEEEE; border-color: #CCCCCC;
border-style: solid;
border-width: 1px;
margin: 1px; padding: 2px;
}
div.message {
color: #000000; background: #F6FFED; border-color: #9EC678;
}
div.principal {
color: #000000; background: #F7FAFF; border-color: #98B4DF;
}
div.follow-on {
border-top-style: solid;
border-top-width: 1px;
}
div.sender {
color: #386C05; background: #BBEE99; border-color: #9EC678;
border-style: solid;
border-width: 1px;
margin: 1px; padding: 2px;
font-weight: bold;
}
div.principal div.sender {
color: #234578; background: #CCDDFF; border-color: #98B4DF;
}
div.meta {
float: left; padding-right: 0.5em;
}
div.content {
margin-left: 14em;
}
span.sender {
font-size: 90%;
}
span.time {
font-size: 90%; color: gray;
}
/* i started customizing from here */
.message .content > div:last-child > span { font-family: inherit !important; font-size: inherit!important;}
.message.auto {
opacity: 0.2;
}
.message.auto .content > div:last-child > span { font-size: 50% !important;}
span.auto { display:none;}
status .sender { display:none;}
status { font-size: 50%; display:block; border-left: solid 5px hsl(108, 79%, 50%); }
status .sender + div { display: inline;}
status > div:last-child > span { font-size: 100% !important;}
status[type="available"] { /* already done above */ }
status[type="away"],
status[type="offline"] { border-color: hsl(1, 57%, 50%);}
status[type="idle"] { border-color: hsl(60, 60%, 62%);}
div.event { font-size: 50%; }
#!/bin/sh
# this script is from http://trac.adium.im/ticket/6569
# Adium is the legal property of its developers, whose names are listed in the copyright file included
# with this source distribution.
#
# This program is free software; you can redistribute it and/or modify it under the terms of the GNU
# General Public License as published by the Free Software Foundation; either version 2 of the License,
# or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
# the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
# Public License for more details.
#
# You should have received a copy of the GNU General Public License along with this program; if not,
# write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
# Purpose:
# Format an Adium .chatlog file as HTML
#
# Usage:
# format-html.sh LOG ...
#
# Notes:
# Output is written to a .html file in the same directory as the log
# xsltproc is used to run the transform
STYLESHEET=$(dirname "$0")/format-html.xsl
for LOG
do
TITLE=$(basename "$LOG" .chatlog | sed \
's/\([0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]\)T'\
'\([0-9][0-9]\)\.\([0-9][0-9]\)\.\([0-9][0-9]\)/'\
'\1 \2:\3:\4 /')
OUT=$(echo "${LOG%.chatlog}" | sed -e 's/[ |]/-/g' -e 's/[()]//g').html
xsltproc -o "$OUT" --stringparam title "$TITLE" "$STYLESHEET" "$LOG"
done
<?xml version="1.0"?>
<!-- this xslt is from http://trac.adium.im/ticket/6569 -->
<!--
Adium is the legal property of its developers, whose names are listed in the copyright file included
with this source distribution.
This program is free software; you can redistribute it and/or modify it under the terms of the GNU
General Public License as published by the Free Software Foundation; either version 2 of the License,
or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not,
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Purpose:
Format an Adium log file as XHTML
Parameters:
title A string to use for the page title
-->
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:adium="http://purl.org/net/ulf/ns/0.4-02"
xmlns="http://www.w3.org/1999/xhtml"
exclude-result-prefixes="adium">
<xsl:output method="xml"
doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
indent="yes" encoding="utf-8"/>
<xsl:strip-space elements="*"/>
<xsl:param name="title" select="'Chat'"/>
<!-- Process chats -->
<xsl:template match="adium:chat">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title><xsl:value-of select="$title"/></title>
<link rel="stylesheet" href="http://paulirish.com/adiumlogs.css"/>
</head>
<body>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>
<!-- Process events -->
<xsl:template match="adium:event">
<div class="event">
<xsl:value-of select="@type"/>
<xsl:text>: </xsl:text>
<xsl:value-of select="translate(@time, 'T', ' ')"/>
</div>
</xsl:template>
<!-- Process messages -->
<xsl:template match="adium:message">
<!-- Record whether this is a follow-on message -->
<xsl:variable name="prec" select="preceding-sibling::*[1]"/>
<xsl:variable name="follow-on">
<xsl:if test="$prec[self::adium:message] and $prec/@sender = @sender">
<xsl:text>follow-on</xsl:text>
</xsl:if>
</xsl:variable>
<!-- Record whether this is from the principal account -->
<xsl:variable name="principal">
<xsl:if test="@sender = /adium:chat/@account">
<xsl:text>principal</xsl:text>
</xsl:if>
</xsl:variable>
<!-- Record if this is an auto message -->
<xsl:variable name="auto">
<xsl:if test="@auto = 'true'">
<xsl:text>auto</xsl:text>
</xsl:if>
</xsl:variable>
<!-- Create message div -->
<div class="message {$principal} {$follow-on} {$auto}">
<!-- Include a sender box when this is not a follow-on message -->
<xsl:if test="$follow-on = ''">
<div class="sender">
<xsl:apply-templates select="@sender|@alias"/>
</div>
</xsl:if>
<!-- Process attributes -->
<div class="meta">
<xsl:apply-templates select="@*[not(name() = 'sender' or name() = 'alias')]"/>
</div>
<div class="content">
<!-- Process child elements etc. -->
<xsl:apply-templates select="node()"/>
</div>
</div>
</xsl:template>
<xsl:template match="@sender|@alias">
<xsl:if test="name() = 'alias' or not(../@alias)">
<span class="sender">
<xsl:value-of select="."/>
</span>
</xsl:if>
</xsl:template>
<xsl:template match="@auto">
<span class="auto">
<xsl:value-of select="."/>
</span>
</xsl:template>
<xsl:template match="@time">
<span class="time">
<xsl:value-of select="substring(., 12, 8)"/>
</span>
</xsl:template>
<xsl:template match="adium:message/@*" priority="0">
<xsl:message>Unhandled attribute: message/@<xsl:value-of select="name()"/>&#10;</xsl:message>
</xsl:template>
<!-- Copy elements but strip off the namespace -->
<xsl:template match="*">
<xsl:element name="{local-name()}">
<xsl:apply-templates select="node()|@*"/>
</xsl:element>
</xsl:template>
<!-- Copy atrributes but strip off the namespace -->
<xsl:template match="@*">
<xsl:attribute name="{local-name()}">
<xsl:apply-templates/>
</xsl:attribute>
</xsl:template>
</xsl:stylesheet>
#!/bin/bash
file=0
for i in `find . -name "*.xml"` ;
do xsltproc -o "$i.html" ../format-html.xsl "$i";
# move that HTML file to this HARDCODED FOLDER NAME
# YES YOU SHOULD PROBABLY CHANGE THIS OR SOMETHING
mv "$i.html" ~/mylogs/gtalk ;
file=$(($file+1))
done
echo Total files: $file
# i had to do this bullshit because ...
# my htmlify `find` command choked on whitespace filename
# see also: i'm a noob.
find . -name '* *' | while read file;
do
target=`echo "$file" | sed 's/ /_/g'`;
echo "Renaming '$file' to '$target'";
mv "$file" "$target";
done;
@plaidfinch
Copy link

I figured out how to solve your whitespace issue in the htmilfy.sh script. Set the IFS environment variable at the start of your script, by saying: IFS=$'\n'. What this does is makes it such that fields are interpreted not to be broken on spaces; only on newlines.

To demonstrate this, compare the output of IFS=$'\n'; for i in find . -name "*.xml"; do echo "$i"; done to the same command not prefaced by the setting of the IFS variable. You'll note that the use of the IFS setting leads to each file being output on its own line, not broken by spaces, whereas not setting IFS causes files to be broken on spaces.

Hope this helps!

@paulirish
Copy link
Author

So dope!! thanks a bunch. I added a quick note :)

@plaidfinch
Copy link

plaidfinch commented Jan 5, 2012 via email

@scoobydoobydude
Copy link

I just came across this, hoping to find a way to export my old logs to HTML especially since I doubt Adium will continue development to offer 64-bit support. I made the modification to the htmlify.sh file but are there any other locations and how do I run this? Do I just execute from the terminal and how does it know where my Adium logs will be? Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment