Skip to content

Fix: markdown-previewer - dark mode toggle not working - #834

Merged
praveenscience merged 1 commit into
praveenscience:mainfrom
dev-Aarish:fix/markdown-previewer-dark-mode
Aug 15, 2026
Merged

Fix: markdown-previewer - dark mode toggle not working#834
praveenscience merged 1 commit into
praveenscience:mainfrom
dev-Aarish:fix/markdown-previewer-dark-mode

Conversation

@dev-Aarish

Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes the dark mode toggle in the Markdown Previewer tool. The moon/sun button did nothing because a ReferenceError at script load (the view-restore block called setView() before let currentView was declared, i.e. a temporal-dead-zone violation) aborted the rest of the inline script — so toggleTheme() was never set up. Moved the state declarations (dark, currentView) above their restore blocks and fixed the view-persistence save to use the correct variable.

Closes #833

Type of Change

  • New tool
  • Enhancement to existing tool
  • Bug fix
  • Documentation update
  • Build system / infrastructure

Screenshot

Screenshot 2026-08-15 at 2 30 46 PM

Checklist

  • I have read the Contributing Guide
  • My branch follows the naming convention (add/tool-name, feat/description, or fix/description)
  • I have tested my changes locally in at least one modern browser

For new tools:

  • The tool is a single self-contained .html file in the tools/ folder
  • The filename is kebab-case (e.g. json-formatter.html)
  • I added an entry to data/tools.json with all required fields
  • I added a screenshot as tools/<tool-name>.png next to the HTML file
  • No JS frameworks (React, Vue, Angular, etc.) or heavy UI libraries (Bootstrap JS, jQuery, etc.)
  • CDN links for lightweight libraries and fonts are fine — no copy-pasting library source code inline
  • I ran node scripts/sort-norm.js data/tools.json to sort and normalize the tools registry
  • I ran node scripts/build.js and verified the landing page renders correctly

For enhancements / bug fixes:

  • I have not introduced any external dependencies
  • The tool still works as a standalone single HTML file

@praveenscience praveenscience left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

The three fixes are correct:

  1. let dark = false moved above toggleTheme() call — fixes temporal dead zone issue
  2. let currentView = "both" moved above setView() call — same fix
  3. modecurrentView in localStorage.setItemmode was out of scope (it is a parameter of setView(), not available at line 577)

Note: There is a remaining bug at lines 575–578 — setView("both") always overwrites the restored view from localStorage, and then saves "both" back, wiping the user preference. Will create a follow-up issue for this.

@praveenscience
praveenscience merged commit 5f5009f into praveenscience:main Aug 15, 2026
2 checks passed
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.

Bug: Dark mode doesn't work in Markdown Previewer Tool

2 participants