Git Product home page Git Product logo

Comments (5)

Yunkou avatar Yunkou commented on June 11, 2024 2

核心代码在这:

var pagetoc = document.getElementsByClassName("pagetoc")[0];
var elements = document.getElementsByClassName("header");
Array.prototype.forEach.call(elements, function (el) {
var link = document.createElement("a");
// Indent shows hierarchy
var indent = "";
switch (el.parentElement.tagName) {
case "H1":
return;
case "H3":
indent = "20px";
break;
case "H4":
indent = "40px";
break;
default:
break;
}
link.appendChild(document.createTextNode(el.text));
link.style.paddingLeft = indent;
link.href = el.href;
pagetoc.appendChild(link);
});

  • 通过 class 为 header 的拿到目录 (每个标题都有个 class为 header 的 a 标签)
  • 遍历 elements 将大纲添加到 pagetoc
  • 通过 a 的父标签判断等级,增加缩进

from rust-course.

sunface avatar sunface commented on June 11, 2024

看的不是很明白,custom.js 的代码应该挺清晰的,里面有哪个地方的数据获取方式有问题吗?

from rust-course.

codecoron avatar codecoron commented on June 11, 2024

你好,是不清楚custom.jsArray的数据是怎么获取的。比如Array是如何拿到每个md文档的标题

from rust-course.

Yunkou avatar Yunkou commented on June 11, 2024

@sunface 这个 Issues 可以关闭了

from rust-course.

sunface avatar sunface commented on June 11, 2024

好的

from rust-course.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.