Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
788900e
Added markdownlint rules form
roottool Apr 28, 2019
7fb22f3
Translated from English to Japanese
roottool Apr 28, 2019
11bed72
Introduced jsonlint-mod
roottool Apr 28, 2019
4ba4e68
Added markdownlint rules form
roottool Apr 28, 2019
8b3beb4
Added a caution of the custom markdownlint rules
roottool Apr 29, 2019
33d1700
Change styleName of caution
roottool Apr 29, 2019
79a29c3
Merge branch 'master' into add-markdownlint-rules-form
roottool May 6, 2019
a162bab
Fix: Improved for the app not to need to reload
roottool May 6, 2019
ecfeede
Fix: Removed unnecessary caution
roottool May 6, 2019
f3ca893
Ajusted markdownlint config editor to code editor
roottool May 6, 2019
f1597f8
Fix: Poped up the lint tooptip
roottool May 6, 2019
0a5c4c0
Fix: Improved for the app not to need to reload
roottool May 6, 2019
61e0540
Fix: Removed unnecessary css code
roottool May 6, 2019
69a62d1
Fix: Changed variable name
roottool May 8, 2019
2da4f1d
Fix: Rewrote the code to inline
roottool May 8, 2019
c42eb41
Fix: Fixed that default rule was shifted by indent
roottool May 8, 2019
0d6c952
Added a newline
roottool May 8, 2019
c82dbdd
Fix markdownlint result desplay works properly
roottool May 12, 2019
2497bdb
Fix: Removed changes to debug the app
roottool May 22, 2019
270a015
WIP: Add MarkdownLint enable setting. Gutter toggle not working as ex…
AWolf81 May 24, 2019
8b82c44
Fix: Changed the function name
roottool May 24, 2019
3b473a5
Fix: Changed the function name
roottool May 24, 2019
2cffb50
Fix: Changed height of form
roottool May 24, 2019
b68b367
Toggle linting gutter with document.querySelector and style.display
AWolf81 May 25, 2019
4263309
Merge branch 'add-markdownlint-rules-form' of github.com:roottool/Boo…
AWolf81 May 25, 2019
02576c4
move enableMarkdownLint checkbox to customMarkdownLintConfig area (li…
AWolf81 May 25, 2019
1a38771
remove console.logs & improve error handling
AWolf81 May 26, 2019
c70cca2
remove console.log
AWolf81 May 26, 2019
63eb858
Hide markdown lint settings when markdown lint is disabled
Rokt33r May 26, 2019
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
124 changes: 79 additions & 45 deletions browser/components/CodeEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import {languageMaps} from '../lib/CMLanguageList'
import snippetManager from '../lib/SnippetManager'
import {generateInEditor, tocExistsInEditor} from 'browser/lib/markdown-toc-generator'
import markdownlint from 'markdownlint'
import Jsonlint from 'jsonlint-mod'
import { DEFAULT_CONFIG } from '../main/lib/ConfigManager'

CodeMirror.modeURL = '../node_modules/codemirror/mode/%N/%N.js'

Expand All @@ -38,38 +40,6 @@ function translateHotkey (hotkey) {
return hotkey.replace(/\s*\+\s*/g, '-').replace(/Command/g, 'Cmd').replace(/Control/g, 'Ctrl')
}

const validatorOfMarkdown = (text, updateLinting) => {
const lintOptions = {
'strings': {
'content': text
}
}

return markdownlint(lintOptions, (err, result) => {
if (!err) {
const foundIssues = []
result.content.map(item => {
let ruleNames = ''
item.ruleNames.map((ruleName, index) => {
ruleNames += ruleName
if (index === item.ruleNames.length - 1) {
ruleNames += ': '
} else {
ruleNames += '/'
}
})
foundIssues.push({
from: CodeMirror.Pos(item.lineNumber, 0),
to: CodeMirror.Pos(item.lineNumber, 1),
message: ruleNames + item.ruleDescription,
severity: 'warning'
})
})
updateLinting(foundIssues)
}
})
}

export default class CodeEditor extends React.Component {
constructor (props) {
super(props)
Expand Down Expand Up @@ -116,6 +86,8 @@ export default class CodeEditor extends React.Component {
this.searchHandler = (e, msg) => this.handleSearch(msg)
this.searchState = null
this.scrollToLineHandeler = this.scrollToLine.bind(this)
this.getCodeEditorLintConfig = this.getCodeEditorLintConfig.bind(this)
this.validatorOfMarkdown = this.validatorOfMarkdown.bind(this)

this.formatTable = () => this.handleFormatTable()

Expand Down Expand Up @@ -283,13 +255,12 @@ export default class CodeEditor extends React.Component {
}

componentDidMount () {
const { rulers, enableRulers } = this.props
const { rulers, enableRulers, enableMarkdownLint } = this.props
eventEmitter.on('line:jump', this.scrollToLineHandeler)

snippetManager.init()
this.updateDefaultKeyMap()

const checkMarkdownNoteIsOpening = this.props.mode === 'Boost Flavored Markdown'
this.value = this.props.value
this.editor = CodeMirror(this.refs.root, {
rulers: buildCMRulers(rulers, enableRulers),
Expand All @@ -306,10 +277,7 @@ export default class CodeEditor extends React.Component {
inputStyle: 'textarea',
dragDrop: false,
foldGutter: true,
lint: checkMarkdownNoteIsOpening ? {
'getAnnotations': validatorOfMarkdown,
'async': true
} : false,
lint: enableMarkdownLint ? this.getCodeEditorLintConfig() : false,
gutters: ['CodeMirror-linenumbers', 'CodeMirror-foldgutter', 'CodeMirror-lint-markers'],
autoCloseBrackets: {
pairs: this.props.matchingPairs,
Expand All @@ -320,6 +288,8 @@ export default class CodeEditor extends React.Component {
extraKeys: this.defaultKeyMap
})

document.querySelector('.CodeMirror-lint-markers').style.display = enableMarkdownLint ? 'inline-block' : 'none'

if (!this.props.mode && this.props.value && this.props.autoDetect) {
this.autoDetectLanguage(this.props.value)
} else {
Expand Down Expand Up @@ -546,7 +516,9 @@ export default class CodeEditor extends React.Component {
let needRefresh = false
const {
rulers,
enableRulers
enableRulers,
enableMarkdownLint,
customMarkdownLintConfig
} = this.props
if (prevProps.mode !== this.props.mode) {
this.setMode(this.props.mode)
Expand All @@ -564,6 +536,16 @@ export default class CodeEditor extends React.Component {
if (prevProps.keyMap !== this.props.keyMap) {
needRefresh = true
}
if (prevProps.enableMarkdownLint !== enableMarkdownLint || prevProps.customMarkdownLintConfig !== customMarkdownLintConfig) {
if (!enableMarkdownLint) {
this.editor.setOption('lint', {default: false})
document.querySelector('.CodeMirror-lint-markers').style.display = 'none'
} else {
this.editor.setOption('lint', this.getCodeEditorLintConfig())
document.querySelector('.CodeMirror-lint-markers').style.display = 'inline-block'
}
needRefresh = true
}

if (
prevProps.enableRulers !== enableRulers ||
Expand Down Expand Up @@ -644,6 +626,56 @@ export default class CodeEditor extends React.Component {
}
}

getCodeEditorLintConfig () {
const { mode } = this.props
const checkMarkdownNoteIsOpen = mode === 'Boost Flavored Markdown'

return checkMarkdownNoteIsOpen ? {
'getAnnotations': this.validatorOfMarkdown,
'async': true
} : false
}

validatorOfMarkdown (text, updateLinting) {
const { customMarkdownLintConfig } = this.props
let lintConfigJson
try {
Jsonlint.parse(customMarkdownLintConfig)
lintConfigJson = JSON.parse(customMarkdownLintConfig)
} catch (err) {
eventEmitter.emit('APP_SETTING_ERROR')
return
}
const lintOptions = {
'strings': {
'content': text
},
'config': lintConfigJson
}

return markdownlint(lintOptions, (err, result) => {
if (!err) {
const foundIssues = []
const splitText = text.split('\n')
result.content.map(item => {
let ruleNames = ''
item.ruleNames.map((ruleName, index) => {
ruleNames += ruleName
ruleNames += (index === item.ruleNames.length - 1) ? ': ' : '/'
})
const lineNumber = item.lineNumber - 1
foundIssues.push({
from: CodeMirror.Pos(lineNumber, 0),
to: CodeMirror.Pos(lineNumber, splitText[lineNumber].length),
message: ruleNames + item.ruleDescription,
severity: 'warning'
})
})
updateLinting(foundIssues)
}
})
}

setMode (mode) {
let syntax = CodeMirror.findModeByName(convertModeName(mode || 'text'))
if (syntax == null) syntax = CodeMirror.findModeByName('Plain Text')
Expand Down Expand Up @@ -1105,13 +1137,11 @@ export default class CodeEditor extends React.Component {
}
ref='root'
tabIndex='-1'
style={
{
style={{
fontFamily,
fontSize: fontSize,
width: width
}
}
}}
onDrop={
e => this.handleDropImage(e)
}
Expand Down Expand Up @@ -1149,7 +1179,9 @@ CodeEditor.propTypes = {
onChange: PropTypes.func,
readOnly: PropTypes.bool,
autoDetect: PropTypes.bool,
spellCheck: PropTypes.bool
spellCheck: PropTypes.bool,
enableMarkdownLint: PropTypes.bool,
customMarkdownLintConfig: PropTypes.string
}

CodeEditor.defaultProps = {
Expand All @@ -1161,5 +1193,7 @@ CodeEditor.defaultProps = {
indentSize: 4,
indentType: 'space',
autoDetect: false,
spellCheck: false
spellCheck: false,
enableMarkdownLint: DEFAULT_CONFIG.editor.enableMarkdownLint,
customMarkdownLintConfig: DEFAULT_CONFIG.editor.customMarkdownLintConfig
}
2 changes: 2 additions & 0 deletions browser/components/MarkdownEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,8 @@ class MarkdownEditor extends React.Component {
enableSmartPaste={config.editor.enableSmartPaste}
hotkey={config.hotkey}
switchPreview={config.editor.switchPreview}
enableMarkdownLint={config.editor.enableMarkdownLint}
customMarkdownLintConfig={config.editor.customMarkdownLintConfig}
/>
<MarkdownPreview styleName={this.state.status === 'PREVIEW'
? 'preview'
Expand Down
2 changes: 2 additions & 0 deletions browser/components/MarkdownSplitEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ class MarkdownSplitEditor extends React.Component {
enableSmartPaste={config.editor.enableSmartPaste}
hotkey={config.hotkey}
switchPreview={config.editor.switchPreview}
enableMarkdownLint={config.editor.enableMarkdownLint}
customMarkdownLintConfig={config.editor.customMarkdownLintConfig}
/>
<div styleName='slider' style={{left: this.state.codeEditorWidthInPercent + '%'}} onMouseDown={e => this.handleMouseDown(e)} >
<div styleName='slider-hitbox' />
Expand Down
8 changes: 7 additions & 1 deletion browser/main/lib/ConfigManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ const consts = require('browser/lib/consts')

let isInitialized = false

const DEFAULT_MARKDOWN_LINT_CONFIG = `{
"default": true
}`

export const DEFAULT_CONFIG = {
zoom: 1,
isSideNavFolded: false,
Expand Down Expand Up @@ -59,7 +63,9 @@ export const DEFAULT_CONFIG = {
enableFrontMatterTitle: true,
frontMatterTitleField: 'title',
spellcheck: false,
enableSmartPaste: false
enableSmartPaste: false,
enableMarkdownLint: false,
customMarkdownLintConfig: DEFAULT_MARKDOWN_LINT_CONFIG
},
preview: {
fontSize: '14',
Expand Down
34 changes: 33 additions & 1 deletion browser/main/modals/PreferencesModal/UiTab.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ class UiTab extends React.Component {
componentDidMount () {
CodeMirror.autoLoadMode(this.codeMirrorInstance.getCodeMirror(), 'javascript')
CodeMirror.autoLoadMode(this.customCSSCM.getCodeMirror(), 'css')
CodeMirror.autoLoadMode(this.customMarkdownLintConfigCM.getCodeMirror(), 'javascript')
this.customCSSCM.getCodeMirror().setSize('400px', '400px')
this.customMarkdownLintConfigCM.getCodeMirror().setSize('400px', '200px')
this.handleSettingDone = () => {
this.setState({UiAlert: {
type: 'success',
Expand Down Expand Up @@ -101,7 +103,9 @@ class UiTab extends React.Component {
matchingTriples: this.refs.matchingTriples.value,
explodingPairs: this.refs.explodingPairs.value,
spellcheck: this.refs.spellcheck.checked,
enableSmartPaste: this.refs.enableSmartPaste.checked
enableSmartPaste: this.refs.enableSmartPaste.checked,
enableMarkdownLint: this.refs.enableMarkdownLint.checked,
customMarkdownLintConfig: this.customMarkdownLintConfigCM.getCodeMirror().getValue()
},
preview: {
fontSize: this.refs.previewFontSize.value,
Expand Down Expand Up @@ -637,6 +641,34 @@ class UiTab extends React.Component {
/>
</div>
</div>
<div styleName='group-section'>
<div styleName='group-section-label'>
{i18n.__('Custom MarkdownLint Rules')}
</div>
<div styleName='group-section-control'>
<input onChange={(e) => this.handleUIChange(e)}
checked={this.state.config.editor.enableMarkdownLint}
ref='enableMarkdownLint'
type='checkbox'
/>&nbsp;
{i18n.__('Enable MarkdownLint')}
<div style={{fontFamily, display: this.state.config.editor.enableMarkdownLint ? 'block' : 'none'}}>
<ReactCodeMirror
width='400px'
height='200px'
onChange={e => this.handleUIChange(e)}
ref={e => (this.customMarkdownLintConfigCM = e)}
value={config.editor.customMarkdownLintConfig}
options={{
lineNumbers: true,
mode: 'application/json',
theme: codemirrorTheme,
lint: true,
gutters: ['CodeMirror-linenumbers', 'CodeMirror-foldgutter', 'CodeMirror-lint-markers']
}} />
</div>
</div>
</div>

<div styleName='group-header2'>{i18n.__('Preview')}</div>
<div styleName='group-section'>
Expand Down
6 changes: 6 additions & 0 deletions lib/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@
border-left-color: rgba(142, 142, 142, 0.5);
mix-blend-mode: difference;
}

.CodeMirror-lint-tooltip {
z-index: 1003;
}
</style>
</head>

Expand Down Expand Up @@ -126,7 +130,9 @@
<script src="../node_modules/codemirror/addon/dialog/dialog.js"></script>
<script src="../node_modules/codemirror/addon/display/rulers.js"></script>

<script src="../node_modules/jsonlint-mod/lib/jsonlint.js"></script>
<script src="../node_modules/codemirror/addon/lint/lint.js"></script>
<script src="../node_modules/codemirror/addon/lint/json-lint.js"></script>

<script src="../node_modules/raphael/raphael.min.js"></script>
<script src="../node_modules/flowchart.js/release/flowchart.min.js"></script>
Expand Down
1 change: 1 addition & 0 deletions locales/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
"Matching character pairs": "自動補完する括弧ペアの列記",
"Matching character triples": "自動補完する3文字括弧の列記",
"Exploding character pairs": "改行時に空行を挿入する括弧ペアの列記",
"Custom MarkdownLint Rules": "カスタムMarkdownLintルール",
"Preview": "プレビュー",
"Preview Font Size": "プレビュー時フォントサイズ",
"Preview Font Family": "プレビュー時フォント",
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
"immutable": "^3.8.1",
"invert-color": "^2.0.0",
"js-yaml": "^3.12.0",
"jsonlint-mod": "^1.7.4",
"katex": "^0.9.0",
"lodash": "^4.11.1",
"lodash-move": "^1.1.1",
Expand Down
Loading