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

TOC issue that headline with chinese characters only No links generated #1241

Closed
heavenzone opened this Issue Jan 10, 2018 · 2 comments

Comments

Projects
None yet
2 participants
@heavenzone
Copy link

heavenzone commented Jan 10, 2018

I don't know if this is an issue.

If the headline has chinese characters only, the output htmldocument's source code of this position #TOC ul li a does not create the href attribute. And the div wrapping the headline <h2></h2> does not create the id attribute.

here's the result.

test env

i'v tested for both version 1.8 and version 1.8.5.
both of them caused this issue.

> packageVersion("rmarkdown")
[1] ‘1.8’
> packageVersion("rmarkdown")
[1] ‘1.8.5’

rmarkdown file

---
title: "rmarkdown toc that headline with chinese characters only issue"
author:
  - test
output:
  html_document:
	toc: true
---

## 中文标题

chinese characters only

## 标题headline

mix


## headline

english only

output html source code

<div id="TOC">
<ul>
<li><a>中文标题</a></li>
<li><a href="#headline">标题headline</a></li>
<li><a href="#headline-1">headline</a></li>
</ul>
</div>

<div class="section level2">
<h2>中文标题</h2>
<p>chinese characters only</p>
</div>
<div id="headline" class="section level2">
<h2>标题headline</h2>
<p>mix</p>
</div>
<div id="headline-1" class="section level2">
<h2>headline</h2>
<p>english only</p>
</div>

blogdown has the same issue.

@yihui

This comment has been minimized.

Copy link
Member

yihui commented Jan 10, 2018

Duplicate of #1149

It is a Pandoc issue, but I don't think Pandoc can automatically solve it. You have manually add IDs to your pure Chinese titles. Thanks!

@yihui yihui marked this as a duplicate of #1149 Jan 10, 2018

@yihui yihui closed this Jan 10, 2018

@yihui yihui added this to the v1.9 milestone Jan 10, 2018

@yihui yihui added the Question label Jan 10, 2018

@heavenzone

This comment has been minimized.

Copy link
Author

heavenzone commented Jan 11, 2018

@yihui thanks for pointing out the details of this issue.
I think this issue could solve by javascript easily. so i searched "markdown toc" for another solution.
then I found this two repos:

now i just easily paste these codes into rmarkdown files, Then the toc with pure Chinese makes sense.

<script type="text/javascript">
 $(document).ready(function(){
      $("h2,h3,h4,h5,h6").each(function(i,item){
        var tag = $(item).get(0).localName;
        $(item).attr("id","wow"+i);
        $("#category").append('<a class="new'+tag+'" href="#wow'+i+'">'+$(this).text()+'</a></br>');
        $(".newh2").css("margin-left",0);
        $(".newh3").css("margin-left",20);
        $(".newh4").css("margin-left",40);
        $(".newh5").css("margin-left",60);
        $(".newh6").css("margin-left",80);
      });
 });
</script>
<div id="category"></div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment