Skip to content

Commit 69ef489

Browse files
jhildenbiddleQingWei-Li
authored andcommitted
fix: task list rendering (Fix #749) (#757)
This PR restores the task list presentation removed in 4.8: - Add “task-list-item” class to task list `<li>` elms - Hide list bullets on unordered task lists `<li>` elms It also provides several improvements on the pre-4.8 presentation: - Add “task-list” class to task list `<ul>` elms - Display list numbers on ordered task lists `<li>` elms - Render accessible task list items by wrapping checkbox and text in `<label>` elm - Allow task lists to be nested within standard ordered/unordered lists Please makes sure these boxes are checked before submitting your PR, thank you! * [x] Make sure you are merging your commits to `master` branch. * [x] Add some descriptions and refer relative issues for you PR. * [x] DO NOT include files inside `lib` directory.
1 parent c3345ba commit 69ef489

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/core/render/compiler.js

+17
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,23 @@ export class Compiler {
302302

303303
return `<img src="${url}"data-origin="${href}" alt="${text}"${attrs}>`
304304
}
305+
origin.list = renderer.list = function (body, ordered, start) {
306+
const isTaskList = /<li class="task-list-item">/.test(body.split('class="task-list"')[0])
307+
const isStartReq = start && start > 1
308+
const tag = ordered ? 'ol' : 'ul'
309+
const tagAttrs = [
310+
(isTaskList ? 'class="task-list"' : ''),
311+
(isStartReq ? `start="${start}"` : '')
312+
].join(' ').trim()
313+
314+
return `<${tag} ${tagAttrs}>${body}</${tag}>`
315+
}
316+
origin.listitem = renderer.listitem = function (text) {
317+
const isTaskItem = /^(<input.*type="checkbox"[^>]*>)/.test(text)
318+
const html = isTaskItem ? `<li class="task-list-item"><label>${text}</label></li>` : `<li>${text}</li>`
319+
320+
return html
321+
}
305322

306323
renderer.origin = origin
307324

src/themes/basic/_layout.styl

+3
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,9 @@ body.sticky
383383
border-radius 2px
384384
padding 1rem
385385

386+
.markdown-section ul.task-list > li
387+
list-style-type none
388+
386389
body.close
387390
.sidebar
388391
transform translateX(- $sidebar-width)

0 commit comments

Comments
 (0)