mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-13 09:46:22 +00:00
improve line anchors placement
This commit is contained in:
@@ -148,7 +148,7 @@ export default class MarkdownPreview extends React.Component {
|
|||||||
let row = parseInt(lineAnchor.getAttribute('data-key'))
|
let row = parseInt(lineAnchor.getAttribute('data-key'))
|
||||||
if (row > targetRow) {
|
if (row > targetRow) {
|
||||||
let targetAnchor = lineAnchors[index - 1]
|
let targetAnchor = lineAnchors[index - 1]
|
||||||
this.getWindow().scrollTo(0, targetAnchor.offsetTop)
|
targetAnchor != null && this.getWindow().scrollTo(0, targetAnchor.offsetTop)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -105,9 +105,10 @@ a
|
|||||||
&.lineAnchor
|
&.lineAnchor
|
||||||
padding 0
|
padding 0
|
||||||
margin 0
|
margin 0
|
||||||
display block
|
display inline-block
|
||||||
font-size 0
|
font-size 0
|
||||||
height 0
|
height 0
|
||||||
|
width 0
|
||||||
hr
|
hr
|
||||||
border-top none
|
border-top none
|
||||||
border-bottom solid 1px borderColor
|
border-bottom solid 1px borderColor
|
||||||
|
|||||||
@@ -59,22 +59,18 @@ md.use(math, {
|
|||||||
return output
|
return output
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
md.use(require('markdown-it-checkbox'))
|
|
||||||
md.use(require('markdown-it-footnote'))
|
md.use(require('markdown-it-footnote'))
|
||||||
|
|
||||||
let originalRenderToken = md.renderer.renderToken
|
window.md = md
|
||||||
md.renderer.renderToken = function renderToken (tokens, idx, options) {
|
|
||||||
let token = tokens[idx]
|
|
||||||
|
|
||||||
let result = originalRenderToken.call(md.renderer, tokens, idx, options)
|
|
||||||
if (token.map != null) {
|
|
||||||
return result + '<a class=\'lineAnchor\' data-key=\'' + token.map[0] + '\'></a>'
|
|
||||||
}
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
export default function markdown (content) {
|
export default function markdown (content) {
|
||||||
if (content == null) content = ''
|
if (content == null) content = ''
|
||||||
|
content = content.toString()
|
||||||
return md.render(content.toString())
|
.split('\n')
|
||||||
|
.map((line, index) => {
|
||||||
|
if (line.trim().length === 0) return ''
|
||||||
|
return line + '<a class=\'lineAnchor\' data-key=\'' + (index + 1) + '\'></a>'
|
||||||
|
})
|
||||||
|
.join('\n')
|
||||||
|
return md.render(content)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user