-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add html2nmail util that may be used for html_to_text_cmd
- Loading branch information
Showing
4 changed files
with
49 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#!/usr/bin/env bash | ||
|
||
# html2nmail | ||
# | ||
# Copyright (c) 2024 Kristofer Berggren | ||
# All rights reserved. | ||
# | ||
# nmail is distributed under the MIT license, see LICENSE for details. | ||
|
||
INPATH=${1} | ||
|
||
if [[ ! -f "${INPATH}" ]]; then | ||
>&2 echo "usage: html2nmail <html-file>" | ||
exit 1 | ||
fi | ||
|
||
# 1 = no table in html file | ||
NO_TABLE=$(grep -qi '<table' "${INPATH}" ; echo ${?}) | ||
|
||
if [[ "${NO_TABLE}" == "1" ]]; then | ||
if command -v pandoc &> /dev/null; then | ||
pandoc -f html -t plain+literate_haskell --wrap=preserve "${INPATH}" | ||
exit ${?} | ||
fi | ||
fi | ||
|
||
if command -v w3m &> /dev/null; then | ||
w3m -T text/html -I utf-8 -dump "${INPATH}" | ||
exit ${?} | ||
fi | ||
|
||
if command -v lynx &> /dev/null; then | ||
lynx -assume_charset=utf-8 -display_charset=utf-8 -nomargins -dump "${INPATH}" | ||
exit ${?} | ||
fi | ||
|
||
if command -v elinks &> /dev/null; then | ||
elinks -dump-charset utf-8 -dump "${INPATH}" | ||
exit ${?} | ||
fi | ||
|
||
>&2 echo "error: html2nmail found no supported html converter" | ||
exit 1 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters