Skip to content

feat(blocklist): add site blocking and RFC documentation#31

Open
jamesainslie wants to merge 4 commits intomainfrom
docs-add-rfcs
Open

feat(blocklist): add site blocking and RFC documentation#31
jamesainslie wants to merge 4 commits intomainfrom
docs-add-rfcs

Conversation

@jamesainslie
Copy link
Owner

Overview

This PR introduces a configurable site blocklist to MDView, allowing users to prevent markdown rendering on selected sites via URL patterns. It also adds RFC documentation for ongoing design work, refines UI styling, and fixes several bugs including CSS scoping issues and TOC toggle behavior.

Changes

Features

  • Site blocklist core logic

    • Add blockedSites?: string[] preference to the application state for site filtering
    • Implement blocklist pattern matching in FileScanner supporting:
      • Exact domains (e.g. example.com)
      • Wildcard subdomains (e.g. *.example.com)
      • Path-based patterns (e.g. example.com/docs/*)
      • Full URL patterns
    • Check blocklist before rendering markdown; skip initialization on blocked sites
  • Options UI for managing blocklist

    • Add blocklist section to Advanced settings with input field and add button
    • Include collapsible help section with pattern examples
    • Provide scrollable list of blocked patterns with per-item remove actions
  • Popup UI controls for per-site blocking

    • Add quick site blocking toggle showing current hostname
    • Move per-site block toggle to popup footer as icon button alongside reload control

Fixes

  • TOC toggle behavior: Reload page when showToc preference changes to properly strip or restore the original document TOC
  • CSS scoping: Revert broken CSS scoping that caused specificity conflicts breaking export dialog, paragraph spacing, and table rendering
  • Popup blocklist removal: Correct wildcard blocklist removal to use non-null currentHost when matching patterns
  • PDF generator: Add missing return Promise.resolve() in prepareSvgsForPrint

Style

  • Replace gradient headers in popup and settings with neutral backgrounds and subtle borders
  • Adjust blockquote left padding for better text separation from border

Documentation

  • Add RFC-20251202-001-docx-svg-support.md documenting SVG support in forked docx library
  • Add RFC-20251203-001-mdview-semantic-block-dsl.md specifying HTML-comment-based semantic block DSL
  • Fix changelog entry ordering to maintain descending version order

Chores

  • Sync manifest version to 0.3.2

Tests

  • Add 17 unit tests for blocklist functionality covering pattern matching, edge cases, and getCurrentSiteIdentifier()

Technical Details

  • Affected modules: FileScanner, content-script, popup, options, pdf-generator
  • New preference: blockedSites?: string[] in AppState.preferences
  • Pattern matching: Case-insensitive matching with glob-to-regex conversion for path patterns
  • TOC behavior change: showToc toggle now triggers page reload instead of just showing/hiding sidebar

Testing

  • 17 new unit tests for blocklist pattern matching
  • All 414 existing tests pass
  • Manual testing: site blocking toggle, pattern management UI, TOC toggle with original TOC documents

File Changes Summary

 CHANGELOG.md                                       |   8 +-
 public/manifest.json                               |   2 +-
 rfcs/RFC-20251202-001-docx-svg-support.md          | 527 +++++++++++++++++++++
 rfcs/RFC-20251203-001-mdview-semantic-block-dsl.md | 503 ++++++++++++++++++++
 src/background/service-worker.ts                   |   1 +
 src/content/content-script.ts                      | 140 +++++-
 src/content/content.css                            |   2 +-
 src/options/options.css                            | 121 ++++-
 src/options/options.html                           |  30 ++
 src/options/options.ts                             | 135 ++++++
 src/popup/popup.css                                |  50 +-
 src/popup/popup.html                               |  26 +-
 src/popup/popup.ts                                 | 140 ++++++
 src/types/index.d.ts                               |   2 +
 src/utils/file-scanner.ts                          | 129 +++++
 src/utils/pdf-generator.ts                         |  11 +-
 tests/unit/utils/file-scanner-blocklist.test.ts    | 239 ++++++++++
 17 files changed, 2009 insertions(+), 57 deletions(-)

Checklist

  • All tests passing
  • Linting checks passed
  • Documentation updated
  • Breaking changes documented
  • Reviewed own code changes

The scoping approach (body.mdview-active *) created specificity
conflicts with the universal reset, causing UI elements like the
export menu and progress overlay to lose their padding and margins.

Restores original unscoped selectors while preserving the blockquote
left padding fix (0 1em -> 0 1em 0 1.5em) for better text separation
from the border.
The TOC stripper runs during markdown rendering, so toggling the
showToc preference requires a full page reload to strip or restore
the original document TOC. Previously, the content script only
showed/hid the MDView TOC sidebar without re-rendering, leaving
the original TOC visible when enabled or missing when disabled.
@greptile-apps
Copy link

greptile-apps bot commented Dec 3, 2025

Greptile Overview

Greptile Summary

This PR adds a site blocklist feature allowing users to prevent markdown rendering on selected sites, plus bug fixes for TOC toggling and CSS scoping. The blocklist implementation supports exact domains, wildcard subdomains, path patterns, and full URLs with comprehensive test coverage.

Key Changes:

  • Site blocklist with pattern matching (domains, wildcards, paths, full URLs)
  • Blocklist UI in options page and quick toggle in popup
  • TOC toggle now triggers page reload to properly strip/restore original document TOC
  • CSS scoping reverted to fix dialog, paragraph spacing, and table rendering issues

Critical Issue Found:

  • Variable declaration order bug in content-script.ts:621 - needsReload is used before being declared on line 636, which will cause a ReferenceError when toggling TOC preference

Strengths:

  • Well-tested blocklist logic with 17 unit tests covering edge cases
  • Proper HTML escaping in UI components
  • Case-insensitive pattern matching with whitespace handling
  • Clear separation of concerns between FileScanner, popup, and options modules

Confidence Score: 2/5

  • Critical variable declaration bug will cause runtime error when toggling TOC preference
  • The variable declaration order bug in content-script.ts (using needsReload on line 621 before declaring it on line 636) is a critical logical error that will cause a ReferenceError at runtime. This prevents users from toggling the TOC preference without encountering errors. The blocklist implementation itself is solid with good test coverage, but this bug significantly impacts functionality.
  • src/content/content-script.ts requires immediate fix for variable declaration order bug

Important Files Changed

File Analysis

Filename Score Overview
src/content/content-script.ts 2/5 Added site blocklist check and TOC reload logic, but variable declaration order bug will cause runtime error
src/utils/file-scanner.ts 5/5 Blocklist pattern matching implementation is well-tested with proper wildcard, path, and URL pattern support
src/popup/popup.ts 5/5 Site blocking toggle UI properly handles hostname matching and wildcard pattern removal
src/options/options.ts 5/5 Blocklist management UI with proper HTML escaping, duplicate detection, and real-time updates

Sequence Diagram

sequenceDiagram
    participant User
    participant ContentScript
    participant FileScanner
    participant Background
    participant Storage

    User->>ContentScript: Load markdown page
    ContentScript->>Background: GET_STATE
    Background->>Storage: Retrieve preferences
    Storage-->>Background: Return state
    Background-->>ContentScript: State with blockedSites[]
    
    ContentScript->>FileScanner: isSiteBlocked(blockedSites)
    FileScanner->>FileScanner: matchesPattern for each pattern
    alt Site is blocked
        FileScanner-->>ContentScript: true
        ContentScript->>ContentScript: Skip rendering, exit
    else Site not blocked
        FileScanner-->>ContentScript: false
        ContentScript->>ContentScript: activateStyles()
        ContentScript->>ContentScript: Render markdown
    end

    User->>Popup: Toggle site block
    Popup->>Background: UPDATE_PREFERENCES
    Background->>Storage: Save blockedSites[]
    Popup->>ContentScript: Reload tab
    ContentScript->>FileScanner: isSiteBlocked (new blocklist)

Loading

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

4 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

preferences.showToc !== this.state.preferences.showToc
) {
debug.info('MDView', 'TOC preference changed, reloading page to re-render...');
needsReload = true;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: needsReload used before declaration (line 636). This will cause a ReferenceError at runtime when toggling the TOC preference.

Suggested change
needsReload = true;
// Check for structural changes that require re-render
let needsReload = false;
// Handle TOC visibility toggle - requires reload to strip/restore original TOC
if (
preferences.showToc !== undefined &&
this.state &&
preferences.showToc !== this.state.preferences.showToc
) {
debug.info('MDView', 'TOC preference changed, reloading page to re-render...');
needsReload = true;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant