Replies: 2 comments 3 replies
-
Thanks for suggesting – you're proposing changes to Markdown processing, which is an upstream issue and as we already stated in one of your other feature suggestions 😊 Regarding storage of checkbox state – this could be implemented by persisting it to local storage, but is considered out-of-scope for this project, because of its rather limited use. Custom JavaScript to the rescue! |
Beta Was this translation helpful? Give feedback.
-
In case it helps I wrote a quick script to achieve this. How it worksIt stores an array in localstorage with the checked checkboxes. Each item has a key composed of: This key structure allows me to have multiple items in the same (or different) page with the same text. Also allows to add more items to the list without loosing the right selected items. Note If the text changes or you add more lists in the same webpage that not after the existing checklists, the selected values will disappear or be in conflict Implementationin mkdocs load the custom script:
Save the custom script // script.js
// Logic to keep the checkboxes state
const allLists = Array.from(document.querySelectorAll(".task-list"))
const LOCALSTORAGE_KEY = "checkedItems"
window.addEventListener('load', () => {
const path = window.location.pathname
let checkedItems = localStorage.getItem(LOCALSTORAGE_KEY)
if (!checkedItems)
checkedItems = []
else
checkedItems = JSON.parse(checkedItems)
allLists.forEach((list, listIndex) => {
const items = Array.from(list.querySelectorAll(".task-list-item"))
items.forEach((item) => {
const text = item.textContent
const itemKey = `${path}:${listIndex}:${text}`
if (checkedItems.includes(itemKey)) {
const checkbox = item.querySelector('input[type="checkbox"]')
checkbox.checked = true
}
})
})
})
document.body.addEventListener('click', (e) => {
if (!e.target.matches('.task-list-item label input'))
return
const checkbox = e.target
const checked = checkbox.checked
const li = checkbox.parentElement.parentElement
const text = li.textContent
const list = li.parentElement
const listIndex = allLists.indexOf(list)
const path = window.location.pathname
const itemKey = `${path}:${listIndex}:${text}`
let checkedItems = JSON.parse(localStorage.getItem(LOCALSTORAGE_KEY))
if (!checkedItems)
checkedItems = []
// Ensure we don't have duplicates by always removing the item first
checkedItems = checkedItems.filter(i => i !== itemKey)
if (checked)
checkedItems.push(itemKey)
localStorage.setItem(LOCALSTORAGE_KEY, JSON.stringify(checkedItems))
}) |
Beta Was this translation helpful? Give feedback.
-
Context
If we have this clickable_checkbox, it is usually discouraged to use it alone.
Yet, can I somehow customize or we somehow implement such convenient features that the users can have certain storage for those boxes?
Issue Description
Expected Behaviour
The clickable checkbox will be saved even if the user refreshes the page
Actual Behaviour
Any of the checkbox will always be reset each time the user refreshes the page
Minimal Base Yaml
Related Links
https://facelessuser.github.io/pymdown-extensions/extensions/tasklist/?h=tasklist
https://squidfunk.github.io/mkdocs-material/setup/extensions/python-markdown-extensions/?h=tasklist#tasklist
Configuration
Latest version mkdocs.
Latest version insider pymdown.
Local-host: Acer Nitro 5 Laptop
Online-host: Gitlab
System: Window
Browser: Chrome
Suggestion
I suggest to use a specific storage system (a certain directory that can be customized) somehow that is convenient for the writer to learn how to do, as well as easy for the reader to use the feature.
Interactable Checkbox
[ ]:text
- Unclickable Disabled Checkbox[_]:text
- Clickable Disabled Checkbox[X]:text
- Unclickable Enabled Checkbox[*]:text
- Clickable Enabled Checkbox[$]:text
- Unclickable Removed Checkbox Line (straight through the text and add little shady effect)[~]:text
- Clickable Removed Checkbox Line (straight through the text and add little shady effect)[!]:text
- Unclickable Highlight Checkbox Line[@]:text
- Clickable Anchor Checkbox Line[%]:text
- Unclickable Draggable Checkbox Line[&]:text
- Clickable Draggable Checkbox Line[?]{ reset="false" }:text
- If writer want to reset the checkbox upon user's refresh (recommended for clickable checkbox)Note: [?] means any of above 10 basic properties [ ] [_] [X] [*] [$] [~] [!] [@] [%] [&]
_Those last 4 (~$@!) might be niche and should not be prioritized
Might be incompatibilities with admonitions, abbr
Feedback Button
[:icon:]
- Make a feedback button with visible counters[!:icon:]
- Make a feedback button with invisible counters[:icon:#id]
- Use #... for specific index, for example #2702[:icon:+]
- Share the id information, + for incremental from the last (making another one)[:icon:=]
- Share the id information, = for the exact from the last[:icon:-]
- Share the id information, - for incremental from the last (go back to previous one)[:icon:]{ hover="..." }
Text upon hoveringUsing yaml to use directory
path/to/dir/*.icon
Those last 3 (discremental, hover, yaml) might be niche and should not be prioritized
If both button share id, only one can be counted, for example:
Application
Specifically saying, I am writing a wiki for an algorithm, and I have a list of problems that users can try. Intendedly I wanna use checkbox to help the user mark the problems they have solved so far, as there will be many hard problems that need a long time to think.
Also, it might improve the interactivity of the feedback on the pages (Might be overengineering if spamming).
Before Startings The Discussions
master
(for the sake of overall functionality).Beta Was this translation helpful? Give feedback.
All reactions