Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
40 changes: 39 additions & 1 deletion browser/components/CodeEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import TurndownService from 'turndown'
import {
gfm
} from 'turndown-plugin-gfm'
import markdownlint from 'markdownlint'

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

Expand Down Expand Up @@ -117,6 +118,38 @@ const languageMaps = {
elixir: 'Elixir'
}

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 @@ -344,7 +377,12 @@ export default class CodeEditor extends React.Component {
inputStyle: 'textarea',
dragDrop: false,
foldGutter: true,
gutters: ['CodeMirror-linenumbers', 'CodeMirror-foldgutter'],
lint: {
'getAnnotations': validatorOfMarkdown,
'async': true
},
mode: 'markdown',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't use markdown mode here. We set the mode according to the props or self-detecting language result if the CodeEditor is used in snippet note.
https://github.com/BoostIO/Boostnote/blob/885f656d3458af090c62f81b4f8a1c775effcdc6/browser/components/CodeEditor.js#L357-L361

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understood.
I fixed it. Please check it again.

gutters: ['CodeMirror-linenumbers', 'CodeMirror-foldgutter', 'CodeMirror-lint-markers'],
autoCloseBrackets: {
pairs: this.props.matchingPairs,
triples: this.props.matchingTriples,
Expand Down
6 changes: 5 additions & 1 deletion lib/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<link rel="stylesheet" href="../node_modules/codemirror/lib/codemirror.css">
<link rel="stylesheet" href="../node_modules/katex/dist/katex.min.css">
<link rel="stylesheet" href="../node_modules/codemirror/addon/dialog/dialog.css">
<link rel="stylesheet" href="../node_modules/codemirror/addon/lint/lint.css">
<link rel="stylesheet" href="../extra_scripts/codemirror/mode/bfm/bfm.css">

<title>Boostnote</title>
Expand Down Expand Up @@ -125,6 +126,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/codemirror/addon/lint/lint.js"></script>
<script src="../node_modules/codemirror/mode/markdown/markdown.js"></script>

<script src="../node_modules/raphael/raphael.min.js"></script>
<script src="../node_modules/flowchart.js/release/flowchart.min.js"></script>
<script>
Expand Down Expand Up @@ -154,4 +158,4 @@
</style>
</body>

</html>
</html>
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@
"jest-localstorage-mock": "^2.2.0",
"jsdom": "^9.4.2",
"json-loader": "^0.5.4",
"markdownlint": "^0.11.0",
"merge-stream": "^1.0.0",
"mock-require": "^3.0.1",
"nib": "^1.1.0",
Expand Down