diff --git a/browser/components/MarkdownPreview.js b/browser/components/MarkdownPreview.js index 9a09679b..8a5b1353 100644 --- a/browser/components/MarkdownPreview.js +++ b/browser/components/MarkdownPreview.js @@ -148,7 +148,7 @@ export default class MarkdownPreview extends React.Component { let row = parseInt(lineAnchor.getAttribute('data-key')) if (row > targetRow) { let targetAnchor = lineAnchors[index - 1] - this.getWindow().scrollTo(0, targetAnchor.offsetTop) + targetAnchor != null && this.getWindow().scrollTo(0, targetAnchor.offsetTop) break } } diff --git a/browser/components/markdown.styl b/browser/components/markdown.styl index 2cd0f3e2..5d7ea39c 100644 --- a/browser/components/markdown.styl +++ b/browser/components/markdown.styl @@ -105,9 +105,10 @@ a &.lineAnchor padding 0 margin 0 - display block + display inline-block font-size 0 height 0 + width 0 hr border-top none border-bottom solid 1px borderColor diff --git a/browser/lib/markdown.js b/browser/lib/markdown.js index be2afc59..31111e61 100644 --- a/browser/lib/markdown.js +++ b/browser/lib/markdown.js @@ -59,22 +59,18 @@ md.use(math, { return output } }) -md.use(require('markdown-it-checkbox')) md.use(require('markdown-it-footnote')) -let originalRenderToken = md.renderer.renderToken -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 + '' - } - return result -} +window.md = md export default function markdown (content) { if (content == null) content = '' - - return md.render(content.toString()) + content = content.toString() + .split('\n') + .map((line, index) => { + if (line.trim().length === 0) return '' + return line + '' + }) + .join('\n') + return md.render(content) }