diff --git a/.gitignore b/.gitignore index b4116c1f..1c447c6d 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ node_modules/* /dist /compiled /secret +*.log diff --git a/browser/components/MarkdownPreview.js b/browser/components/MarkdownPreview.js index 5d10cca8..f4c00971 100644 --- a/browser/components/MarkdownPreview.js +++ b/browser/components/MarkdownPreview.js @@ -21,7 +21,7 @@ const sanitizeOpts = { 'a': ['lineAnchor'], 'div': ['math'], 'pre': ['hljs'], - 'span': ['math', 'hljs-*'], + 'span': ['math', 'hljs-*', 'lineNumber'], 'code': ['language-*'] }, allowedAttributes: { @@ -91,7 +91,8 @@ export default class MarkdownPreview extends React.Component { this.state = { fontSize: config['preview-font-size'], - fontFamily: config['preview-font-family'] + fontFamily: config['preview-font-family'], + lineNumber: config['preview-line-number'] } } componentDidMount () { @@ -182,7 +183,8 @@ export default class MarkdownPreview extends React.Component { handleConfigApply (e, config) { this.setState({ fontSize: config['preview-font-size'], - fontFamily: config['preview-font-family'] + fontFamily: config['preview-font-family'], + lineNumber: config['preview-line-number'] }) } @@ -196,7 +198,7 @@ export default class MarkdownPreview extends React.Component { return (
this.handleClick(e)} onDoubleClick={e => this.handleDoubleClick(e)} onMouseDown={e => this.handleMouseDown(e)} diff --git a/browser/lib/markdown.js b/browser/lib/markdown.js index 7dad1e39..d8636f8e 100644 --- a/browser/lib/markdown.js +++ b/browser/lib/markdown.js @@ -3,6 +3,15 @@ import emoji from 'markdown-it-emoji' import math from '@rokt33r/markdown-it-math' import hljs from 'highlight.js' +function createGutter (str) { + let lc = (str.match(/\n/g) || []).length + let lines = [] + for (let i = 1; i <= lc; i++) { + lines.push('' + i + '') + } + return '' + lines.join('') + '' +} + var md = markdownit({ typographer: true, linkify: true, @@ -11,12 +20,16 @@ var md = markdownit({ highlight: function (str, lang) { if (lang && hljs.getLanguage(lang)) { try { - return '
' +
+        return '
' +
+        createGutter(str) +
+        '' +
         hljs.highlight(lang, str).value +
         '
' } catch (e) {} } - return '
' +
+    return '
' +
+    createGutter(str) +
+    '' +
     str.replace(/\&/g, '&').replace(/\/g, '>').replace(/\"/g, '"') +
     '
' } diff --git a/browser/main/modal/Preference/AppSettingTab.js b/browser/main/modal/Preference/AppSettingTab.js index 16a4c5ed..d1656fb0 100644 --- a/browser/main/modal/Preference/AppSettingTab.js +++ b/browser/main/modal/Preference/AppSettingTab.js @@ -80,9 +80,18 @@ export default class AppSettingTab extends React.Component { } } + handleLineNumberingClick (e) { + let config = this.state.config + + config['preview-line-number'] = e.target.checked + this.setState({ + config + }) + } + handleDisableDirectWriteClick (e) { let config = this.state.config - config['disable-direct-write'] = !config['disable-direct-write'] + config['disable-direct-write'] = e.target.checked this.setState({ config }) @@ -142,11 +151,14 @@ export default class AppSettingTab extends React.Component {
+
+ +
{ global.process.platform === 'win32' ? (
- +
) : null diff --git a/browser/styles/main/ArticleDetail.styl b/browser/styles/main/ArticleDetail.styl index 9c897eb0..bcf9edeb 100644 --- a/browser/styles/main/ArticleDetail.styl +++ b/browser/styles/main/ArticleDetail.styl @@ -382,6 +382,9 @@ infoButton() color lighten(inactiveTextColor, 10%) user-select none font-size 14px + &.lineNumbered + .lineNumber + display block .CodeEditor absolute top left right bottom border-top solid 1px borderColor diff --git a/browser/styles/mixins/marked.styl b/browser/styles/mixins/marked.styl index 8984db74..cc9fcd94 100644 --- a/browser/styles/mixins/marked.styl +++ b/browser/styles/mixins/marked.styl @@ -126,15 +126,25 @@ marked() border-radius 5px overflow-x auto margin 0 0 15px - line-height 1.35em - &>code + line-height 1.35 + code margin 0 padding 0 border none border-radius 0 - &>pre + pre border none margin -5px + &>span.lineNumber + font-family Monaco, Menlo, 'Ubuntu Mono', Consolas, source-code-pro, monospace + display none + float left + margin 0 0.5em 0 -0.5em + border-right 1px solid + text-align right + &>span + display block + padding 0 .5em 0 1em table width 100% margin 15px 0 25px diff --git a/lib/config.js b/lib/config.js index 8e631e47..d4a42d80 100644 --- a/lib/config.js +++ b/lib/config.js @@ -15,7 +15,8 @@ const defaultConfig = { 'disable-direct-write': false, 'theme-ui': 'light', 'theme-code': 'xcode', - 'theme-syntax': 'xcode' + 'theme-syntax': 'xcode', + 'preview-line-number': false } const configFile = 'config.json'