Skip to content

Commit 0211f26

Browse files
committed
Add initialization class, eslint
1 parent e09409f commit 0211f26

27 files changed

+538
-507
lines changed

.eslintrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
"html/indent": "0",
66
"html/report-bad-indent": "error"
77
},
8+
"rules": {
9+
"indent": ["error", 4]
10+
},
811
"env": {
912
"browser": true
1013
},

index.html

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66
<title>luogu-markdown-editor</title>
77
</head>
88
<body>
9-
<div id="editor">
10-
<luogu-markdown-editor v-model="code"></luogu-markdown-editor>
11-
</div>
9+
<div id="editor"></div>
1210
<script src="/dist/luogu-markdown-editor.js"></script>
11+
<script>
12+
var editor = new MarkdownPalettes("#editor")
13+
</script>
1314
</body>
1415
</html>

src/components/ContentParser.js

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
11
import { MarkdownParser } from './plugin/MarkdownParser'
22

33
export function ContentParser (content, parsers) {
4-
let md5 = require('md5')
4+
let md5 = require('md5')
55

6-
let newContent = content
7-
let stringMap = []
6+
let newContent = content
7+
let stringMap = []
88

9-
parsers.forEach(function (parserConfig) {
10-
let segments = newContent.match(parserConfig.reg)
9+
parsers.forEach(function (parserConfig) {
10+
let segments = newContent.match(parserConfig.reg)
1111

12-
if (segments) {
13-
segments.forEach(function (segment) {
14-
let mapItem = {
15-
hash: '$' + md5(segment) + '$',
16-
segment: segment,
17-
content: parserConfig.parser(segment)
12+
if (segments) {
13+
segments.forEach(function (segment) {
14+
let mapItem = {
15+
hash: '$' + md5(segment) + '$',
16+
segment: segment,
17+
content: parserConfig.parser(segment)
18+
}
19+
newContent = newContent.replace(segment, mapItem.hash)
20+
stringMap.push(mapItem)
21+
})
1822
}
19-
newContent = newContent.replace(segment, mapItem.hash)
20-
stringMap.push(mapItem)
21-
})
22-
}
23-
})
23+
})
2424

25-
newContent = MarkdownParser(newContent, stringMap)
25+
newContent = MarkdownParser(newContent, stringMap)
2626

27-
stringMap.forEach(function (mapItem) {
28-
newContent = newContent.replace(mapItem.hash, mapItem.content)
29-
})
27+
stringMap.forEach(function (mapItem) {
28+
newContent = newContent.replace(mapItem.hash, mapItem.content)
29+
})
3030

31-
return newContent
31+
return newContent
3232
}

src/components/DefaultConfig.js

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,31 @@ import { defaultBtns, getBtns } from './toolbar-button/toolbarBtn'
33
import _ from 'lodash'
44

55
function set (obj, config) {
6-
for (let key in config) {
7-
if (typeof obj[key] === 'object' && !Array.isArray(obj[key])) {
8-
set(obj[key], config)
6+
for (let key in config) {
7+
if (typeof obj[key] === 'object' && !Array.isArray(obj[key])) {
8+
set(obj[key], config)
9+
}
10+
obj[key] = config[key]
911
}
10-
obj[key] = config[key]
11-
}
12-
return obj
12+
return obj
1313
}
1414

1515
export let defaultConfig = {
16-
height: '500px',
17-
previewDisplay: 'normal',
18-
fullscreen: false,
19-
parsers: [
20-
KatexParser
21-
],
22-
toolbarConfig: defaultBtns,
23-
editorOption: {
24-
mode: 'markdown',
25-
lineNumbers: true,
26-
lineWrapping: true
27-
}
16+
height: '500px',
17+
previewDisplay: 'normal',
18+
fullscreen: false,
19+
parsers: [
20+
KatexParser
21+
],
22+
toolbarConfig: defaultBtns,
23+
editorOption: {
24+
mode: 'markdown',
25+
lineNumbers: true,
26+
lineWrapping: true
27+
}
2828
}
2929

3030
export function getConfig (config) {
31-
if (config.toolbarConfig !== undefined) { config.toolbarConfig = getBtns(config.toolbarConfig) }
32-
return set(_.cloneDeep(defaultConfig), config)
31+
if (config.toolbarConfig !== undefined) { config.toolbarConfig = getBtns(config.toolbarConfig) }
32+
return set(_.cloneDeep(defaultConfig), config)
3333
}

src/components/Dialog.vue

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -139,40 +139,40 @@
139139
import 'font-awesome/css/font-awesome.css'
140140
141141
export default {
142-
name: 'editor-dialog',
143-
props: {
144-
request: {
145-
type: Object
146-
}
147-
},
148-
data () {
149-
return {
150-
responseData: {}
151-
}
152-
},
153-
computed: {
154-
response () {
155-
let res = this.request
156-
res.data = this.responseData
157-
return res
158-
}
159-
},
160-
mounted () {
161-
let initialData = {}
162-
163-
this.request.body.forEach(function (field) {
164-
initialData[field.name] = field.default ? field.default : ''
165-
})
166-
167-
this.responseData = initialData
168-
},
169-
methods: {
170-
close () {
171-
this.$emit('close')
142+
name: 'editor-dialog',
143+
props: {
144+
request: {
145+
type: Object
146+
}
172147
},
173-
finish () {
174-
this.$emit('finish', this.response)
148+
data () {
149+
return {
150+
responseData: {}
151+
}
152+
},
153+
computed: {
154+
response () {
155+
let res = this.request
156+
res.data = this.responseData
157+
return res
158+
}
159+
},
160+
mounted () {
161+
let initialData = {}
162+
163+
this.request.body.forEach(function (field) {
164+
initialData[field.name] = field.default ? field.default : ''
165+
})
166+
167+
this.responseData = initialData
168+
},
169+
methods: {
170+
close () {
171+
this.$emit('close')
172+
},
173+
finish () {
174+
this.$emit('finish', this.response)
175+
}
175176
}
176-
}
177177
}
178178
</script>

src/components/InputArea.vue

Lines changed: 59 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -14,71 +14,74 @@ import {codemirror} from 'vue-codemirror-lite'
1414
import 'codemirror/mode/markdown/markdown.js'
1515
1616
export default {
17-
name: 'input-area',
18-
props: {
19-
value: {
20-
type: String
17+
name: 'input-area',
18+
props: {
19+
value: {
20+
type: String
21+
},
22+
editorOption: {
23+
type: Object
24+
},
25+
height: {
26+
type: String,
27+
default: '400px'
28+
},
29+
insertCode: {
30+
default: null
31+
}
2132
},
22-
editorOption: {
23-
type: Object
33+
computed: {
34+
editor () {
35+
return this.$refs.editor.editor
36+
}
2437
},
25-
height: {
26-
type: String,
27-
default: '400px'
28-
},
29-
insertCode: {
30-
default: null
31-
}
32-
},
33-
computed: {
34-
editor () {
35-
return this.$refs.editor.editor
36-
}
37-
},
38-
watch: {
39-
insertCode: function (insert) {
40-
if (insert === null) {
41-
return
42-
}
38+
watch: {
39+
insertCode (insert) {
40+
if (insert === null) {
41+
return
42+
}
4343
44-
if (typeof insert === 'function') { insert = insert() }
44+
if (typeof insert === 'function') { insert = insert() }
4545
46-
if (!Array.isArray(insert)) {
47-
insert = [insert, '']
48-
}
46+
if (!Array.isArray(insert)) {
47+
insert = [insert, '']
48+
}
4949
50-
let cursor = this.editor.getCursor()
51-
let selection = this.editor.getSelection()
50+
let cursor = this.editor.getCursor()
51+
let selection = this.editor.getSelection()
5252
53-
this.editor.replaceSelection(insert[0] + selection + insert[1])
53+
this.editor.replaceSelection(insert[0] + selection + insert[1])
5454
55-
if (selection === '') {
56-
this.editor.setCursor(cursor.line, cursor.ch + 2)
57-
}
55+
if (selection === '') {
56+
this.editor.setCursor(cursor.line, cursor.ch + 2)
57+
}
5858
59-
this.$emit('finish')
59+
this.$emit('finish')
60+
},
61+
height (newHeight) {
62+
this.editor.setSize('100%', newHeight)
63+
},
64+
value (newValue) {
65+
this.code = newValue
66+
}
6067
},
61-
height: function (newHeight) {
62-
this.editor.setSize('100%', newHeight)
63-
}
64-
},
65-
data: function () {
66-
return {
67-
code: ''
68-
}
69-
},
70-
components: {
71-
codemirror
72-
},
73-
mounted: function () {
74-
this.code = this.value
75-
this.editor.setSize('100%', this.height)
76-
this.editor.focus()
77-
},
78-
methods: {
79-
updateCode (code) {
80-
this.$emit('input', code)
68+
data: function () {
69+
return {
70+
code: ''
71+
}
72+
},
73+
components: {
74+
codemirror
75+
},
76+
mounted: function () {
77+
this.code = this.value
78+
this.editor.setSize('100%', this.height)
79+
this.editor.focus()
80+
},
81+
methods: {
82+
updateCode (code) {
83+
this.$emit('input', code)
84+
}
8185
}
82-
}
8386
}
8487
</script>

0 commit comments

Comments
 (0)