Created
August 15, 2025 10:57
-
-
Save Okkk7744/5cb75f9d298eea4b113af4c180d4a95b to your computer and use it in GitHub Desktop.
Export bookmarks from Dia
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import json, os, html | |
| src = os.path.expanduser("~/Library/Application Support/Dia/User Data/Default/Bookmarks") | |
| dst = os.path.expanduser("~/Desktop/bookmarks.html") | |
| with open(src, "r", encoding="utf-8") as f: | |
| data = json.load(f) | |
| lines = ['<!DOCTYPE NETSCAPE-Bookmark-file-1>', | |
| '<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">', | |
| '<TITLE>Bookmarks</TITLE><H1>Bookmarks</H1><DL><p>'] | |
| def dump_node(node, indent=1): | |
| pad = " " * indent | |
| t = node.get('type') | |
| if t == 'folder': | |
| lines.append(f'{pad}<DT><H3>{html.escape(node.get("name",""))}</H3>') | |
| lines.append(f'{pad}<DL><p>') | |
| for c in node.get('children', []): | |
| dump_node(c, indent+1) | |
| lines.append(f'{pad}</DL><p>') | |
| elif t == 'url': | |
| name = html.escape(node.get('name',"")) | |
| url = html.escape(node.get('url',"")) | |
| lines.append(f'{pad}<DT><A HREF="{url}">{name}</A>') | |
| roots = data.get('roots', {}) | |
| for key in ['bookmark_bar', 'other', 'synced']: | |
| root = roots.get(key) | |
| if root: | |
| dump_node(root, 1) | |
| lines.append('</DL><p>') | |
| with open(dst, "w", encoding="utf-8") as f: | |
| f.write("\n".join(lines)) | |
| print("Exported to:", dst) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for this Gist, worked like a charm!