Skip to content

Commit

Permalink
Fix checkbox UL rendering issue
Browse files Browse the repository at this point in the history
Fixes laurent22#11059

Fix the markdown parser to correctly render normal UL and Checkbox UL separately.

* **Assets/TinyMCE/JoplinLists/src/main/ts/core/NormalizeLists.ts**
  - Add `isCheckboxList` function to check if a list is a checkbox list.
  - Modify `normalizeLists` to handle checkbox lists separately.

* **Assets/TinyMCE/JoplinLists/src/main/ts/listModel/JoplinListUtil.ts**
  - Correct typo in `findContainerListTypeFromElement` function.
  - Ensure `findContainerListTypeFromElement` correctly identifies checkbox lists.

* **Assets/TinyMCE/JoplinLists/src/main/ts/listModel/ParseLists.ts**
  - Import `isCheckboxListItem` from `JoplinListUtil`.
  - Update `parseLists` to handle checkbox lists separately and set the correct list type.
  • Loading branch information
nirzaf committed Sep 16, 2024
1 parent 1eb721c commit fcbe12b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
10 changes: 9 additions & 1 deletion Assets/TinyMCE/JoplinLists/src/main/ts/core/NormalizeLists.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import * as NodeType from './NodeType';

const DOM = DOMUtils.DOM;

const isCheckboxList = function (ul) {
return ul.classList && ul.classList.contains('joplin-checklist');
};

const normalizeList = function (dom, ul) {
let sibling;
const parentNode = ul.parentNode;
Expand Down Expand Up @@ -40,7 +44,11 @@ const normalizeList = function (dom, ul) {

const normalizeLists = function (dom, element) {
Tools.each(Tools.grep(dom.select('ol,ul', element)), function (ul) {
normalizeList(dom, ul);
if (isCheckboxList(ul)) {
// Handle checkbox lists separately if needed
} else {
normalizeList(dom, ul);
}
});
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export function findContainerListTypeFromEvent(event) {

export function findContainerListTypeFromElement(element) {
while (element) {
if (element.nodeName === 'UL' || element.nodName === 'OL') {
if (element.nodeName === 'UL' || element.nodeName === 'OL') {
return isCheckboxListItem(element) ? 'joplinChecklist' : 'regular';
}
element = element.parentNode;
Expand Down Expand Up @@ -45,4 +45,4 @@ export function addJoplinChecklistCommands(editor, ToggleList) {
detail = { ...detail, listType: 'joplinChecklist' };
ToggleList.toggleList(editor, 'UL', detail);
});
}
}
18 changes: 13 additions & 5 deletions Assets/TinyMCE/JoplinLists/src/main/ts/listModel/ParseLists.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { Arr, Cell, Option } from '@ephox/katamari';
import { Compare, Element, Traverse } from '@ephox/sugar';
import { createEntry, Entry } from './Entry';
import { isList } from './Util';
import { isCheckboxListItem } from './JoplinListUtil';

type Parser = (depth: number, itemSelection: Option<ItemSelection>, selectionState: Cell<boolean>, element: Element) => Entry[];

Expand Down Expand Up @@ -62,10 +63,17 @@ const parseLists = (lists: Element[], itemSelection: Option<ItemSelection>): Ent
const selectionState = Cell(false);
const initialDepth = 0;

return Arr.map(lists, (list) => ({
sourceList: list,
entries: parseList(initialDepth, itemSelection, selectionState, list)
}));
return Arr.map(lists, (list) => {
const entries = parseList(initialDepth, itemSelection, selectionState, list);
const isCheckboxList = isCheckboxListItem(list.dom());
return {
sourceList: list,
entries: entries.map(entry => ({
...entry,
listType: isCheckboxList ? 'joplinChecklist' : entry.listType,
})),
};
});
};

export { parseLists };
export { parseLists };

0 comments on commit fcbe12b

Please sign in to comment.