Giter Site home page Giter Site logo

linkcheckermd's Introduction

LinkCheckMD

Load a Markdown file and get highlights and hovers for links that contain a country code (en-us for example.)

If you use Alt+L, it will generate a report on the links in the document, including broken links. It attempts to check broken links by trying to resolve HTTP & HTTPS links, and relative links (../folder/file.md) by checking if the file exist on the local file system. The result of these checks are logged in an output window on the right of the editor.

Animated GIF of URLs being flagged as warnings and Alt+L functionality

Note that checking for broken links is more of an art than a science. Some sites don't actually return 404, but send you to a landing page. For example, Azure.com works this way. You can go to https://Azure.com/foo/bar and it will happily redirect you to https://Azure.com, with no 404 status returned. So take a status of "OK" with a grain of salt - you may not be arriving at the page you intend.

Install

Open Visual Studio Code and press F1; a field will appear at the top of the window. Type ext install linkcheck, hit enter, and reload the window to enable.

Animated GIF of installing the extension

Rules

LNK0001: Check for country code

This rule checks links for language identifiers, such as en-us.

Check for broken links

To check for broken links, use Alt+L. This will open a new column to the right of the VSCode window and display the status of the links as they are checked.

Changes

0.3.0

  • Added configuration setting to disable the country code rule

0.2.0

  • Fixed a bug preventing links with parentheses from being correctly parsed

0.1.5

  • Added country code warnings to the output window for Alt+L checking
  • Updated vscode dependency for the latest version

TODO

  • Refactor broken link checking to display the actual URL that you arrived at for "OK" results that were redirects to a different URL.

linkcheckermd's People

Contributors

adunndevster avatar blackmist avatar dependabot[bot] avatar jamarw avatar michaelgwelch avatar microsoft-github-policy-service[bot] avatar msftgits avatar nschonni avatar squillace avatar stephenjust avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

linkcheckermd's Issues

Relative link checking

Add the ability to check that files linked by relative URIs actually exist. Should not block user's ability to continue editing. Should return a warning rather than an error, since the file may not have been created yet.

Could relative links be checked automatically?

According to the documentation, links containing a country code gets checked automatically while broken links are only checked on Alt+L.

Would it be possible to make local/relative links be checked automatically and Alt+L only be needed for external URLs where a network call is needed?

GitHub links

This is a little tricky but GitHub links need a little massaging...

This is the correct link...

https://github.com/Microsoft/vscode-extensionbuilders/blob/master/docs/extensionAPI/extension-manifest.md#gallery-presentation-tips

You test this link... [missing the /blob/branch name/...]

https://github.com/Microsoft/vscode-extensionbuilders/docs/extensionAPI/extension-manifest.md#gallery-presentation-tips

Another option for relative links is to actually check the file exists on the disk for that repo via a node file all.

correct relative link marked as error in report

I have this link in an md file:
[XFBTransfer requests](../xfbtransfer_request)
I have a file named xfbtransfer_request.md in the same folder. The link works correctly in the browser.
When I request a report for the file, I get the following error:
Error: ../xfbtransfer_request on line 31 does not exist.

Error message misuses `hasCountryCode` as an arraylike object

Source:

`Link ${link.address} contains a language reference: ${hasCountryCode[0]} `

The function isCountryCodeLink below expects to be able to use hasCountryCode as though it were an indexable object (like an array or list), but hasCountryCode is the function handle.

The line `Link ${link.address} contains a language reference: ${hasCountryCode[0]} ` uses the `hasCountryCode` as though it is indexable. However, `hasCountryCode` is a function.
// Check for addresses that contain country codes
function isCountryCodeLink(link: Link): Diagnostic {
    let countryCodeDiag=null;
    
    //If one was found...
    if(hasCountryCode(link.address)) {
        //Create the diagnostics object
        countryCodeDiag = createDiagnostic(
            DiagnosticSeverity.Warning,
            link.text,
            link.lineText,
            `Link ${link.address} contains a language reference: ${hasCountryCode[0]} `
        );
    }
    return countryCodeDiag;
}

