Skip to content

Commit eee3403

Browse files
authored
Merge pull request #2460 from ZeroX-DG/linethrough-checkbox
Added linethrough checkbox & make it optional
2 parents a2bc1a5 + 8936d8b commit eee3403

File tree

7 files changed

+31
-4
lines changed

7 files changed

+31
-4
lines changed

browser/components/MarkdownPreview.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,10 @@ export default class MarkdownPreview extends React.Component {
483483
eventEmitter.on('export:save-md', this.saveAsMdHandler)
484484
eventEmitter.on('export:save-html', this.saveAsHtmlHandler)
485485
eventEmitter.on('print', this.printHandler)
486+
eventEmitter.on('config-renew', () => {
487+
this.markdown.updateConfig()
488+
this.rewriteIframe()
489+
})
486490
}
487491

488492
componentWillUnmount () {

browser/components/markdown.styl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ li
8080
&.checked
8181
text-decoration line-through
8282
opacity 0.5
83+
&.taskListItem.checked
84+
text-decoration line-through
85+
opacity 0.5
8386
div.math-rendered
8487
text-align center
8588
.math-failed

browser/lib/markdown.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import _ from 'lodash'
77
import ConfigManager from 'browser/main/lib/ConfigManager'
88
import katex from 'katex'
99
import { lastFindInArray } from './utils'
10+
import ee from 'browser/main/lib/eventEmitter'
1011

1112
function createGutter (str, firstLineNumber) {
1213
if (Number.isNaN(firstLineNumber)) firstLineNumber = 1
@@ -20,7 +21,7 @@ function createGutter (str, firstLineNumber) {
2021

2122
class Markdown {
2223
constructor (options = {}) {
23-
const config = ConfigManager.get()
24+
let config = ConfigManager.get()
2425
const defaultOptions = {
2526
typographer: config.preview.smartQuotes,
2627
linkify: true,
@@ -223,7 +224,11 @@ class Markdown {
223224
if (!liToken.attrs) {
224225
liToken.attrs = []
225226
}
226-
liToken.attrs.push(['class', 'taskListItem'])
227+
if (config.preview.lineThroughCheckbox) {
228+
liToken.attrs.push(['class', `taskListItem${match[1] !== ' ' ? ' checked' : ''}`])
229+
} else {
230+
liToken.attrs.push(['class', 'taskListItem'])
231+
}
227232
}
228233
content = `<label class='taskListItem${match[1] !== ' ' ? ' checked' : ''}' for='checkbox-${startLine + 1}'><input type='checkbox'${match[1] !== ' ' ? ' checked' : ''} id='checkbox-${startLine + 1}'/> ${content.substring(4, content.length)}</label>`
229234
}
@@ -260,6 +265,9 @@ class Markdown {
260265
}
261266
// FIXME We should not depend on global variable.
262267
window.md = this.md
268+
this.updateConfig = () => {
269+
config = ConfigManager.get()
270+
}
263271
}
264272

265273
render (content) {

browser/main/lib/ConfigManager.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ export const DEFAULT_CONFIG = {
6565
smartArrows: false,
6666
allowCustomCSS: false,
6767
customCSS: '',
68-
sanitize: 'STRICT' // 'STRICT', 'ALLOW_STYLES', 'NONE'
68+
sanitize: 'STRICT', // 'STRICT', 'ALLOW_STYLES', 'NONE'
69+
lineThroughCheckbox: true
6970
},
7071
blog: {
7172
type: 'wordpress', // Available value: wordpress, add more types in the future plz

browser/main/modals/PreferencesModal/UiTab.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ class UiTab extends React.Component {
107107
smartArrows: this.refs.previewSmartArrows.checked,
108108
sanitize: this.refs.previewSanitize.value,
109109
allowCustomCSS: this.refs.previewAllowCustomCSS.checked,
110+
lineThroughCheckbox: this.refs.lineThroughCheckbox.checked,
110111
customCSS: this.customCSSCM.getCodeMirror().getValue()
111112
}
112113
}
@@ -512,6 +513,16 @@ class UiTab extends React.Component {
512513
</select>
513514
</div>
514515
</div>
516+
<div styleName='group-checkBoxSection'>
517+
<label>
518+
<input onChange={(e) => this.handleUIChange(e)}
519+
checked={this.state.config.preview.lineThroughCheckbox}
520+
ref='lineThroughCheckbox'
521+
type='checkbox'
522+
/>&nbsp;
523+
{i18n.__('Allow line through checkbox')}
524+
</label>
525+
</div>
515526
<div styleName='group-checkBoxSection'>
516527
<label>
517528
<input onChange={(e) => this.handleUIChange(e)}

tests/lib/snapshots/markdown-test.js.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Generated by [AVA](https://ava.li).
3131
3232
`<ul>␊
3333
<li class="taskListItem"><input type="checkbox" id="checkbox-2" /> Unchecked</li>␊
34-
<li class="taskListItem"><input type="checkbox" checked id="checkbox-3" /> Checked</li>␊
34+
<li class="taskListItem checked"><input type="checkbox" checked id="checkbox-3" /> Checked</li>␊
3535
</ul>␊
3636
`
3737

5 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)