从html文件中获取源代码

Qia*_* Li 0 html syntax-highlighting

我想知道你是否可以请求帮助以编程方式从以下html文件生成.cpp/.h文件(使用任何脚本语言,编程语言,甚至使用vi或emacs等编辑器):

<!DOCTYPE html
    PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-US">
<head>
<title>Class</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body link="blue" vlink="purple" bgcolor="#FFFABB" text="black">

<h2><font face="Helvetica">Code Fragment: Class</font></h2>
</center><br><dl><dd><pre>

  <font color=#A000A0>template</font> &lt;<font color=#A000A0>typename</font> G&gt;
  <font color=#A000A0>class</font> Components : <font color=#A000A0>public</font> DFS&lt;G&gt; {            <font color=#0000FF>// count components</font>
  <font color=#A000A0>private</font>:
    <font color=#A000A0>int</font> nComponents;                 <font color=#0000FF>// num of components</font>
  <font color=#A000A0>public</font>:
    <font color=#000000>Components</font>(<font color=#A000A0>const</font> G& g): DFS&lt;G&gt;(g) {}        <font color=#0000FF>// constructor</font>
    <font color=#A000A0>int</font> <font color=#A000A0>operator</font>()();                 <font color=#0000FF>// count components</font>
  };
</dl>

</body>
</html>
Run Code Online (Sandbox Code Playgroud)

如果你能指出如何在另一个方向上做到这一点,这将是伟大的.非常感谢.

jma*_*man 8

这对你有用吗?

[18:56:44 jaidev@~]$ lynx --dump foo.html
Code Fragment: Class


  template <typename G>
  class Components : public DFS<G> {            // count components
  private:
    int nComponents;                 // num of components
  public:
    Components(const G& g): DFS<G>(g) {}        // constructor
    int operator()();                 // count components
  };
[18:56:49 jaidev@~]$
Run Code Online (Sandbox Code Playgroud)

编辑:

反方向.如果使用vim作为编辑器,则可以输入:TOhtml以在新缓冲区中生成突出显示HTML代码的语法.它会根据你的vim colorscheme生成一个html.要更改colorscheme,请使用该:colorscheme <name>命令.