Skip to content

Commit

Permalink
Fix: XBEL parser didn't retain ordering
Browse files Browse the repository at this point in the history
fixes #113
  • Loading branch information
marcelklehr committed Mar 9, 2019
1 parent 57c002c commit 0185bef
Showing 1 changed file with 23 additions and 33 deletions.
56 changes: 23 additions & 33 deletions src/lib/adapters/WebDav.js
Original file line number Diff line number Diff line change
Expand Up @@ -378,40 +378,30 @@ function parseXbelDoc(xbelDoc, rootFolder) {
}

function parseXbelFolder(xbelObj, folder) {
/* parse bookmarks first, breadth first */

let bookmarkList = getElementsByNodeName(
xbelObj.childNodes,
'bookmark',
1 /* element type */
)

bookmarkList.forEach(bookmark => {
let bm = new Bookmark({
id: parseInt(bookmark.id),
parentId: folder.id,
url: bookmark.getAttribute('href'),
title: bookmark.firstElementChild.textContent
})

folder.children.push(bm)
})

let folderList = getElementsByNodeName(
xbelObj.childNodes,
'folder',
1 /* element type */
)
/* parse depth first */

xbelObj.childNodes.forEach(node => {
let item
if (node.tagName && node.tagName === 'bookmark') {
item = new Bookmark({
id: parseInt(node.id),
parentId: folder.id,
url: node.getAttribute('href'),
title: node.firstElementChild.textContent
})
} else if (node.tagName && node.tagName === 'folder') {
Logger.log('Adding folder "' + node.firstElementChild.textContent + '"')
item = new Folder({
id: parseInt(node.getAttribute('id')),
title: node.firstElementChild.textContent,
parentId: folder.id
})
parseXbelFolder(node, item)
} else {
return
}

folderList.forEach(bmFolder => {
Logger.log('Adding folder :' + bmFolder.firstElementChild.textContent + ':')
let newFolder = new Folder({
id: parseInt(bmFolder.getAttribute('id')),
title: bmFolder.firstElementChild.textContent,
parentId: folder.id
})
folder.children.push(newFolder)
parseXbelFolder(bmFolder, newFolder)
folder.children.push(item)
})
}

Expand Down

0 comments on commit 0185bef

Please sign in to comment.