Blame Scripts/Functions/Render/render_convertHtmlToText.sh

8d1098
#!/bin/bash
8d1098
#
ab1d67
# render_convertHtmlToText.sh -- This function takes one HTML file
8d1098
# and produces one plain-text file (i.e., without markup inside).
8d1098
#
8d1098
# Copyright (C) 2009-2011 Alain Reguera Delgado
8d1098
# 
8d1098
# This program is free software; you can redistribute it and/or
8d1098
# modify it under the terms of the GNU General Public License as
8d1098
# published by the Free Software Foundation; either version 2 of the
8d1098
# License, or (at your option) any later version.
8d1098
# 
8d1098
# This program is distributed in the hope that it will be useful, but
8d1098
# WITHOUT ANY WARRANTY; without even the implied warranty of
8d1098
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
8d1098
# General Public License for more details.
8d1098
#
8d1098
# You should have received a copy of the GNU General Public License
8d1098
# along with this program; if not, write to the Free Software
8d1098
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
8d1098
# USA.
8d1098
# 
8d1098
# ----------------------------------------------------------------------
8d1098
# $Id$
8d1098
# ----------------------------------------------------------------------
8d1098
ab1d67
function render_convertHtml2Text {
8d1098
8d1098
    # Verify existence of HTML file.
8d1098
    cli_checkFiles ${FILE}.xhtml 'f'
8d1098
8d1098
    local COMMAND=''
8d1098
    local OPTIONS=''
8d1098
8d1098
    # Define the command path to text-based web browser and options
8d1098
    # used to produce plain-text files. Most of these programs have a
8d1098
    # dump option that print formatted plain-text versions of given
8d1098
    # HTML file to stdout.
8d1098
    if [[ -x '/usr/bin/lynx' ]];then
8d1098
        COMMAND='/usr/bin/lynx'
8d1098
        OPTIONS='-force_html -nolist -width 70 -dump'
8d1098
    elif [[ -x '/usr/bin/elinks' ]];then
8d1098
        COMMAND='/usr/bin/elinks'
8d1098
        OPTIONS='-force_html -no-numbering -no-references -width 70 -dump'
8d1098
    elif [[ -x '/usr/bin/w3m' ]];then
8d1098
        COMMAND='/usr/bin/w3m'
8d1098
        OPTIONS='-dump'
8d1098
    fi
8d1098
8d1098
    if [[ $COMMAND != '' ]];then
8d1098
8d1098
        # Print action message.
8d1098
        if [[ -f ${FILE}.txt ]];then
8d1098
            cli_printMessage "${FILE}.txt" 'AsUpdatingLine'
8d1098
        else
8d1098
            cli_printMessage "${FILE}.txt" 'AsCreatingLine'
8d1098
        fi
8d1098
8d1098
        # Convert from HTML to plain-text without markup.
8d1098
        ${COMMAND} ${OPTIONS} ${FILE}.xhtml > ${FILE}.txt
8d1098
8d1098
    else
8d1098
        cli_printMessage "`gettext "No way to convert from HTML to plain-text found."`" 'AsErrorLine'
8d1098
        cli_printMessage "$(caller)" 'AsToKnowMoreLine'
8d1098
    fi
8d1098
8d1098
}