Skip to content

fixed #36 #37

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export class MarkdownNavbar extends Component {
.replace(/^[^#]+\n/g, '')
.replace(/(?:[^\n#]+)#+\s([^#\n]+)\n*/g, '') // 匹配行内出现 # 号的情况
.replace(/^#\s[^#\n]*\n+/, '')
.replace(/```[^`\n]*\n+[^```]+```\n+/g, '')
.replace(/```[^`\n]*\n+[^```]+```\n*/g, '')
.replace(/`([^`\n]+)`/g, '$1')
.replace(/\*\*?([^*\n]+)\*\*?/g, '$1')
.replace(/__?([^_\n]+)__?/g, '$1')
Expand Down Expand Up @@ -295,17 +295,17 @@ export class MarkdownNavbar extends Component {

this.updateHash(curHeading.dataId);
}
if(currentNavElement){
const {container} = this.refs
const {offsetTop} = currentNavElement
const {scrollTop:containerScrollTop,offsetHeight:containerOffsetHeight} = container
const min = containerScrollTop + 0.3 * containerOffsetHeight
const max = containerScrollTop + 0.7 * containerOffsetHeight
if(offsetTop < min || offsetTop > max){
const targetTop = offsetTop - 0.2 * containerOffsetHeight
this.safeScrollTo(container, targetTop,0,true)
}
}
// if(currentNavElement){
// const {container} = this.refs
// const {offsetTop} = currentNavElement
// const {scrollTop:containerScrollTop,offsetHeight:containerOffsetHeight} = container
// const min = containerScrollTop + 0.3 * containerOffsetHeight
// const max = containerScrollTop + 0.7 * containerOffsetHeight
// if(offsetTop < min || offsetTop > max){
// const targetTop = offsetTop - 0.2 * containerOffsetHeight
// this.safeScrollTo(container, targetTop,0,true)
// }
// }
this.setState({
currentListNo: curHeading.listNo,
});
Expand All @@ -330,7 +330,7 @@ export class MarkdownNavbar extends Component {
}

render() {
const tBlocks = this.getNavStructure().map((t) => {
const tBlocks = this.getNavStructure(this.props.source).map((t) => {
const cls = `title-anchor title-level${t.level} ${
this.state.currentListNo === t.listNo ? 'active' : ''
}`;
Expand Down