【问题标题】:links in the string do not enable in html code字符串中的链接在 html 代码中不启用
【发布时间】:2020-08-04 23:28:15
【问题描述】:

我是网络开发的新手,非常感谢论坛的任何帮助!

我正在从多个文本文件中读取文本并将其作为列表发送到 html 表单。

文本可能有一些链接。这些链接在显示为段落时不会启用。 我无法读取每个文件并将 href 属性放在任何存在链接的地方。

因此需要帮助以使下面的片段启用链接。

<!DOCTYPE html>
<html>
<body>

<h1>My First Heading </h1>
<pre>My first paragraph. https://www.w3schools.com/html/tryit.asp?filename=tryhtml_elements</pre>

</body>
</html>

【问题讨论】:

    标签: html


    【解决方案1】:

    我无法读取每个文件并将 href 属性放在任何存在链接的地方。

    首先备份您的文本文件并考虑在命令行中使用sed 来试验自动将html 添加到每个txt 文件中的链接:

    sed -i -e "s|http[:]//[^ ]*|&lt;a href=\"\0\"&gt;\0&lt;/a&gt;|g" yourfile.txt[1]

    在上面的示例中,yourfile 将替换为您正在使用的文本文件的名称。如果结果看起来不错,您可以更新 sed 命令以修改特定位置的所有 txt 文件。

    祝你好运。


    [1]Convert URLs into HTML links using sed?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-06-16
      • 2019-07-08
      • 2012-06-20
      • 2015-08-17
      • 1970-01-01
      • 2019-04-08
      • 1970-01-01
      相关资源
      最近更新 更多