blob: f02d6c0f813957ff5c9fa7504fbcbb1d3626d857 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
/**
* This method parses raw markdown text in GFM input field and toggles checkboxes
* based on checkboxChecked property.
*
* @param {Object} object containing rawMarkdown, sourcepos, checkboxChecked properties
* @returns String with toggled checkboxes
*/
export const toggleMarkCheckboxes = ({ rawMarkdown, sourcepos, checkboxChecked }) => {
// Extract the description text
const [startRange] = sourcepos.split('-');
let [startRow] = startRange.split(':');
startRow = Number(startRow) - 1;
// Mark/Unmark the checkboxes
return rawMarkdown
.split('\n')
.map((row, index) => {
if (startRow === index) {
if (checkboxChecked) {
return row.replace(/\[ \]/, '[x]');
}
return row.replace(/\[[x~]\]/i, '[ ]');
}
return row;
})
.join('\n');
};
|