question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Copy/paste that ensures correct relative links

See original GitHub issue

What is the problem?

Copy/paste markdown between files will break relative links (e.g. to images or local files).

While it is easy to capture images and paste them into markdown (e.g. using https://marketplace.visualstudio.com/items?itemName=mushan.vscode-paste-image), there is no easy way to move markdown content between files if both files are in different folders.

This is a serious limitation, as it makes it very difficult to rearrange content, a process that is trivial in any word processor.

How can I reproduce it?

Create a file first.md in folder path/to/file/a/ containing a link to an image.

### This is file path/to/file/a/first.md
![Some Image]("2020-08-09-09-20-21.png")

Then copy and paste the markdown into a file second.md in folder path/to/file/b.

The link in the 2nd file will be broken, as the relative path now points to the wrong folder.

Is there any error message in the console?

No

Solution

We need modified copy/paste commands that either updates relative paths, or copy linked files as well (setting copyLinkedFiles).

Copy should convert every path referenced in the file to an absolute path, i.e. ![Some Image]("path/to/file/a/first.md/2020-08-09-09-20-21.png").

Paste should convert any absolute path to a path relative to the 2nd file. In the case above, this would be ![Some Image]("../a/first.md/2020-08-09-09-20-21.png").

If copyLinkedFiles=true, paste should copy all referenced files under folder a to folder b (potentially preserving subfolders, e.g. if the file is in a folder “images” on a it should be copied to a folder “images” on b as well.

If the first path and the second path reside on different drives, the linked files should be copied by default.

Note: Always using absolute paths is not a solution, as in this case the markdown files can’t be moved around freely (e.g. onto a USB or network drive).

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
max92334commented, Aug 11, 2020

Sounds good. Maybe someone with more experience than me with extensions will comment, I am still learning. Thank you!

0reactions
Lemminghcommented, Aug 11, 2020

It could be possible to check the existence of relative links and show warnings and code actions. Though it’s not a direct solution, I still think this can help a lot.

Please also note that there are many corner cases in URIs.

BTW, markdown-it provides a MarkdownIt.parse() method. Then, it might be feasible to build a language server on it to gain more knowledge of a document.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to stop Chrome from turning relative links to absolute ...
Browsers copy links with absolute URLs, this is to prevent issues arising when you paste links into different areas.
Read more >
How to copy-paste absolute cell references temporarely as ...
One way to tackle this problem is to use only relative references and follow the procedure below to copy the relative references in...
Read more >
Copy and Paste Formulas in Excel without Changing Cell ...
In this tutorial, you will learn how to COPY and PASTE formulas in Excel without changing the cell references. Learn how to copy...
Read more >
Excel: Copying with Relative Links - datawookie
An Excel spreadsheet. Cut-paste the region containing relative links to temporary location. Finally Copy and Paste from the temporary location ...
Read more >
Copy paste designs to upload (!45987) · Merge requests · GitLab ...
Ensure the videos added to the frontmatter have the correct URL format. ... Check that all links to about.gitlab.com content are relative URLs....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found