带有 Python 语法突出显示的 HTML 演示幻灯片

发布于 2024-10-02 10:58:01 字数 636 浏览 0 评论 0原文

我想为我的演示文稿创建幻灯片。我的演示文稿将包含以下内容:幻灯片标题、项目符号点、代码片段(等宽字体)、一些以粗体突出显示的代码行、Python 代码片段(带有语法突出显示)。

我需要一个可以在 HTML(或 HTML5)中生成此类幻灯片的应用程序或工具,因此当我在 Web 浏览器中打开生成的 HTML 并将 Web 浏览器设置为全屏模式时,它将开始幻灯片放映。我更喜欢将演示文稿编写为带有一些标记的 .txt 文件,然后该工具应生成 HTML。

我知道 Google Docs 的演示功能,但它不支持 Python 语法突出显示。

我还了解 LaTeX 和 Beamer,但这会生成 PDF 而不是 HTML(不是一个大问题) ,并且没有内置的 Python 语法突出显示。

我更喜欢使用普通的 Google Chrome 或 Mozilla Firefox 来投影我的演示文稿。我不想在投影机上安装任何演示软件(例如 bruce) 。

还有其他选择吗?

I'd like to create slides for my presentation. My presentation will contain these: slide title, bullet points, code snippets (in a monospace font), some code lines highlighted as bold, Python code snippets (with syntax highlighting).

I need an application or tool which can generate such slides in HTML (or HTML5), so when I open the generated HTML in my web browser, and put the web browser to full screen mode, it will start the slideshow. I prefer writing my presentation as a .txt file with some markup, and then the tool should generate the HTML.

I know about the presentation feature Google Docs, but that doesn't support Python syntax highlighting.

I also know about LaTeX and Beamer, but that would generate PDF instead of HTML (not a big problem), and doesn't have Python syntax highlighting built in.

I'd prefer projecting my presentation using a vanilla Google Chrome or Mozilla Firefox. I don't want to install any presentation software (such as bruce) on the projecting machine.

Is there an alternative?

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

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

发布评论

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

评论(5

生生漫 2024-10-09 10:58:01

尝试以下方法之一:

  1. 使用 S5 重构文本

    http://meyerweb.com/eric/tools/s5/

    http://docutils.sourceforge.net/docs/user/slide-显示.html

    如果您安装docutils(首选快照),您将在tools文件夹中获得rst2s5.py。

  2. Bruce,演示工具

    http://code.google.com/p/bruce-tpt/

  3. Pandoc:通用文档转换器

    http://johnmacfarlane.net/pandoc/

  4. AsciiDoc 有一个选项可以生成生成自包含的 Slidy HTML

Try one of the following:

  1. Restructured text with S5

    http://meyerweb.com/eric/tools/s5/

    http://docutils.sourceforge.net/docs/user/slide-shows.html

    If you install docutils (snapshot is preferred), you will get rst2s5.py in the tools folder.

  2. Bruce, The Presentation Tool

    http://code.google.com/p/bruce-tpt/

  3. Pandoc: a universal document converter

    http://johnmacfarlane.net/pandoc/

  4. AsciiDoc has an option to generate generate self-contained Slidy HTML

热风软妹 2024-10-09 10:58:01

就在最近,出现了 slippy:将演示文稿编辑为 HTML,并突出显示 Python(和许多其他语言)。

Just recently slippy appeared: edit your presentation as HTML, with Python (and lots of other languages) highlighting.

完美的未来在梦里 2024-10-09 10:58:01

你绝对应该看看landslide,这是一个Python应用程序,可以用它创建非常漂亮的幻灯片HTML5来自markdown格式的文本,并且它支持语法高亮。要预览它的功能,只需查看从项目的自述文件

You should definitely take a look at landslide, this is a python app that allows to create really nice looking slides in HTML5 from markdown formatted text, and it supports syntax highlighting. To have a preview of what it can do, just take a look at the sample slideshow generated from the project's README.

冷情 2024-10-09 10:58:01

html5slides 是一个不错的选择。

http://code.google.com/p/html5slides/

html5slides is great option.

http://code.google.com/p/html5slides/

凤舞天涯 2024-10-09 10:58:01

这只是您所要求的一部分,但是如果您想要对 Python 进行语法突出显示并转换为 HTML,那么您可以在 Emacs 中使用 python-mode 来执行语法突出显示并 htmlize 转换为 HTML。

例如,您可能会从 htmlize 开始

def decode_safely(s, charset='ascii'):
    """Return s decoded according to charset, but do so safely."""
    try:
        return s.decode(charset or 'ascii', 'replace')
    except LookupError: # bogus charset
        return s.decode('ascii', 'replace')

,然后通过 htmlize 您会得到:

<pre><span class="keyword">def</span> <span class="function-name">decode_safely</span>(s, charset=<span class="string">'ascii'</span>):
    <span class="string">"""Return s decoded according to charset, but do so safely."""</span>
    <span class="keyword">try</span>:
        <span class="keyword">return</span> s.decode(charset <span class="keyword">or</span> <span class="string">'ascii'</span>, <span class="string">'replace'</span>)
    <span class="keyword">except</span> <span class="type">LookupError</span>: <span class="comment"># see job002442
</span>        <span class="keyword">return</span> s.decode(<span class="string">'ascii'</span>, <span class="string">'replace'</span>)
</pre>

您可以看到每个语法都用属于一个的 进行标记。 class 指示它属于哪个语法类:然后您可以使用 CSS 来指定您想要的颜色。 (htmlize 可以配置为指定显式颜色 - - 但类/CSS 方法更灵活。)

作为幻灯片生成过程的一部分,这可以轻松实现自动化,但我认为这对于一个答案来说已经足够了。

It's only a part of what you're asking for, but if you want to do syntax-highlighting of Python and conversion to HTML, then you can do this in Emacs using python-mode to do the syntax highlighting and htmlize to do the conversion to HTML.

For example, you might start with

def decode_safely(s, charset='ascii'):
    """Return s decoded according to charset, but do so safely."""
    try:
        return s.decode(charset or 'ascii', 'replace')
    except LookupError: # bogus charset
        return s.decode('ascii', 'replace')

and after passing through htmlize you get:

<pre><span class="keyword">def</span> <span class="function-name">decode_safely</span>(s, charset=<span class="string">'ascii'</span>):
    <span class="string">"""Return s decoded according to charset, but do so safely."""</span>
    <span class="keyword">try</span>:
        <span class="keyword">return</span> s.decode(charset <span class="keyword">or</span> <span class="string">'ascii'</span>, <span class="string">'replace'</span>)
    <span class="keyword">except</span> <span class="type">LookupError</span>: <span class="comment"># see job002442
</span>        <span class="keyword">return</span> s.decode(<span class="string">'ascii'</span>, <span class="string">'replace'</span>)
</pre>

You can see that each piece of syntax is marked up with a <span> that belongs to a class indicating which syntax class it belongs to: you can then use CSS to specify the colours you want. (htmlize can be configured to specify explicit colours instead — <span style="color:#b22222"> — but the class/CSS approach is more flexible.)

This can be easily automated as part of your slide-generation process, but I think that's enough for one answer.

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