diff --git a/markdown_sqlite.py b/markdown_sqlite.py index 0329b77..5af88f6 100644 --- a/markdown_sqlite.py +++ b/markdown_sqlite.py @@ -7,10 +7,11 @@ The script tracks changes using MD5 hashes and ensures the database reflects the current state of the markdown file. """ +import os import sqlite3 import hashlib import argparse -import os +import logging from datetime import datetime from typing import List, Tuple, Optional from markdown_it import MarkdownIt @@ -154,6 +155,7 @@ class MarkdownProcessor: def clear_document_content(self, document_id: int) -> None: """Clear existing content for a document in the database.""" + logging.debug(f"!! DELETING FROM DATABASE, document_id: {document_id}") self.db_manager.cursor.execute('DELETE FROM headings WHERE document_id = ?', (document_id,)) self.db_manager.cursor.execute('DELETE FROM body WHERE document_id = ?', (document_id,)) @@ -162,6 +164,10 @@ class MarkdownProcessor: parent_stack: List[Tuple[int, int]] = [] # (level, heading_id) current_heading_id = None for token in tokens: + content_preview = ' '.join(token.content.split()[:10]) + '...' \ + if len(token.content.split()) > 10 else token.content + + logging.debug(f"Processing token: {token.type}, content: {content_preview}") if token.type == 'heading_open': level = int(token.tag.strip('h')) content_token = tokens[tokens.index(token) + 1] @@ -318,11 +324,7 @@ class TopicReader: def _fetch_subtopics(self, heading_id: int, parent_level: int) -> List[Tuple[int, int, str]]: """ Fetch all subtopics that are children of the given heading. - - Args: - heading_id (int): The parent heading ID. - parent_level (int): The level of the parent heading. - + Returns: List of tuples containing the subtopic's ID, level, and title. """ @@ -458,6 +460,7 @@ def main(): topic_title: Optional topic for content selection (fuzzy matching enabled). --bootstrap: If provided, generates markdown calendar for the current year and loads it to the database. --ls: If provided, lists all available headings. + --html: If provided, will produce {filename}.html file along the markdown file. """ # Set up command-line argument parsing parser = argparse.ArgumentParser(description='Process markdown file and optionally select a topic.') @@ -467,7 +470,12 @@ def main(): parser.add_argument('--bootstrap', action='store_true', help='Generate markdown calendar for the current year and load it to the database.') parser.add_argument('--ls', action='store_true', help='List all available headings.') parser.add_argument('--html', action='store_true', help='Generate an HTML version of the output') + parser.add_argument('--debug', action='store_true', help='Enable debug printing') args = parser.parse_args() + + # Set up logging + logging.basicConfig(level=logging.DEBUG if args.debug else logging.INFO) + # Use the provided or default file paths markdown_file = args.markdown