哈巴狗 - 包括“ include”的C代码。其中的关键字

发布于 2025-02-03 13:18:06 字数 535 浏览 3 评论 0原文

我想将C文件内容放入HTML文档中。为此,我使用的是:

<pre>
        <code>
            include main.c
        </code>
</pre>

在我的main.c文件中,我有:

#include <stdio.h>
#include <stdlib.h>

然后将其编译为:

<pre>
<code>
 "#include "
 <stdio.h>
  "#include "
  <stdlib.h>
   ...
  </stdlib.h>
 </stdio.h>
</code>
</pre>

如何防止它并拥有&lt; stdio.h&gt;包括正常文本? PS:与(#include“ main.h”一起使用,不使用&lt;&gt;)

I want to put c file content in html document with pug. For that I use:

<pre>
        <code>
            include main.c
        </code>
</pre>

In my main.c file I have:

#include <stdio.h>
#include <stdlib.h>

It then compiles to:

<pre>
<code>
 "#include "
 <stdio.h>
  "#include "
  <stdlib.h>
   ...
  </stdlib.h>
 </stdio.h>
</code>
</pre>

How can I prevent that and have <stdio.h> included as normal text ?
PS: works fine with (#include "main.h", not using <>)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

凉墨 2025-02-10 13:18:06

如果您使用的是Pug,您可能正在使用VUE等UI框架?如果是这样,只需将您的文件代码转换为一个变量并将其放置(即&lt; code&gt; {{mycode}}&lt;/code&gt;。像您这样做的代码(直接输入它或从文件中包括)

。从逻辑

上讲,您的操作方式也可以在文件级别上使用,以便在文件级别上使用c文件IT服务器端

If you're using pug, you're probably using a UI framework like Vue? If so, just turn your file code into a variable and place it this way (i.e. <code>{{myCode}}</code>. Pug isn't meant for processing hard-coded code like you're doing it (entering it directly or including it from a file). If you do that you'll have to keep escaping it and other shenanigans.

If you push it back to a variable, you'll see more options logically open up to what is possible for you.

Also, the way you're doing it, the C file has to be available to pug at the file level, to the pug renderer, which is doing yourself a disservice as you can only render it server side.

If you push it to a variable you can render it client-side, or from anywhere at any point.

玉环 2025-02-10 13:18:06

&lt;&gt;是特殊保留的HTML chars。这种炭是必须逃脱的。
在哈巴狗中,您可以使用过滤器为此。

如果使用webpack在静态html中编译哈巴狗文件,则可以使用。此PUG-LOADER已嵌入过滤器,例如 > :突出显示/a>,:markdown 做您需要的确切功能。

用法:Escape应用于包含的main.c

pre: code
  include:escape main.c

生成的HTML:

<pre>
  <code>
    #include <stdio.h>
    #include <stdlib.h>
  </code>
</pre>

浏览器中的输出:

#include <stdio.h>
#include <stdlib.h>

The <> are special reserved HTML chars. This chars must be escaped.
In Pug, you can use filters for this.

If you use Webpack to compile Pug files in static HTML, then you can use the @webdiscus/pug-loader. This pug-loader has embedded filters such :escape, :highlight, :markdown that do exact what you need.

Usage the :escape Pug filter applied to included main.c:

pre: code
  include:escape main.c

Generated HTML:

<pre>
  <code>
    #include <stdio.h>
    #include <stdlib.h>
  </code>
</pre>

Output in browser:

#include <stdio.h>
#include <stdlib.h>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文