1

根据pandoc(1),pandoc 支持 HTML 幻灯片中的内部链接。但是当我单击一个时,我什么也没有发生。

一个最小的例子:

% A minimal example
% moi
% 2015-04-04

# Section 1

la la la

# Section 2

cf. [Section 1](#section-1)

我将上述内容另存为example.md. 然后在 bash 我跑

file=example && \
pandoc -fmarkdown -tslidy --standalone --self-contained -o$file.html $file.md

在网络浏览器中打开生成的 HTML 幻灯片后,我单击幻灯片“第 2 节”上的“第 1 节”,但没有任何反应。我已经在多个设备上的多个浏览器中尝试过:xombrero 在运行 Arch Linux 的 Macbook 上,Chrome 在运行 Android 的 Moto X 上,以及在运行 Windows 8.1 的 Sony 笔记本电脑上的 Chrome。结果是一样的。我正在使用 pandoc 版本 1.13.2。

pandoc 为内部参考生成的链接与相关幻灯片的链接不同:在本示例中,前者以 . 结尾#section-1,后者以#(2). 我想这就是为什么单击内部链接不会返回到相关幻灯片的原因。有什么方法可以实现内部链接确实转到他们的相关幻灯片?

这是相关的HTML:

<body>
<div class="slide titlepage">
  <h1 class="title">A minimal example</h1>
  <p class="author">
moi
  </p>
  <p class="date">2015-04-04</p>
</div>
<div id="section-1" class="slide section level1">
<h1>Section 1</h1>
<p>la la la</p>
</div>
<div id="section-2" class="slide section level1">
<h1>Section 2</h1>
<p>cf. <a href="#section-1">Section 1</a></p>
</div>
</body>

谢谢你的帮助!

4

2 回答 2

2

Your problem is not with Pandoc but with Slidy. Pandoc is creating the right HTML for an ordinary HTML page but the Slidy slide software does not support going to a <div> - only going to a slide number.

If you change your link to cf. [Section 1](#(2)) ('2' being the number of the slide with 'Section 1') then it will work fine.

BTW - It works perfectly in a reveal.js slideshow created by Pandoc.

于 2015-04-09T00:10:52.263 回答
0

尽管这个问题是在五年多前提出的,但我最近遇到了同样的问题,并在 Python 中创建了一个后处理脚本,它对我有用。本质上,它是读取 Pandoc -> Slidy html 输出,扫描内部链接并将其替换为定义链接 ID 的幻灯片编号。

def Fix_Internal_Slidy_Links(infilename, outfilename):
    """Replaces all internal link targets with targets of the respective slidy page number
    """
    page_pattern = ' class=\"slide';
    id_pattern = ' id=\"';
    internal_link_pattern = '<a href=\"#';
    id_dict = dict();
    whole_text = [];
    cur_page = 0;
    #
    # First read all ids and associate them with the current page in id_dict
    with open(infilename, 'r', encoding='utf-8') as filecontent:
        for idx_cur_line, cur_line in enumerate(filecontent):
            whole_text += [cur_line];
            if (page_pattern in cur_line):
                cur_page += 1;
            #
            if (id_pattern in cur_line):
                while (id_pattern in cur_line):
                    startidx = cur_line.index(id_pattern);
                    cur_line = cur_line[startidx+len(id_pattern):];
                    lineparts = cur_line.split('"');
                    # Check if the current id is properly ended
                    if (len(lineparts) > 1):
                        id_dict.update([(lineparts[0], cur_page)]);
    #
    # Then process the code again and replace all internal links known in id_dict
    with open(outfilename, 'w', encoding='utf-8') as filecontent:
        for cur_line in whole_text:
            if (internal_link_pattern in cur_line):
                temp_line = '';
                offset = 0;
                while (internal_link_pattern in cur_line):
                    startidx = cur_line.index(internal_link_pattern);
                    # Extract name
                    temp_line += cur_line[offset:startidx+len(internal_link_pattern)];
                    cur_line = cur_line[startidx+len(internal_link_pattern):];
                    lineparts = cur_line.split('"');
                    if (len(lineparts) < 2):
                        # It seems that the id is not properly finished
                        break;
                    #
                    link = lineparts[0];
                    try:
                        # Create a link to the page assigned to that id
                        replacement_link = '(' + str(id_dict[link]) + ')"';
                    except:
                        # The link reference is not known in id_dict so do not change it
                        replacement_link = lineparts[0] + '"';
                    #
                    temp_line += replacement_link;
                    cur_line = cur_line[len(lineparts[0])+1:];
                #
                cur_line = temp_line + cur_line;
            #
            filecontent.write(cur_line);
#
于 2020-09-18T21:31:55.287 回答