Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add anchor links fixing #80 #260

Closed
wants to merge 3 commits into from
Closed

Add anchor links fixing #80 #260

wants to merge 3 commits into from

Conversation

Hagb
Copy link
Contributor

@Hagb Hagb commented Mar 2, 2019

  1. 让书内的链接指向正常
  2. 让 pdf 能显示像原书一样的页码(效果如下,截图于1.1 《什么是自由软件?》的脚注)

screenshot
screenshot

#80 可以通过此法处理了(但是赶着上学来不及搞了)

@tonghuix tonghuix requested a review from mytbk March 2, 2019 04:48
@tonghuix
Copy link
Contributor

tonghuix commented Mar 2, 2019

所以后续工作需要怎么做呢?

@Hagb
Copy link
Contributor Author

Hagb commented Mar 2, 2019 via email

@mytbk
Copy link
Contributor

mytbk commented Mar 2, 2019

初步看了下还行,就是Makefile里面一堆sed看着很乱。

@Hagb
Copy link
Contributor Author

Hagb commented Mar 2, 2019

确实。希望能有更优雅的做法

@tonghuix
Copy link
Contributor

tonghuix commented Mar 2, 2019

@Hagb 主要是解决 #80 需要做的工作

@Hagb
Copy link
Contributor Author

Hagb commented Mar 2, 2019

@tonghuix
pandoc 和 mkdocs 都会在标题处设置 anchor,我们只需要使用它们设置的就行了……
之前我在原书的源码目录 grep 了一下,(瞟过一眼没仔细看)似乎 anchor 都是在标题处的(除了指向 附录 B 表格开头的一个 anchor,但这个并不影响,因为直接指向 附录 B 的标题有几乎同样的效果)……
所以处理方法就是像处理指向文章的办法那样子,将 anchor 找出(对于 mkdocs,可以直接将链接指向 xxx.md#xxxx;对于 pandoc 生成的 html,可以看标题处的 html 源码找到 anchor,然后将链接指向 #xxxx,PDF 也可用这种办法;对于 pdf 的页码的显示,pandoc 把 anchor 中的中文之类的以编码表示,这就是 Makefile 里 sed 后面那堆乱七八糟的东西。我没有研究他是怎么编码的,直接把编码后的从 tex 文件里抠了出来(找相关标题处,关键词 “label”))……

@tonghuix tonghuix changed the title Add links Add anchor links fixing #80 Mar 3, 2019
@tonghuix
Copy link
Contributor

tonghuix commented Mar 3, 2019

@tonghuix
pandoc 和 mkdocs 都会在标题处设置 anchor,我们只需要使用它们设置的就行了……
之前我在原书的源码目录 grep 了一下,(瞟过一眼没仔细看)似乎 anchor 都是在标题处的(除了指向 附录 B 表格开头的一个 anchor,但这个并不影响,因为直接指向 附录 B 的标题有几乎同样的效果)……
所以处理方法就是像处理指向文章的办法那样子,将 anchor 找出(对于 mkdocs,可以直接将链接指向 xxx.md#xxxx;对于 pandoc 生成的 html,可以看标题处的 html 源码找到 anchor,然后将链接指向 #xxxx,PDF 也可用这种办法;对于 pdf 的页码的显示,pandoc 把 anchor 中的中文之类的以编码表示,这就是 Makefile 里 sed 后面那堆乱七八糟的东西。我没有研究他是怎么编码的,直接把编码后的从 tex 文件里抠了出来(找相关标题处,关键词 “label”))……

我没太明白后续要怎么做?是说每篇文章都要 sed 一遍吗?

@Hagb
Copy link
Contributor Author

Hagb commented Mar 3, 2019

(以下假定原书的 anchor 都在标题处)
首先在 fsfs 的原书的源文件里找出设定的 anchor
grep anchor *.texi
输出类似 xxx.texi: @anchor{aaa} 的字样,我们需要找到这些字样在文章中的位置。
然后找到跳转到这些 anchor 的地方(以上述例子为例,若无特殊说明)
grep pageref{aaa *.texi
根据输出找到这些引用 anchor 的在文章中的位置。

md 文件是要能直接适配 mkdocs 的,所以先在 mkdocs 生成的 html 里面 xxx 对应的文件,在源代码中找到 xxx 的位置,(没记错的话)会有一个 id 属性(如 id="2"),这个就是 mkdocs 自动设置的 anchor。
之后,在上面找到的引用了这个 anchor 的位置,加入超链接指向 xxx.md#2.

之后处理 pandoc 的 html,可以在 pandoc 生成的 html 中那个 anchor 的位置,和上面同样的办法找到它的 id 属性(为了方便叙述,假定是 id="aaaaaa",当然实际上这不可能)。(pandoc 的 html 在同一个文件里,所以相关链接得指向 #aaaaaa,这些链接的添加在 Makefile 的 sed 里做)
之后处理 pandoc 生成的 tex,在生成的 tex 文件里找到 anchor 的位置,会看到像 \label{aaaaaaaaaa} 这样的代码(当然实际上也不可能是 aaaaaaaaaa)。

之后在 Makefile 的 sed 里加入
s/(xxx.md#2)/(#aaaaaa)<!--(pdf) \\\\pageto{aaaaaaaaaa} (pdf)-->/g
的语句

……这种做法似乎很不优雅……希望有更好的办法。

@tonghuix
Copy link
Contributor

tonghuix commented Mar 3, 2019

确实不够优雅啊,我想有没有可能把你这个PR开到一个分支里。

我开了一个新分支 issue-80,这样可以直接向那个分支提交,改起来也方便。

@tonghuix tonghuix mentioned this pull request Mar 3, 2019
@tonghuix tonghuix closed this Mar 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants