【发布时间】:2022-02-14 12:36:58
【问题描述】:
例如,我有一堆这样的 HTML 页面:
<!DOCTYPE html>
<html>
<head><title>Table des matières</title>
<meta http-equiv="Content-Type" content="text/html; charset="utf-8"" />
<meta name="generator" content="TeX4ht (http://www.tug.org/tex4ht/)" />
<meta name="originator" content="TeX4ht (http://www.tug.org/tex4ht/)" />
<!-- 3,html,xhtml,charset="utf-8" -->
<meta name="src" content="content_final.tex" />
<link rel="stylesheet" type="text/css" href="content_final.css" />
<script type="text/javascript" src="./jquery.js">
</script>
<script type="text/javascript">
$(document).ready(function() {
function capitalizeFirstLetter(string) {
return string.charAt(0).toUpperCase() + string.slice(1).toLowerCase();
}
$('div.caption span.id').each(function() { var result = $(this).text().replace(':','');
result=capitalizeFirstLetter(result);
$(this).text(result);
});
});
</script>
</head><body
>
<!--l. 125--><div class="crosslinks"><p class="noindent">[<a
href="chapter1.html" >next</a>] [<a
href="#tailcontent.html">tail</a>] [<a
href="/sciences/index.html" >up</a>] </p></div>
<h2 class="likechapterHead"><a
id="x2-1000"></a>Table des matières</h2>
<div class="tableofcontents">
但是不可能转换这些 HTML 页面中的所有法语口音,例如上面的口音
“Table des matières”出现“è”而不是“&egrave;”。
我尝试了两件事:
for i in $(ls *.html); do iconv -f iso-8859-1 -t utf8 $i > $i"_new"; mv -f $i"_new" $i; done
=> 重音不转换
for i in $(ls *.html); do recode ..html $i; done
=> 我有以下错误:
recode: section5.html failed: Invalid input in step `CHAR..ISO-10646-UCS-2'
recode: section6.html failed: Invalid input in step `CHAR..ISO-10646-UCS-2'
recode: section7.html failed: Invalid input in step `CHAR..ISO-10646-UCS-2'
recode: section8.html failed: Invalid input in step `CHAR..ISO-10646-UCS-2'
recode: section9.html failed: Invalid input in step `CHAR..ISO-10646-UCS-2'
recode: table_of_contents.html failed: Invalid input in step `CHAR..ISO-10646-UCS-2'
...
我不知道如何转换所有这些法语口音?
有没有人有任何想法或建议来转换所有可能的法语口音?我想使用iconv、recode 或sed 命令。
更新 1: 举一个基本示例,这是我收到的单个文件的消息:
$ recode ..html table_of_contents.html
recode: table_of_contents.html failed: Invalid input in step `CHAR..ISO-10646-UCS-2'
怎么了?
更新 2: 这是我原始 HTML 页面的输出:
$file -i index.html
$ index.html: text/x-tex; charset=iso-8859-1
还有index.html的负责人:
<!DOCTYPE html>
<html>
<head><title>Table des matières</title>
<meta http-equiv="Content-Type" content="text/html; charset="utf-8"" />
<meta name="generator" content="TeX4ht (http://www.tug.org/tex4ht/)" />
<meta name="originator" content="TeX4ht (http://www.tug.org/tex4ht/)" />
<!-- 3,html,xhtml,charset="utf-8" -->
<meta name="src" content="content_final.tex" />
<link rel="stylesheet" type="text/css" href="content_final.css" />
<script type="text/javascript" src="./jquery.js">
</script>
<script type="text/javascript">
$(document).ready(function() {
function capitalizeFirstLetter(string) {
return string.charAt(0).toUpperCase() + string.slice(1).toLowerCase();
}
$('div.caption span.id').each(function() { var result = $(this).text().replace(':','');
result=capitalizeFirstLetter(result);
$(this).text(result);
如果我应用命令:
$ recode -vfd u8..html index.html
Request: UTF-8..:libiconv:..ISO-10646-UCS-2..HTML_4.0
Shrunk to: UTF-8..ISO-10646-UCS-2..HTML_4.0
Recoding index.html... done
和
<!DOCTYPE html>
<html>
<head><title>Table des matires</title>
<meta http-equiv="Content-Type" content="text/html; charset="utf-8"" />
<meta name="generator" content="TeX4ht (http://www.tug.org/tex4ht/)" />
<meta name="originator" content="TeX4ht (http://www.tug.org/tex4ht/)" />
<!-- 3,html,xhtml,charset="utf-8" -->
<meta name="src" content="content_final.tex" />
<link rel="stylesheet" type="text/css" href="content_final.css" />
<script type="text/javascript" src="./jquery.js">
</script>
<script type="text/javascript">
$(document).ready(function() {
function capitalizeFirstLetter(string) {
return string.charAt(0).toUpperCase() + string.slice(1).toLowerCase();
}
$('div.caption span.id').each(function() { var result = $(this).text().replace(':','');
result=capitalizeFirstLetter(result);
$(this).text(result);
});
});
</script>
如您所见,“è”消失了。
我能做什么?
【问题讨论】:
-
这看起来是个常见问题。你检查过这里askubuntu.com/questions/40047/…吗?在尝试整个文件之前,您是否尝试过一个最小的示例,例如其中只有一个字符的文件,例如 è?
-
这是一个 HTML 实体,它与 UTF-8 没有任何关系。事实上,该页面声明使用 UTF-8(不知道您为什么认为它是 ISO-8859-1)。所以...您基本上是尝试使您的页面与 US-ASCII 兼容?您要解决的具体问题是什么?
-
@ÁlvaroGonzález 。我想将“é”转换为“é”,将“è”转换为“è”,将“à”转换为“à”和所有的法语口音,我想避免使用
sed,因为有很多可能的口音,我想使用recode或iconv -
@geco17 。是的,我看到了这篇文章,这就是为什么我在我的帖子中尝试了命令
recode ..html $i但它似乎不起作用,字符“é”没有被转换。 -
为什么会出现问题?为什么您认为需要将字符转换为 HTML 实体?如果字符编码正确(最好是 UTF-8)并且 Web 服务器配置为发送正确的
Content-Type标头,那么这些字符可以正常工作。
标签: html non-ascii-characters iconv recode french