Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/858/checkboxtoggle #861

Merged
merged 17 commits into from
Aug 5, 2022
Merged
Show file tree
Hide file tree
Changes from 4 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
1 change: 0 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 36 additions & 1 deletion src/components/EditorMarkdownIt.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default {
})

md.use(require('markdown-it-task-checkbox'), {
disabled: true,
disabled: false,
korelstar marked this conversation as resolved.
Show resolved Hide resolved
liClass: 'task-list-item',
})

Expand All @@ -41,6 +41,7 @@ export default {

watch: {
value: 'onUpdate',
html: 'onChange',
},

created() {
Expand All @@ -52,6 +53,40 @@ export default {
onUpdate() {
this.html = this.md.render(this.value)
},

onChange() {
const markdown = this.value
const updateFunction = this.updateMarkdown
const items = document.getElementsByClassName('task-list-item')
for (let i = 0; i < items.length; ++i) {
items[i].addEventListener('click', function() {
const wasChecked = !this.children[0].checked

let idOfCheckbox = 0
const markdownLines = markdown.split('\n')
markdownLines.forEach((line, i) => {
if (line.trim().startsWith('- [x]') || line.trim().startsWith('- [ ]')) {
newhinton marked this conversation as resolved.
Show resolved Hide resolved
if ('cbx_' + idOfCheckbox === this.children[0].id) {
if (wasChecked) {
markdownLines[i] = markdownLines[i].replace('[x]', '[ ]')
markdownLines[i] = markdownLines[i].replace('[X]', '[ ]')
} else {
markdownLines[i] = markdownLines[i].replace('[ ]', '[x]')
}
}
idOfCheckbox++
}
})
updateFunction(markdownLines.join('\n'))
})
}
},

updateMarkdown(newMarkdown) {
this.$emit('input', newMarkdown)
this.onUpdate()
},

setImageRule(id) {
// https://github.com/markdown-it/markdown-it/blob/master/docs/architecture.md#renderer
// Remember old renderer, if overridden, or proxy to default renderer
Expand Down
6 changes: 5 additions & 1 deletion src/components/Note.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@
<div v-show="!note.content" class="placeholder">
{{ preview ? t('notes', 'Empty note') : t('notes', 'Write …') }}
</div>
<ThePreview v-if="preview" :value="note.content" :noteid="noteId" />
<ThePreview v-if="preview"
:value="note.content"
:noteid="noteId"
@input="onEdit"
/>
<TheEditor v-else
:value="note.content"
:noteid="noteId"
Expand Down