function hasCountryCode(linkToCheck: string): boolean {
    //Regex for country-code
    let hasCountryCode = linkToCheck.match(/(.com|aka\.ms)\/[a-z]{2}\-[a-z]{2}\//);
    return hasCountryCode ? true : false;
}

I guess the second function got refactored out of the first one and the developer forgot that the hasCountryCode moved to a different scope.

Perhaps a suitable correction would be to pass a reference that gets set to the country found like so:
// Check for addresses that contain country codes
function isCountryCodeLink(link: Link): Diagnostic {
    let countryCodeDiag=null;
let countryCode= new Array("");
    
    //If one was found...
    if(hasCountryCode(link.address, countryCode)) {
        //Create the diagnostics object
        countryCodeDiag = createDiagnostic(
            DiagnosticSeverity.Warning,
            link.text,
            link.lineText,
            `Link ${link.address} contains a language reference: ${countryCode[0]} `
        );
    }
    return countryCodeDiag;
}

function hasCountryCode(linkToCheck: string, countryCode?: Array<string>): boolean {
    //Regex for country-code
    let hasCountryCode = linkToCheck.match(/(?:.com|aka\.ms)\/([a-z]{2}\-[a-z]{2})\//);
    if( countryCode !== undefined) {
        countryCode = hasCountryCode;
    }
    return hasCountryCode ? true : false;
}

relative links not checked in MD file?

hi
per #8 relative links should be checked, but doing this on this example file I only get URL checks
https://github.com/pestrela/smi_counter/blob/master/test.md

thanks

Name: Link Checker
Id: link-checker.link-checker
Description: Checks links for 200 OK and, in the case of Github, repository staleness.
Version: 1.0.1
Publisher: link-checker
VS Marketplace Link: https://marketplace.visualstudio.com/items?itemName=link-checker.link-checker

Version: 1.41.1 (user setup)
Commit: 26076a4de974ead31f97692a0d32f90d735645c0
Date: 2019-12-18T14:58:56.166Z
Electron: 6.1.5
Chrome: 76.0.3809.146
Node.js: 12.4.0
V8: 7.6.303.31-electron.0
OS: Windows_NT x64 10.0.18363

image

command `extension.generateLinkReport` not found

I can't run the link check with Alt + L, it returns the alert "command extension.generateLinkReport not found"

This extension is installed as part of the VSCode extension 'Docs Authoring Pack'

I'm running on:

macOS Catalina 10.15.6
VSCode 1.48.2

Thanks!

Error on running report

I installed the extension, hit ALT + L and I get this message:

Running the contributed command: 'extension.generateLinkReport' failed.

I do have some links to anchors with HTML-like tags in them.

是否支持批量检测整个vscode中的项目

在vscode中安装了此组件,只支持打开一个文档(ALT+L),然后在输出窗口中查看error么?是否支持批量检测整个项目中的多个markdown文件中的失效链接。

When problems are listed in Problems Tab linkcheckermd should be reported as the source

I've lived with the issue of warnings on links with language codes in them for a long time. (Ironically it turns out that this extension is from Microsoft which I did not know, because it's links to Microsoft that typically have the language codes in them. Every time I get this warning it's a Microsoft link and I have no idea what I'm supposed to do about it.)

I finally just had to start disabling extensions to figure out what was reporting this warning.

Fortunately I found it rather quickly. I don't know when or why I installed this extension but I could have disabled it much more quickly if it had reported to me where it comes from. Here's a screen shot showing two warnings. The first from this extension, the second from markdownlint.

image

The one related to markdownlint is much more user friendly.

Checking Web Site for Broken Links

Sorry if this isn’t the right place to post this. I was sent here by a Ask a Question button on another page.

Can this Visual Studio Code extension check an entire Web site for broken links? The documentation I’ve seen only seems to deal with checking a single Web page at a time, which is impractical for a large site like mine.

Off by 1 for line

I ran this on a few files and line counts seam to be off by one... Notice QUICKSTART.md error vs line.

image

Add configuration

Some folks might want to enable/disable specific behaviors. Like the default is to not treat redirects as a broken link, but some might want to enable this. Also, we might want to add additional things to flag as warnings/errors in link's.

Extension causes high cpu load

blackmist.LinkCheckMD-unresponsive.cpuprofile.txt

  • Issue Type: Performance
  • Extension Name: LinkCheckMD
  • Extension Version: 0.3.1
  • OS Version: Windows_NT x64 10.0.19041
  • VSCode version: 1.42.0

⚠️ Make sure to attach this file from your home-directory:
⚠️C:\Users\caveb\blackmist.LinkCheckMD-unresponsive.cpuprofile.txt
blackmist.LinkCheckMD-unresponsive.cpuprofile.txt

Find more details here: https://github.com/microsoft/vscode/wiki/Explain-extension-causes-high-cpu-load

Add 404 checking

Need to add 404 checking for HTML style links. Care should be taken that this doesn't block the user's ability to continue editing

Links with parentheses becomes unreachable

Links which contains parentheses seems to be cutoff at the end and becomes unreachable.

Example in markdown:
[the Foo Fighters album](https://en.wikipedia.org/wiki/Foo_Fighters_(album))
Becomes:
https://en.wikipedia.org/wiki/Foo_Fighters_(album

Change default keyboard shortcut to something that is less likely to conflict

The current default keyboard shortcut Alt+L is very generic and likely to cause conflicts. This happens for example on several non-English keyboard layouts on macOS where Alt+L is the shortcut for @.

Using a different shortcut would make for a better initial experience when using this extension for users with any of those affected layouts.

bad internal links are not found

Markdown test code: none of these files or headers exist:

- [bad link test 1](#badlink)
- [bad link test 2](nofile.md#badlink)
- [bad link test 3](nofile.md)

Expected output:

Error: #badlink on line 144.
Error: nofile.md#badlink on line 145 does not exist.
Error: nofile.md on line 146 does not exist.

Actual output:

Info: #badlink on line 144.
Error: nofile.md#badlink on line 145 does not exist.
Error: nofile.md on line 146 does not exist.

Link 'x' contains a language reference: undefined

This is driving me nuts, and I cannot find a way to ignore this warning. I initially thought it might be markdownlint, because I thought markdownlint was the only extension I had installed, that was parsing my markdown for errors. I had configured for Markdown files, but, @DavidAnson suggested I look at the LinkCheckerMD, and sure enough, the warning is coming from LinkCheckerMD.

When writing a markdown file, if I include a link or multiple links, as demonstrated below, I get a warning for each link, and it does not have an error/warning code and I can't find any information, ANYWHERE, on how to ignore it. It is kind of annoying having yellow squiggly lines everywhere on the document. Note, that if I take off the view=powershell-7.3 the links do not trigger a warning, and I could just do a find replace on all of them, but that's not really a feasible solution. All of the links below are links to Microsoft PowerShell documentation, but this same warning is triggered on any link in markdown, containing similar "URL arguments/parameters". What am I missing? Is this a bug? A feature? How can I ignore this warning either in the user settings.json, or the workspace settings.json? If I cannot ignore this warning, I will have to uninstall the LinkCheckerMD extension. Please help!!!

- Overview
  - [What is PowerShell?](https://learn.microsoft.com/en-us/powershell/scripting/overview?view=powershell-7.3)
  - [What is a PowerShell command?](https://learn.microsoft.com/en-us/powershell/scripting/powershell-commands?view=powershell-7.3)
  - [Discover PowerShell](https://learn.microsoft.com/en-us/powershell/scripting/discover-powershell?view=powershell-7.3)

vscode-markdown-error-20221127-01

Check all files in the directory

Is it just me or do you think its a valuable feature?
do sth like alt+shft+L to check all files in the directory for broken links.

While linkcheckmd is great for creating new docs and markdowns, it gets so tedious when a restructuring happens.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.