Blame Scripts/Functions/Render/Xhtml/xhtml_convertToText.sh

8d1098
#!/bin/bash
8d1098
#
997ef4
# svg_convertHtmlToText.sh -- This function takes one HTML file
8d1098
# and produces one plain-text file (i.e., without markup inside).
8d1098
#
2d3646
# Copyright (C) 2009, 2010, 2011 The CentOS Project
fa95b1
#
fa95b1
# This program is free software; you can redistribute it and/or modify
fa95b1
# it under the terms of the GNU General Public License as published by
dcd347
# the Free Software Foundation; either version 2 of the License, or (at
dcd347
# your option) any later version.
fa95b1
#
74a058
# This program is distributed in the hope that it will be useful, but
74a058
# 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
dcd347
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
7ac5a5
#
8d1098
# ----------------------------------------------------------------------
8d1098
# $Id$
8d1098
# ----------------------------------------------------------------------
8d1098
997ef4
function xhtml_convertToText {
8d1098
8d1098
    # Verify existence of HTML file.
76bde7
    cli_checkFiles ${FILE}.xhtml
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
0ff158
            cli_printMessage "${FILE}.txt" --as-updating-line
8d1098
        else
0ff158
            cli_printMessage "${FILE}.txt" --as-creating-line
8d1098
        fi
8d1098
8d1098
        # Convert from HTML to plain-text without markup.
8d1098
        ${COMMAND} ${OPTIONS} ${FILE}.xhtml > ${FILE}.txt
8d1098
8d1098
    else
0ff158
        cli_printMessage "`gettext "No way to convert from HTML to plain-text found."`" --as-error-line
8d1098
    fi
8d1098
8d1098
}