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

UNC path plugin #233

Open
ekalchev opened this issue Apr 21, 2018 · 0 comments
Open

UNC path plugin #233

ekalchev opened this issue Apr 21, 2018 · 0 comments

Comments

@ekalchev
Copy link

ekalchev commented Apr 21, 2018

I am trying to create plugin for creating links for UNC file path "\\server\path\directory". I need to know if I am at the right path.

I made the following modification to linkify.js to get this working

I defined a new token like this, because backslash was missing

var BACKSLASH = inheritsToken('\\');

Added a new symbol to state on S_START

S_START.on('\\', makeState(BACKSLASH));

and this is the plugin code

'use strict';

; (function (linkify) {
  var plugin = function () {
    'use strict';

    function hashtag(linkify) {
        var TT = linkify.scanner.TOKENS; // Text tokens
        var MultiToken = linkify.parser.TOKENS.Base; // Base Multi token class
        var S_START = linkify.parser.start;
        var State = linkify.parser.State;

        function BACKSLASH_BACKSLASH(value) {
            this.v = value;
        }

        linkify.inherits(MultiToken, BACKSLASH_BACKSLASH, {
            type: 'uncpath',
            isLink: true,
            toHref: function toHref() {
                return 'file://' + this.toString().substr(1);
            }
        });

        var S_BACKSLASH = S_START.jump(TT.BACKSLASH);
        var S_BACKSLASH_BACKSLASH = new State(BACKSLASH_BACKSLASH);
        S_BACKSLASH.on(TT.BACKSLASH, S_BACKSLASH_BACKSLASH);


        S_BACKSLASH_BACKSLASH.on(TT.DOMAIN, S_BACKSLASH_BACKSLASH);
        S_BACKSLASH_BACKSLASH.on(TT.TLD, S_BACKSLASH_BACKSLASH);
        S_BACKSLASH_BACKSLASH.on(TT.LOCALHOST, S_BACKSLASH_BACKSLASH);
        S_BACKSLASH_BACKSLASH.on(TT.BACKSLASH, S_BACKSLASH_BACKSLASH);
    }

    return hashtag;
}();

plugin(linkify);
})(linkify);

Can you tell me if I am missing something it appears to be working but may be I am not seeing something?

also I can see "asdasdasdasd\\asdasdasd\asdasdas" is also linkified. How can tell the parser to linkify the unc path only if \\ is prefixed with space, newline, tab and etc?

@nfrasser nfrasser added this to the 3.0 milestone Mar 11, 2021
@nfrasser nfrasser mentioned this issue Mar 11, 2021
@nfrasser nfrasser added docs and removed duplicate labels Mar 21, 2021
@nfrasser nfrasser modified the milestones: 3.0, 4.1+ Oct 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants