Skip to content

Instantly share code, notes, and snippets.

@aslamanver
Created June 14, 2025 01:47
Show Gist options
  • Save aslamanver/d1191435acf68d72ed5a1786834110d6 to your computer and use it in GitHub Desktop.
Save aslamanver/d1191435acf68d72ed5a1786834110d6 to your computer and use it in GitHub Desktop.
Toby JSON to Chrome Bookmarks HTML (Export Toby collections and import to Chrome bookmarks)
import json
from datetime import datetime
from pathlib import Path
import html
# --- Configuration ---
INPUT_JSON = "toby.json"
OUTPUT_HTML = "converted_bookmarks.html"
def escape(text):
"""Escape HTML special characters"""
return html.escape(text or "")
def generate_bookmark_html(card, add_date=None):
"""Create a <DT><A> tag for a single bookmark"""
title = escape(card.get("title", "Untitled"))
url = escape(card.get("url", "#"))
timestamp = str(add_date or int(datetime.now().timestamp()))
return f' <DT><A HREF="{url}" ADD_DATE="{timestamp}">{title}</A>\n'
def generate_folder_html(title, bookmarks, folder_add_date=None):
"""Create HTML structure for a folder with bookmarks"""
timestamp = str(folder_add_date or int(datetime.now().timestamp()))
html_lines = [
f' <DT><H3 ADD_DATE="{timestamp}" LAST_MODIFIED="{timestamp}">{escape(title)}</H3>',
' <DL><p>'
]
for card in bookmarks:
html_lines.append(generate_bookmark_html(card, add_date=timestamp))
html_lines.append(' </DL><p>')
return '\n'.join(html_lines)
def main():
# Read and parse the JSON file
with open(INPUT_JSON, "r", encoding="utf-8") as f:
data = json.load(f)
# Prepare output HTML content
html_lines = [
'<!DOCTYPE NETSCAPE-Bookmark-file-1>',
'<!-- This is an automatically generated file. DO NOT EDIT! -->',
'<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">',
'<TITLE>Bookmarks</TITLE>',
'<H1>Bookmarks</H1>',
'<DL><p>'
]
for group in data.get("groups", []):
group_title = group.get("name", "Unnamed Group")
lists = group.get("lists", [])
# Group as folder
group_timestamp = int(datetime.now().timestamp())
html_lines.append(f' <DT><H3 ADD_DATE="{group_timestamp}" LAST_MODIFIED="{group_timestamp}">{escape(group_title)}</H3>')
html_lines.append(' <DL><p>')
for list_ in lists:
list_title = list_.get("title", "Untitled List")
cards = list_.get("cards", [])
html_lines.append(generate_folder_html(list_title, cards))
html_lines.append(' </DL><p>')
html_lines.append('</DL><p>')
# Write to output file
output_path = Path(OUTPUT_HTML)
output_path.write_text('\n'.join(html_lines), encoding="utf-8")
print(f"✅ Bookmarks HTML file created: {output_path.resolve()}")
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment