简体   繁体   English

Markdown 内部链接在 BitBucket README.md 中不起作用

[英]Markdown internal links not working in BitBucket README.md

I have a README.md file in a BitBucket project that goes something like我在 BitBucket 项目中有一个 README.md 文件,它类似于

## Table of Contents

* [Document Organization](#document-organization)

...

## Document Organization

When I open up the markdown preview in the browser with Sublime Text the links in the Table of Contents jump to the appropriate sections, but when I upload the file to BitBucket, the URL seems correct but it does not jump to the section.当我使用 Sublime Text 在浏览器中打开 Markdown 预览时,目录中的链接会跳转到相应的部分,但是当我将文件上传到 BitBucket 时,URL 似乎正确但没有跳转到该部分。

How can I fix this?我该如何解决这个问题?

我会检查锚标记上生成的 html,根据我对 bitbuckets 自动 ID 的回忆,我怀疑您的链接需要看起来更像

* [Document Organization](#markdown-header-document-organization)

Here's a snippet to generate a Table of Contents for Bitbucket readmes (or other markdown files).这是为 Bitbucket 自述文件(或其他降价文件)生成目录的片段。

cat readme.md  |\
grep "^#" |\
sed 's|^[ ]*||g' |\
awk  -F, '\
BEGIN {
}{
  basic_name=$1;
  anchor=basic_name
  basic_name_no_hash=basic_name
  gsub(/^[#]* /,"",basic_name_no_hash)
  gsub(/[ ]*$/,"",basic_name_no_hash)
  subs_string=basic_name
  subs = gsub(/#/,"",subs_string);
  gsub(/^[#]+ /,"",anchor);
  gsub(/ /,"-",anchor);
  anchor = tolower(anchor);
  {for (i=0;i<subs-1;i++) printf "    " }
  print "* [" basic_name_no_hash "](#markdown-header-" anchor ")";
}
END {
}'

This may do as well.这也可以。

According to this: https://confluence.atlassian.com/bitbucket/mark-up-comments-305037452.html , bitbucket supports the Table of Contents extension which can auto-generate links and anchors based on the document headers.根据这个: https ://confluence.atlassian.com/bitbucket/mark-up-comments-305037452.html ,bitbucket 支持目录扩展,它可以根据文档标题自动生成链接锚点。

The TOC extension is documented here: https://pythonhosted.org/Markdown/extensions/toc.html TOC 扩展记录在此处: https : //pythonhosted.org/Markdown/extensions/toc.html

Add the text "[TOC]" to the beginning of the document for it to be generated.将文本“[TOC]”添加到要生成的文档的开头。

It works for me (Atlassian Bitbucket v6.10.0):它对我有用(Atlassian Bitbucket v6.10.0):

## Table of Contents

* [Document Organization](#document-organization)

...

## Document Organization <a name="document-organization"></a>

Just add an ancor link <a name="document-organization"></a> to the header line.只需将 ancor 链接<a name="document-organization"></a>添加到标题行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM