Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass input file's directory as live-server's root #21

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

walterl
Copy link

@walterl walterl commented Jul 31, 2022

⚠️ This PR includes changes from #20, so it should be reviewed and merged before this one.

This fixes broken relative links when previewing files outside of the current working directory.

Example: Open a terminal and cd to the parent directory of your clone of this repo, run nvim nvim-markdown-preview/README.md, and :MarkdowPreview<CR>. Notice how the screenshot is missing.

This happens because the generated HTML's (temporary) directory is mounted at the live server's /. This is required for the HTML file to be accessible to live-server, but it also means that relative links are broken, because the temp directory doesn't contain linked resources.

Previewing files in the current directory happens to work, because live-server's root is the current directory, which live-server
apparently falls back to when it can't find something in the directory mounted at /. (The server root and / mounts both appear to be mapped.)

This fallback functionality is leveraged to fix relative resource links by setting the live-server root to the directory of the input file.

walterl and others added 4 commits July 29, 2022 14:38
This enables a high degree of customization. I've found it useful for
changing the browser being opened, and changing the port on which the
live server is started.
Enable passing extra args to live-server
This fixes broken relative links when previewing files outside of the
current working directory.

Example: Open a terminal and `cd` to the parent directory of your clone
of this repo, run `nvim nvim-markdown-preview/README.md`, and
`:MarkdowPreview<CR>`. Notice how the screenshot is missing.

This happens because the generated HTML's (temporary) directory is
mounted at the live server's `/`. This is required for the HTML file to
be accessible to live-server, but it also means that relative links are
broken, because the temp directory doesn't include linked resources.

Previewing files in the current directory happens to work, because
live-server's root is the current directory, which live-server
apparently falls back to when it can't find something in the directory
mounted at `/`. (The server root and `/` mounts appear to be mapped.)

This fallback functionality is leveraged to fix relative resource links
by setting the live-server root to the directory of the input file.
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