Skip to content

fix: patch landscape2 links to open in new tab#130

Open
Tushar8466 wants to merge 2 commits into
json-schema-org:mainfrom
Tushar8466:fix/landscape-links-new-tab
Open

fix: patch landscape2 links to open in new tab#130
Tushar8466 wants to merge 2 commits into
json-schema-org:mainfrom
Tushar8466:fix/landscape-links-new-tab

Conversation

@Tushar8466
Copy link
Copy Markdown

Problem

landscape2 builds the site from guide.yml and converts Markdown links to HTML <a> tags, but has these hard limitations:

  • Strips target="_blank" even if written as raw HTML in guide.yml
  • Strips <script> tags entirely
  • External links get extra processing that was breaking rendering and showing raw HTML in the browser

There is no way to make landscape2 output target="_blank" links — it's a built-in limitation of the tool.

Solution

Since guide.yml itself can't fix this, we patch the generated output (build/index.html) after landscape2 finishes building.

What build.sh does

  1. Runs landscape2 build — exactly as before
  2. Uses Python to inject a small JS snippet into the bottom of build/index.html

The injected script uses a MutationObserver — a browser API that watches for DOM changes. Since the landscape2 site is a SPA, guide content is rendered dynamically after page load. The observer detects new content in the DOM and immediately sets target="_blank" on every link.

Summary

Problem landscape2 sanitizes and strips target="_blank"
Fix Patch build/index.html after the build using Python
Mechanism A MutationObserver in JS sets target="_blank" on all links dynamically
When to run Use `
Screen.Recording.2026-03-22.at.8.44.53.PM.mov

bash build.shinstead oflandscape2 build ...` every time you rebuild |

Copilot AI review requested due to automatic review settings March 22, 2026 15:15
@Tushar8466
Copy link
Copy Markdown
Author

@Utkarsh-123github I have made the PR you can review it

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a wrapper build script to work around landscape2 sanitization by post-processing the generated build/index.html and injecting a small JS snippet that forces rendered links to open in a new tab (including dynamically-rendered SPA content).

Changes:

  • Introduces build.sh to run landscape2 build with the repo’s standard inputs/outputs.
  • Injects a MutationObserver-based script into build/index.html to set target="_blank" + rel="noopener noreferrer" on links after DOM updates.
  • Makes the injection idempotent by removing the prior injected snippet before re-inserting.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread build.sh Outdated
Comment thread build.sh
Comment thread build.sh
Comment thread build.sh
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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.

2 participants