Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
f3606d78
Commit
f3606d78
authored
May 14, 2021
by
Brett Walker
Committed by
Miguel Rincon
May 14, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix checkboxes in Markdown tables
parent
427d1b2f
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
63 additions
and
13 deletions
+63
-13
app/assets/javascripts/task_list.js
app/assets/javascripts/task_list.js
+19
-2
changelogs/unreleased/bw-table-task-list.yml
changelogs/unreleased/bw-table-task-list.yml
+5
-0
spec/frontend/task_list_spec.js
spec/frontend/task_list_spec.js
+39
-11
No files found.
app/assets/javascripts/task_list.js
View file @
f3606d78
...
...
@@ -40,20 +40,37 @@ export default class TaskList {
taskListField
.
value
=
taskListField
.
dataset
.
value
;
});
$
(
this
.
taskListContainerSelector
).
taskList
(
'
enable
'
);
$
(
document
).
on
(
'
tasklist:changed
'
,
this
.
taskListContainerSelector
,
this
.
updateHandler
);
this
.
enable
();
}
getTaskListTarget
(
e
)
{
return
e
&&
e
.
currentTarget
?
$
(
e
.
currentTarget
)
:
$
(
this
.
taskListContainerSelector
);
}
// Disable any task items that don't have a data-sourcepos attribute, on the
// assumption that if it doesn't then it wasn't generated from our markdown parser.
// This covers the case of markdown not being able to handle task lists inside
// markdown tables. It also includes hand coded HTML lists.
disableNonMarkdownTaskListItems
(
e
)
{
this
.
getTaskListTarget
(
e
)
.
find
(
'
.task-list-item
'
)
.
not
(
'
[data-sourcepos]
'
)
.
find
(
'
.task-list-item-checkbox
'
)
.
prop
(
'
disabled
'
,
true
);
}
disableTaskListItems
(
e
)
{
this
.
getTaskListTarget
(
e
).
taskList
(
'
disable
'
);
}
enableTaskListItems
(
e
)
{
this
.
getTaskListTarget
(
e
).
taskList
(
'
enable
'
);
this
.
disableNonMarkdownTaskListItems
(
e
);
}
enable
()
{
this
.
enableTaskListItems
();
$
(
document
).
on
(
'
tasklist:changed
'
,
this
.
taskListContainerSelector
,
this
.
updateHandler
);
}
disable
()
{
...
...
changelogs/unreleased/bw-table-task-list.yml
0 → 100644
View file @
f3606d78
---
title
:
Disable unsupported task items in Markdown tables
merge_request
:
46060
author
:
type
:
fixed
spec/frontend/task_list_spec.js
View file @
f3606d78
...
...
@@ -16,7 +16,20 @@ describe('TaskList', () => {
beforeEach
(()
=>
{
setFixtures
(
`
<div class="task-list">
<div class="js-task-list-container"></div>
<div class="js-task-list-container">
<ul data-sourcepos="5:1-5:11" class="task-list" dir="auto">
<li data-sourcepos="5:1-5:11" class="task-list-item enabled">
<input type="checkbox" class="task-list-item-checkbox" checked=""> markdown task
</li>
</ul>
<ul class="task-list" dir="auto">
<li class="task-list-item enabled">
<input type="checkbox" class="task-list-item-checkbox"> hand-coded checkbox
</li>
</ul>
<textarea class="hidden js-task-list-field"></textarea>
</div>
</div>
`
);
...
...
@@ -59,32 +72,47 @@ describe('TaskList', () => {
describe
(
'
disableTaskListItems
'
,
()
=>
{
it
(
'
should call taskList method with disable param
'
,
()
=>
{
jest
.
spyOn
(
$
.
prototype
,
'
taskList
'
).
mockImplementation
(()
=>
{}
);
taskList
.
disableTaskListItems
(
);
taskList
.
disableTaskListItems
({
currentTarget
});
expect
(
currentTarget
.
taskList
).
toHaveBeenCalledWith
(
'
disable
'
);
expect
(
document
.
querySelectorAll
(
'
.task-list-item input:disabled
'
).
length
).
toEqual
(
2
);
});
});
describe
(
'
enableTaskListItems
'
,
()
=>
{
it
(
'
should call taskList method with enable param
'
,
()
=>
{
jest
.
spyOn
(
$
.
prototype
,
'
taskList
'
).
mockImplementation
(()
=>
{});
it
(
'
should enable markdown tasks and disable non-markdown tasks
'
,
()
=>
{
taskList
.
disableTaskListItems
();
taskList
.
enableTaskListItems
();
expect
(
document
.
querySelectorAll
(
'
.task-list-item input:enabled
'
).
length
).
toEqual
(
1
);
expect
(
document
.
querySelectorAll
(
'
.task-list-item input:disabled
'
).
length
).
toEqual
(
1
);
});
});
describe
(
'
enable
'
,
()
=>
{
it
(
'
should enable task list items and on document event
'
,
()
=>
{
jest
.
spyOn
(
$
.
prototype
,
'
on
'
).
mockImplementation
(()
=>
{});
taskList
.
enable
();
taskList
.
enableTaskListItems
({
currentTarget
});
expect
(
document
.
querySelectorAll
(
'
.task-list-item input:enabled
'
).
length
).
toEqual
(
1
);
expect
(
document
.
querySelectorAll
(
'
.task-list-item input:disabled
'
).
length
).
toEqual
(
1
);
expect
(
currentTarget
.
taskList
).
toHaveBeenCalledWith
(
'
enable
'
);
expect
(
$
(
document
).
on
).
toHaveBeenCalledWith
(
'
tasklist:changed
'
,
taskList
.
taskListContainerSelector
,
taskList
.
updateHandler
,
);
});
});
describe
(
'
disable
'
,
()
=>
{
it
(
'
should disable task list items and off document event
'
,
()
=>
{
jest
.
spyOn
(
taskList
,
'
disableTaskListItems
'
).
mockImplementation
(()
=>
{});
jest
.
spyOn
(
$
.
prototype
,
'
off
'
).
mockImplementation
(()
=>
{});
taskList
.
disable
();
expect
(
taskList
.
disableTaskListItems
).
toHaveBeenCalled
();
expect
(
document
.
querySelectorAll
(
'
.task-list-item input:disabled
'
).
length
).
toEqual
(
2
);
expect
(
$
(
document
).
off
).
toHaveBeenCalledWith
(
'
tasklist:changed
'
,
taskList
.
taskListContainerSelector
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment