~didrocks/+junk/face-detection-15.04

« back to all changes in this revision

Viewing changes to facedetection/www/bower_components/prism/plugins/autolinker/prism-autolinker.js

  • Committer: Didier Roche
  • Date: 2016-05-10 23:09:11 UTC
  • Revision ID: didier.roche@canonical.com-20160510230911-c7xr490zrj3yrzxd
New version

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
(function(){
 
2
 
 
3
if (
 
4
        typeof self !== 'undefined' && !self.Prism ||
 
5
        typeof global !== 'undefined' && !global.Prism
 
6
) {
 
7
        return;
 
8
}
 
9
 
 
10
var url = /\b([a-z]{3,7}:\/\/|tel:)[\w\-+%~/.:#=?&]+/,
 
11
    email = /\b\S+@[\w.]+[a-z]{2}/,
 
12
    linkMd = /\[([^\]]+)]\(([^)]+)\)/,
 
13
    
 
14
        // Tokens that may contain URLs and emails
 
15
    candidates = ['comment', 'url', 'attr-value', 'string'];
 
16
 
 
17
Prism.hooks.add('before-highlight', function(env) {
 
18
        // Abort if grammar has already been processed
 
19
        if (!env.grammar || env.grammar['url-link']) {
 
20
                return;
 
21
        }
 
22
        Prism.languages.DFS(env.grammar, function (key, def, type) {
 
23
                if (candidates.indexOf(type) > -1 && Prism.util.type(def) !== 'Array') {
 
24
                        if (!def.pattern) {
 
25
                                def = this[key] = {
 
26
                                        pattern: def
 
27
                                };
 
28
                        }
 
29
 
 
30
                        def.inside = def.inside || {};
 
31
 
 
32
                        if (type == 'comment') {
 
33
                                def.inside['md-link'] = linkMd;
 
34
                        }
 
35
                        if (type == 'attr-value') {
 
36
                                Prism.languages.insertBefore('inside', 'punctuation', { 'url-link': url }, def);
 
37
                        }
 
38
                        else {
 
39
                                def.inside['url-link'] = url;
 
40
                        }
 
41
 
 
42
                        def.inside['email-link'] = email;
 
43
                }
 
44
        });
 
45
        env.grammar['url-link'] = url;
 
46
        env.grammar['email-link'] = email;
 
47
});
 
48
 
 
49
Prism.hooks.add('wrap', function(env) {
 
50
        if (/-link$/.test(env.type)) {
 
51
                env.tag = 'a';
 
52
                
 
53
                var href = env.content;
 
54
                
 
55
                if (env.type == 'email-link' && href.indexOf('mailto:') != 0) {
 
56
                        href = 'mailto:' + href;
 
57
                }
 
58
                else if (env.type == 'md-link') {
 
59
                        // Markdown
 
60
                        var match = env.content.match(linkMd);
 
61
                        
 
62
                        href = match[2];
 
63
                        env.content = match[1];
 
64
                }
 
65
                
 
66
                env.attributes.href = href;
 
67
        }
 
68
});
 
69
 
 
70
})();
 
 
b'\\ No newline at end of file'