How to use el.text method in Appium Xcuitest Driver

Best JavaScript code snippet using appium-xcuitest-driver

Run Appium Xcuitest Driver automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Sign up Free
_

GitanaConsoleBreadcrumb.js

Source: GitanaConsoleBreadcrumb.js Github

copy
1(function($) {
2
3    Gitana.Console.Breadcrumb = {
4
5
6        "PATHS" : {
7
8        },
9
10        "findPath": function (child, self, callback) {
11            child.listRelatives({
12                "type" : "a:child",
13                "direction" : "INCOMING"
14            }, {
15                "skip" : 0,
16                "limit" : 1
17            }).count(function(count) {
18
19                if (count == 1) {
20
21                    this.keepOne().then(function() {
22
23                        var parentNode = this;
24
25                        if (Gitana.Console.Breadcrumb.PATHS[parentNode.getId()]) {
26                            var childPath = $.merge([], Gitana.Console.Breadcrumb.PATHS[parentNode.getId()]);
27                            childPath.push({
28                                "text" : self.friendlyTitle(child),
29                                "link" : self.folderLink(child)
30                            });
31                            Gitana.Console.Breadcrumb.PATHS[child.getId()] = childPath;
32                        } else {
33                            Gitana.Console.Breadcrumb.findPath(parentNode, self, function() {
34                                if (Gitana.Console.Breadcrumb.PATHS[parentNode.getId()]) {
35                                    var childPath = $.merge([], Gitana.Console.Breadcrumb.PATHS[parentNode.getId()]);
36                                    childPath.push({
37                                        "text" : self.friendlyTitle(child),
38                                        "link" : self.folderLink(child)
39                                    });
40                                    Gitana.Console.Breadcrumb.PATHS[child.getId()] = childPath;
41                                }
42                            });
43                        }
44                    });
45                }
46
47                this.then(function() {
48                    if (callback) {
49                        callback();
50                    }
51                });
52            });
53        },
54
55        "Error" : function(self, el) {
56            return [
57                {
58                    "text" : "Error",
59                    "link" : "/error"
60                }
61            ];
62        },
63
64        "MyProfile" : function(self, el) {
65            return [
66                {
67                    "text" : "My Profile",
68                    "link" : "/profile"
69                }
70            ];
71        },
72
73        "Platform" : function(self, el) {
74            return [
75                {
76                    "text" : "Platform",
77                    "link" : self.link(self.platform()),
78                    "requiredAuthorities" : [
79                        {
80                            "permissioned" : self.platform(),
81                            "permissions" : ["update"]
82                        }
83                    ]
84                }
85            ];
86        },
87
88        "PlatformTeams" : function(self, el) {
89            return $.merge(this.Platform(self, el), [
90                {
91                    "text" : "Teams",
92                    "link" : self.LINK().call(self, self.platform(), "teams")
93                }
94            ]);
95        },
96
97        "PlatformTeam" : function(self , el) {
98            return $.merge(this.PlatformTeams(self, el), [
99                {
100                    "text" : self.friendlyTitle(self.team()),
101                    "link" : self.teamLink(self.team(),self.platform())
102                }
103            ]);
104        },
105
106        "PlatformLogs" : function(self, el) {
107            return $.merge(this.Platform(self, el), [
108                {
109                    "text" : "Logs",
110                    "link" : self.link(self.platform()) + "logs"
111                }
112            ]);
113        },
114
115        "PlatformJobs" : function(self, el) {
116            return $.merge(this.Platform(self, el), [
117                {
118                    "text" : "Jobs",
119                    "link" : self.listLink("jobs")
120                }
121            ]);
122        },
123
124        "Domains" : function(self , el) {
125            return $.merge(this.Platform(self, el), [
126                {
127                    "text" : "Domains",
128                    "link" : self.LIST_LINK().call(self,'domains')
129                }
130            ]);
131        },
132
133        "Domain" : function(self , el) {
134            return $.merge(this.Domains(self, el), [
135                {
136                    "text" : self.friendlyTitle(self.domain()),
137                    "link" : self.LINK().call(self,self.domain())
138                }
139            ]);
140        },
141
142        "Vaults" : function(self , el) {
143            return $.merge(this.Platform(self, el), [
144                {
145                    "text" : "Vaults",
146                    "link" : self.LIST_LINK().call(self,'vaults')
147                }
148            ]);
149        },
150
151        "Vault" : function(self , el) {
152            return $.merge(this.Vaults(self, el), [
153                {
154                    "text" : self.friendlyTitle(self.vault()),
155                    "link" : self.LINK().call(self,self.vault())
156                }
157            ]);
158        },
159
160        "VaultTeams" : function(self, el) {
161            return $.merge(this.Vault(self, el), [
162                {
163                    "text" : "Teams",
164                    "link" : self.LINK().call(self, self.vault(), "teams")
165                }
166            ]);
167        },
168
169        "VaultTeam" : function(self , el) {
170            return $.merge(this.VaultTeams(self, el), [
171                {
172                    "text" : self.friendlyTitle(self.team()),
173                    "link" : self.teamLink(self.team(),self.vault())
174                }
175            ]);
176        },
177
178        "Archives" : function(self , el) {
179            return $.merge(this.Vault(self, el), [
180                {
181                    "text" : "Archives",
182                    "link" : self.LIST_LINK().call(self,'archives')
183                }
184            ]);
185        },
186
187        "Archive" : function(self , el) {
188            return $.merge(this.Archives(self, el), [
189                {
190                    "text" : self.friendlyTitle(self.archive()),
191                    "link" : self.LINK().call(self,self.archive())
192                }
193            ]);
194        },
195
196        "Stacks" : function(self , el) {
197            return $.merge(this.Platform(self, el), [
198                {
199                    "text" : "Stacks",
200                    "link" : self.LIST_LINK().call(self,'stacks')
201                }
202            ]);
203        },
204
205        "Stack" : function(self , el) {
206            return $.merge(this.Stacks(self, el), [
207                {
208                    "text" : self.friendlyTitle(self.stack()),
209                    "link" : self.LINK().call(self,self.stack())
210                }
211            ]);
212        },
213
214        "StackAttachments" : function(self, el) {
215            return $.merge(this.Stack(self, el), [
216                {
217                    "text" : "Attachments",
218                    "link" : self.LINK().call(self, self.stack(), "attachments")
219                }
220            ]);
221        },
222
223        "StackLogs" : function(self , el) {
224            return $.merge(this.Stack(self, el), [
225                {
226                    "text" : "Logs",
227                    "link" : self.LINK().call(self, self.stack(),"logs")
228                }
229            ]);
230        },
231
232        "StackTeams" : function(self, el) {
233            return $.merge(this.Stack(self, el), [
234                {
235                    "text" : "Teams",
236                    "link" : self.LINK().call(self, self.stack(), "teams")
237                }
238            ]);
239        },
240
241        "StackTeam" : function(self , el) {
242            return $.merge(this.StackTeams(self, el), [
243                {
244                    "text" : self.friendlyTitle(self.team()),
245                    "link" : self.teamLink(self.team(),self.stack())
246                }
247            ]);
248        },
249
250        "Applications" : function(self , el) {
251            return $.merge(this.Platform(self, el), [
252                {
253                    "text" : "Applications",
254                    "link" : self.LIST_LINK().call(self,'applications')
255                }
256            ]);
257        },
258
259        "Application" : function(self , el) {
260            return $.merge(this.Applications(self, el), [
261                {
262                    "text" : self.friendlyTitle(self.application()),
263                    "link" : self.LINK().call(self,self.application())
264                }
265            ]);
266        },
267
268        "Settings" : function(self , el) {
269            return $.merge(this.Application(self, el), [
270                {
271                    "text" : "Settings List",
272                    "link" : self.LIST_LINK().call(self,'settings')
273                }
274            ]);
275        },
276
277        "Setting" : function(self , el) {
278            return $.merge(this.Settings(self, el), [
279                {
280                    "text" : self.friendlyTitle(self.settings()),
281                    "link" : self.LINK().call(self,self.settings())
282                }
283            ]);
284        },
285
286        "EmailProviders" : function(self , el) {
287            return $.merge(this.Application(self, el), [
288                {
289                    "text" : "Email Providers List",
290                    "link" : self.LIST_LINK().call(self,'emailproviders')
291                }
292            ]);
293        },
294
295        "EmailProvider" : function(self , el) {
296            return $.merge(this.EmailProviders(self, el), [
297                {
298                    "text" : self.friendlyTitle(self.emailProvider()),
299                    "link" : self.LINK().call(self,self.emailProvider())
300                }
301            ]);
302        },
303
304        "Warehouses" : function(self , el) {
305            return $.merge(this.Platform(self, el), [
306                {
307                    "text" : "Warehouses",
308                    "link" : self.LIST_LINK().call(self,'warehouses')
309                }
310            ]);
311        },
312
313        "Warehouse" : function(self , el) {
314            return $.merge(this.Warehouses(self, el), [
315                {
316                    "text" : self.friendlyTitle(self.warehouse()),
317                    "link" : self.LINK().call(self,self.warehouse())
318                }
319            ]);
320        },
321
322        "Sessions" : function(self , el) {
323            return $.merge(this.Warehouse(self, el), [
324                {
325                    "text" : "Interaction Sessions",
326                    "link" : self.LIST_LINK().call(self,'sessions')
327                }
328            ]);
329        },
330
331        "Session" : function(self , el) {
332            return $.merge(this.Sessions(self, el), [
333                {
334                    "text" : self.friendlyTitle(self.session()),
335                    "link" : self.LINK().call(self,self.session())
336                }
337            ]);
338        },
339
340        "InteractionReports" : function(self , el) {
341            return $.merge(this.Warehouse(self, el), [
342                {
343                    "text" : "Interaction Reports",
344                    "link" : self.LIST_LINK().call(self,'interaction-reports')
345                }
346            ]);
347        },
348
349        "InteractionReport" : function(self , el) {
350            return $.merge(this.InteractionReports(self, el), [
351                {
352                    "text" : self.friendlyTitle(self.interactionReport()),
353                    "link" : self.LINK().call(self,self.interactionReport())
354                }
355            ]);
356        },
357
358        "InteractionPages" : function(self , el) {
359            return $.merge(this.Warehouse(self, el), [
360                {
361                    "text" : "Interaction Pages",
362                    "link" : self.LIST_LINK().call(self,'interaction-pages')
363                }
364            ]);
365        },
366
367        "InteractionPage" : function(self , el) {
368            return $.merge(this.InteractionPages(self, el), [
369                {
370                    "text" : self.friendlyTitle(self.interactionPage()),
371                    "link" : self.LINK().call(self,self.interactionPage())
372                }
373            ]);
374        },
375
376        "InteractionUsers" : function(self , el) {
377            return $.merge(this.Warehouse(self, el), [
378                {
379                    "text" : "Interaction Users",
380                    "link" : self.LIST_LINK().call(self,'interaction-users')
381                }
382            ]);
383        },
384
385        "InteractionUser" : function(self , el) {
386            return $.merge(this.InteractionUsers(self, el), [
387                {
388                    "text" : self.friendlyTitle(self.interactionUser()),
389                    "link" : self.LINK().call(self,self.interactionUser())
390                }
391            ]);
392        },
393
394        "InteractionNodes" : function(self , el) {
395            return $.merge(this.Warehouse(self, el), [
396                {
397                    "text" : "Interaction Nodes",
398                    "link" : self.LIST_LINK().call(self,'interaction-nodes')
399                }
400            ]);
401        },
402
403        "InteractionNode" : function(self , el) {
404            return $.merge(this.InteractionNodes(self, el), [
405                {
406                    "text" : self.friendlyTitle(self.interactionNode()),
407                    "link" : self.LINK().call(self,self.interactionNode())
408                }
409            ]);
410        },
411
412        "InteractionApplications" : function(self , el) {
413            return $.merge(this.Warehouse(self, el), [
414                {
415                    "text" : "Interaction Applications",
416                    "link" : self.LIST_LINK().call(self,'interaction-applications')
417                }
418            ]);
419        },
420
421        "InteractionApplication" : function(self , el) {
422            return $.merge(this.InteractionApplications(self, el), [
423                {
424                    "text" : self.friendlyTitle(self.interactionApplication()),
425                    "link" : self.LINK().call(self,self.interactionApplication())
426                }
427            ]);
428        },
429
430        "ApplicationTeams" : function(self, el) {
431            return $.merge(this.Application(self, el), [
432                {
433                    "text" : "Teams",
434                    "link" : self.LINK().call(self, self.application(), "teams")
435                }
436            ]);
437        },
438
439        "ApplicationTeam" : function(self , el) {
440            return $.merge(this.ApplicationTeams(self, el), [
441                {
442                    "text" : self.friendlyTitle(self.team()),
443                    "link" : self.teamLink(self.team(),self.application())
444                }
445            ]);
446        },
447
448        "WarehouseTeams" : function(self, el) {
449            return $.merge(this.Warehouse(self, el), [
450                {
451                    "text" : "Teams",
452                    "link" : self.LINK().call(self, self.warehouse(), "teams")
453                }
454            ]);
455        },
456
457        "WarehouseTeam" : function(self , el) {
458            return $.merge(this.WarehouseTeams(self, el), [
459                {
460                    "text" : self.friendlyTitle(self.team()),
461                    "link" : self.teamLink(self.team(),self.warehouse())
462                }
463            ]);
464        },
465
466        "Registrars" : function(self , el) {
467            return $.merge(this.Platform(self, el), [
468                {
469                    "text" : "Registrars",
470                    "link" : self.LIST_LINK().call(self,'registrars')
471                }
472            ]);
473        },
474
475        "Registrar" : function(self , el) {
476            return $.merge(this.Registrars(self, el), [
477                {
478                    "text" : self.friendlyTitle(self.registrar()),
479                    "link" : self.LINK().call(self,self.registrar())
480                }
481            ]);
482        },
483
484        "Tenants" : function(self , el) {
485            return $.merge(this.Registrar(self, el), [
486                {
487                    "text" : "Tenants",
488                    "link" : self.LIST_LINK().call(self,'tenants')
489                }
490            ]);
491        },
492
493        "Tenant" : function(self , el) {
494            return $.merge(this.Tenants(self, el), [
495                {
496                    "text" : self.friendlyTitle(self.tenant()),
497                    "link" : self.LINK().call(self,self.tenant())
498                }
499            ]);
500        },
501
502        "TenantAttachments" : function(self, el) {
503            return $.merge(this.Tenant(self, el), [
504                {
505                    "text" : "Attachments",
506                    "link" : self.LINK().call(self, self.tenant(), "attachments")
507                }
508            ]);
509        },
510
511        "TenantTeams" : function(self, el) {
512            return $.merge(this.Tenant(self, el), [
513                {
514                    "text" : "Teams",
515                    "link" : self.LINK().call(self, self.tenant(), "teams")
516                }
517            ]);
518        },
519
520        "TenantTeam" : function(self , el) {
521            return $.merge(this.TenantTeams(self, el), [
522                {
523                    "text" : self.friendlyTitle(self.team()),
524                    "link" : self.teamLink(self.team(),self.tenant())
525                }
526            ]);
527        },
528
529        "Plans" : function(self , el) {
530            return $.merge(this.Registrar(self, el), [
531                {
532                    "text" : "Plans",
533                    "link" : self.LIST_LINK().call(self,'plans')
534                }
535            ]);
536        },
537
538        "Plan" : function(self , el) {
539            return $.merge(this.Plans(self, el), [
540                {
541                    "text" : self.friendlyTitle(self.plan()),
542                    "link" : self.LINK().call(self,self.plan())
543                }
544            ]);
545        },
546
547        "Clients" : function(self , el) {
548            return $.merge(this.Platform(self, el), [
549                {
550                    "text" : "Clients",
551                    "link" : self.LIST_LINK().call(self,'clients')
552                }
553            ]);
554        },
555
556        "Client" : function(self , el) {
557            return $.merge(this.Clients(self, el), [
558                {
559                    "text" : self.friendlyTitle(self.client()),
560                    "link" : self.LINK().call(self,self.client())
561                }
562            ]);
563        },
564
565        "AuthenticationGrants" : function(self , el) {
566            return $.merge(this.Platform(self, el), [
567                {
568                    "text" : "Authentication Grants",
569                    "link" : self.LIST_LINK().call(self,'authenticationGrants')
570                }
571            ]);
572        },
573
574        "AuthenticationGrant" : function(self , el) {
575            return $.merge(this.AuthenticationGrants(self, el), [
576                {
577                    "text" : self.friendlyTitle(self.authenticationGrant()),
578                    "link" : self.LINK().call(self,self.authenticationGrant())
579                }
580            ]);
581        },
582
583        "Projects" : function(self , el) {
584            return $.merge(this.Platform(self, el), [
585                {
586                    "text" : "Projects",
587                    "link" : self.LIST_LINK().call(self,'projects')
588                }
589            ]);
590        },
591
592        "Project" : function(self , el) {
593            return $.merge(this.Projects(self, el), [
594                {
595                    "text" : self.friendlyTitle(self.project()),
596                    "link" : self.LINK().call(self,self.project())
597                }
598            ]);
599        },
600
601        "Repositories" : function(self , el) {
602            return $.merge(this.Platform(self, el), [
603                {
604                    "text" : "Repositories",
605                    "link" : self.LIST_LINK().call(self,'repositories')
606                }
607            ]);
608        },
609
610        "RepositoryLogs" : function(self , el) {
611            return $.merge(this.Repositories(self, el), [
612                {
613                    "text" : "Logs",
614                    "link" : self.LINK().call(self,self.repository(),"logs")
615                }
616            ]);
617        },
618
619        "RepositoryChangesets" : function(self , el) {
620            return $.merge(this.Repositories(self, el), [
621                {
622                    "text" : "Change Sets",
623                    "link" : self.LINK().call(self,self.repository(),"changesets")
624                }
625            ]);
626        },
627
628        "DomainGroups" : function(self , el) {
629            return $.merge(this.Domain(self, el), [
630                {
631                    "text" : "Groups",
632                    "link" : self.listLink('groups')
633                }
634            ]);
635        },
636
637        "DomainUsers" : function(self , el) {
638            return $.merge(this.Domain(self, el), [
639                {
640                    "text" : "Users",
641                    "link" : self.listLink('users')
642                }
643            ]);
644        },
645
646        "Repository" : function(self , el) {
647            return $.merge(this.Repositories(self, el), [
648                {
649                    "text" : self.friendlyTitle(self.repository()),
650                    "link" : self.LINK().call(self,self.repository())
651                }
652            ]);
653        },
654
655        "RepositoryTeams" : function(self , el) {
656            return $.merge(this.Repository(self, el), [
657                {
658                    "text" : "Teams",
659                    "link" : self.listLink('repository-teams')
660                }
661            ]);
662        },
663
664        "RepositoryTeam" : function(self , el) {
665            return $.merge(this.RepositoryTeams(self, el), [
666                {
667                    "text" : self.friendlyTitle(self.team()),
668                    "link" : self.teamLink(self.team(),self.repository())
669                }
670            ]);
671        },
672
673        "Changesets" : function(self , el) {
674            return $.merge(this.Repository(self, el), [
675                {
676                    "text" : "Changesets",
677                    "link" : self.LIST_LINK().call(self,'changesets')
678                }
679            ]);
680        },
681
682        "Changeset" : function(self , el) {
683            return $.merge(this.Changesets(self, el), [
684                {
685                    "text" : self.friendlyTitle(self.changeset()),
686                    "link" : self.LINK().call(self,self.changeset())
687                }
688            ]);
689        },
690
691        "DomainGroup" : function(self , el) {
692            return $.merge(this.DomainGroups(self, el), [
693                {
694                    "text" : self.friendlyTitle(self.group()),
695                    "link" : self.link(self.group())
696                }
697            ]);
698        },
699
700        "DomainUser" : function(self , el) {
701            return $.merge(this.DomainUsers(self, el), [
702                {
703                    "text" : self.friendlyName(self.principalUser()),
704                    "link" : self.link(self.principalUser())
705                }
706            ]);
707        },
708
709        "Branches" : function(self , el) {
710            return $.merge(this.Repository(self, el), [
711                {
712                    "text" : "Branches",
713                    "link" : self.LIST_LINK().call(self,"branches")
714                }
715            ]);
716        },
717
718        "Branch" : function(self , el) {
719            return $.merge(this.Branches(self, el), [
720                {
721                    "text" : self.friendlyTitle(self.branch()),
722                    "link" : self.LINK().call(self,self.branch())
723                }
724            ]);
725        },
726
727        "BranchLogs" : function(self , el) {
728            return $.merge(this.Branch(self, el), [
729                {
730                    "text" : "Logs",
731                    "link" : self.LINK().call(self,self.branch(),"logs")
732                }
733            ]);
734        },
735
736        "Nodes" : function(self , el) {
737            return $.merge(this.Branch(self, el), [
738                {
739                    "text" : "Nodes",
740                    "link" : self.LIST_LINK().call(self,"nodes")
741                }
742            ]);
743        },
744
745        "Tags" : function(self , el) {
746            return $.merge(this.Branch(self, el), [
747                {
748                    "text" : "Tags",
749                    "link" : self.LIST_LINK().call(self,"tags")
750                }
751            ]);
752        },
753
754        "Definitions" : function(self , el) {
755            return $.merge(this.Branch(self, el), [
756                {
757                    "text" : "Definitions",
758                    "link" : self.LIST_LINK().call(self,"definitions")
759                }
760            ]);
761        },
762
763        "Definition" : function(self , el) {
764            return $.merge(this.Definitions(self, el), [
765                {
766                    "text" : self.definition().getQName(),
767                    "link" : self.LINK().call(self,self.definition())
768                }
769            ]);
770        },
771
772        "Forms" : function(self , el) {
773            return $.merge(this.Definition(self, el), [
774                {
775                    "text" : "Forms",
776                    "link" : self.LIST_LINK().call(self,'forms')
777                }
778            ]);
779        },
780
781        "Form" : function(self , el) {
782            return $.merge(this.Forms(self, el), [
783                {
784                    "text" : self.form()['formKey'],
785                    "link" : self.LINK().call(self,self.form())
786                }
787            ]);
788        },
789
790        "Features" : function(self , el) {
791            return $.merge(this.Definition(self, el), [
792                {
793                    "text" : "Features",
794                    "link" : self.LIST_LINK().call(self,'features')
795                }
796            ]);
797        },
798
799        "Node" : function(self , el) {
800            return $.merge(this.Nodes(self, el), [
801                {
802                    "text" : self.friendlyTitle(self.node()),
803                    "link" : self.LINK().call(self,self.node())
804                }
805            ]);
806        },
807
808        "Tag" : function(self , el) {
809            return $.merge(this.Tags(self, el), [
810                {
811                    "text" : self.friendlyTitle(self.node()),
812                    "link" : self.LINK().call(self,self.node())
813                }
814            ]);
815        },
816
817        "Attachments" : function(self , el) {
818            return $.merge(this.Node(self, el), [
819                {
820                    "text" : "Attachments",
821                    "link" : self.LIST_LINK().call(self,"attachments")
822                }
823            ]);
824        },
825
826        "Associations" : function(self , el) {
827            return $.merge(this.Node(self, el), [
828                {
829                    "text" : "Associations",
830                    "link" : self.LIST_LINK().call(self,"associations")
831                }
832            ]);
833        },
834
835        "Translations" : function(self , el) {
836            return $.merge(this.Node(self, el), [
837                {
838                    "text" : "Translations",
839                    "link" : self.LIST_LINK().call(self,"translations")
840                }
841            ]);
842        },
843
844        "NodeAuditRecords" : function(self , el) {
845            return $.merge(this.Node(self, el), [
846                {
847                    "text" : "Audit Records",
848                    "link" : self.LINK().call(self,self.node(),"auditrecords")
849                }
850            ]);
851        },
852
853        "NodeFeatures" : function(self , el) {
854            return $.merge(this.Node(self, el), [
855                {
856                    "text" : "Features",
857                    "link" : self.LINK().call(self,self.node(),"features")
858                }
859            ]);
860        },
861
862        "NodeRules" : function(self , el) {
863            return $.merge(this.Node(self, el), [
864                {
865                    "text" : "Rules",
866                    "link" : self.LIST_LINK().call(self,"rules")
867                }
868            ]);
869        },
870
871        "Folder" : function(self, el, extra) {
872
873            if (self.node().get('_is_association')) {
874                return self.breadcrumb(Gitana.Console.Breadcrumb.Nodes(self));
875            } else {
876
877                var breadcrumb = self.breadcrumb(Gitana.Console.Breadcrumb.Branch(self));
878
879                var nodeId = self.node().getId();
880
881                if (Gitana.Console.Breadcrumb.PATHS[nodeId]) {
882                    var nodeBreadcrumb = $.merge(breadcrumb, Gitana.Console.Breadcrumb.PATHS[nodeId]);
883                    if (extra) {
884                        $.merge(nodeBreadcrumb, extra);
885                    }
886                    //return self.breadcrumb(nodeBreadcrumb);
887                } else {
888                    Gitana.Console.Breadcrumb.findPath(self.node(), self, function() {
889                        if (Gitana.Console.Breadcrumb.PATHS[nodeId]) {
890                            var nodeBreadcrumb = $.merge(breadcrumb, Gitana.Console.Breadcrumb.PATHS[nodeId]);
891                            if (extra) {
892                                $.merge(nodeBreadcrumb, extra);
893                            }
894
895                            self.breadcrumb(nodeBreadcrumb);
896                        }
897                    });
898                }
899
900                return self.breadcrumb(nodeBreadcrumb);
901            }
902        },
903
904        "FolderRules" : function(self , el) {
905            return $.merge(this.Folder(self, el), [
906                {
907                    "text" : "Rules",
908                    "link" : self.LIST_LINK().call(self,"rules")
909                }
910            ]);
911        },
912
913        "BillingProviders" : function(self , el) {
914            return $.merge(this.Platform(self, el), [
915                {
916                    "text" : "Billing Provider Configs",
917                    "link" : self.LIST_LINK().call(self,'billing-providers')
918                }
919            ]);
920        },
921
922        "BillingProvider" : function(self , el) {
923            return $.merge(this.BillingProviders(self, el), [
924                {
925                    "text" : self.friendlyTitle(self.billingProvider()),
926                    "link" : self.LINK().call(self,self.billingProvider())
927                }
928            ]);
929        },
930
931        "Directories" : function(self , el) {
932            return $.merge(this.Platform(self, el), [
933                {
934                    "text" : "Directories",
935                    "link" : self.LIST_LINK().call(self,'directories')
936                }
937            ]);
938        },
939
940        "Directory" : function(self , el) {
941            return $.merge(this.Directories(self, el), [
942                {
943                    "text" : self.friendlyTitle(self.directory()),
944                    "link" : self.LINK().call(self,self.directory())
945                }
946            ]);
947        },
948
949        "Identities" : function(self , el) {
950            return $.merge(this.Directory(self, el), [
951                {
952                    "text" : "Identities",
953                    "link" : self.LIST_LINK().call(self,'identities')
954                }
955            ]);
956        },
957
958        "Identity" : function(self , el) {
959            return $.merge(this.Identities(self, el), [
960                {
961                    "text" : self.friendlyTitle(self.identity()),
962                    "link" : self.LINK().call(self,self.identity())
963                }
964            ]);
965        },
966
967        "Connections" : function(self , el) {
968            return $.merge(this.Directory(self, el), [
969                {
970                    "text" : "Connections",
971                    "link" : self.LIST_LINK().call(self,'connections')
972                }
973            ]);
974        },
975
976        "Connection" : function(self , el) {
977            return $.merge(this.Connections(self, el), [
978                {
979                    "text" : self.friendlyTitle(self.connection()),
980                    "link" : self.LINK().call(self,self.connection())
981                }
982            ]);
983        },
984
985        "Webhosts" : function(self , el) {
986            return $.merge(this.Platform(self, el), [
987                {
988                    "text" : "Web Hosts",
989                    "link" : self.LIST_LINK().call(self,'webhosts')
990                }
991            ]);
992        },
993
994        "Webhost" : function(self , el) {
995            return $.merge(this.Webhosts(self, el), [
996                {
997                    "text" : self.friendlyTitle(self.webhost()),
998                    "link" : self.LINK().call(self,self.webhost())
999                }
1000            ]);
1001        },
1002
1003        "AutoClientMappings" : function(self , el) {
1004            return $.merge(this.Webhost(self, el), [
1005                {
1006                    "text" : "Auto Client Mappings",
1007                    "link" : self.LIST_LINK().call(self,'auto-client-mappings')
1008                }
1009            ]);
1010        },
1011
1012        "AutoClientMapping" : function(self , el) {
1013            return $.merge(this.AutoClientMappings(self, el), [
1014                {
1015                    "text" : self.friendlyTitle(self.autoClientMapping()),
1016                    "link" : self.LINK().call(self,self.autoClientMapping())
1017                }
1018            ]);
1019        },
1020
1021        "TrustedDomainMappings" : function(self , el) {
1022            return $.merge(this.Webhost(self, el), [
1023                {
1024                    "text" : "Trusted Domain Mappings",
1025                    "link" : self.LIST_LINK().call(self,'trusted-domain-mappings')
1026                }
1027            ]);
1028        },
1029
1030        "TrustedDomainMapping" : function(self , el) {
1031            return $.merge(this.TrustedDomainMappings(self, el), [
1032                {
1033                    "text" : self.friendlyTitle(self.trustedDomainMapping()),
1034                    "link" : self.LINK().call(self,self.trustedDomainMapping())
1035                }
1036            ]);
1037        },
1038
1039        "DeployedApplications" : function(self , el) {
1040            return $.merge(this.Webhost(self, el), [
1041                {
1042                    "text" : "Deployed Applications",
1043                    "link" : self.LIST_LINK().call(self,'deployed-applications')
1044                }
1045            ]);
1046        },
1047
1048        "DeployedApplication" : function(self , el) {
1049            return $.merge(this.DeployedApplications(self, el), [
1050                {
1051                    "text" : self.friendlyTitle(self.deployedApplication()),
1052                    "link" : self.LINK().call(self,self.deployedApplication())
1053                }
1054            ]);
1055        },
1056
1057        "PlatformActivities" : function(self , el) {
1058            return $.merge(this.Platform(self, el), [
1059                {
1060                    "text" : "Activities",
1061                    "link" : self.LIST_LINK().call(self,'activities')
1062                }
1063            ]);
1064        }
1065    };
1066
1067
1068})(jQuery);
Full Screen

filter.spec.js

Source: filter.spec.js Github

copy
1import Vue from 'vue'
2import { parseFilters } from 'compiler/parser/filter-parser'
3
4describe('Filters', () => {
5  it('basic usage', () => {
6    const vm = new Vue({
7      template: '<div>{{ msg | upper }}</div>',
8      data: {
9        msg: 'hi'
10      },
11      filters: {
12        upper: v => v.toUpperCase()
13      }
14    }).$mount()
15    expect(vm.$el.textContent).toBe('HI')
16  })
17
18  it('chained usage', () => {
19    const vm = new Vue({
20      template: '<div>{{ msg | upper | reverse }}</div>',
21      data: {
22        msg: 'hi'
23      },
24      filters: {
25        upper: v => v.toUpperCase(),
26        reverse: v => v.split('').reverse().join('')
27      }
28    }).$mount()
29    expect(vm.$el.textContent).toBe('IH')
30  })
31
32  it('in v-bind', () => {
33    const vm = new Vue({
34      template: `
35        <div
36          v-bind:id="id | upper | reverse"
37          :class="cls | reverse"
38          :ref="ref | lower">
39        </div>
40      `,
41      filters: {
42        upper: v => v.toUpperCase(),
43        reverse: v => v.split('').reverse().join(''),
44        lower: v => v.toLowerCase()
45      },
46      data: {
47        id: 'abc',
48        cls: 'foo',
49        ref: 'BAR'
50      }
51    }).$mount()
52    expect(vm.$el.id).toBe('CBA')
53    expect(vm.$el.className).toBe('oof')
54    expect(vm.$refs.bar).toBe(vm.$el)
55  })
56
57  it('handle regex with pipe', () => {
58    const vm = new Vue({
59      template: `<test ref="test" :pattern="/a|b\\// | identity"></test>`,
60      filters: { identity: v => v },
61      components: {
62        test: {
63          props: ['pattern'],
64          template: '<div></div>'
65        }
66      }
67    }).$mount()
68    expect(vm.$refs.test.pattern instanceof RegExp).toBe(true)
69    expect(vm.$refs.test.pattern.toString()).toBe('/a|b\\//')
70  })
71
72  it('handle division', () => {
73    const vm = new Vue({
74      data: { a: 2 },
75      template: `<div>{{ 1/a / 4 | double }}</div>`,
76      filters: { double: v => v * 2 }
77    }).$mount()
78    expect(vm.$el.textContent).toBe(String(1 / 4))
79  })
80
81  it('handle division with parenthesis', () => {
82    const vm = new Vue({
83      data: { a: 20 },
84      template: `<div>{{ (a*2) / 5 | double }}</div>`,
85      filters: { double: v => v * 2 }
86    }).$mount()
87    expect(vm.$el.textContent).toBe(String(16))
88  })
89
90  it('handle division with dot', () => {
91    const vm = new Vue({
92      template: `<div>{{ 20. / 5 | double }}</div>`,
93      filters: { double: v => v * 2 }
94    }).$mount()
95    expect(vm.$el.textContent).toBe(String(8))
96  })
97
98  it('handle division with array values', () => {
99    const vm = new Vue({
100      data: { a: [20] },
101      template: `<div>{{ a[0] / 5 | double }}</div>`,
102      filters: { double: v => v * 2 }
103    }).$mount()
104    expect(vm.$el.textContent).toBe(String(8))
105  })
106
107  it('handle division with hash values', () => {
108    const vm = new Vue({
109      data: { a: { n: 20 }},
110      template: `<div>{{ a['n'] / 5 | double }}</div>`,
111      filters: { double: v => v * 2 }
112    }).$mount()
113    expect(vm.$el.textContent).toBe(String(8))
114  })
115
116  it('handle division with variable++', () => {
117    const vm = new Vue({
118      data: { a: 7 },
119      template: `<div>{{ a++ / 2 | double }}</div>`,
120      filters: { double: v => v * 2 }
121    }).$mount()
122    expect(vm.$el.textContent).toBe(String(7))
123  })
124
125  it('handle division with variable--', () => {
126    const vm = new Vue({
127      data: { a: 7 },
128      template: `<div>{{ a-- / 2 | double }}</div>`,
129      filters: { double: v => v * 2 }
130    }).$mount()
131    expect(vm.$el.textContent).toBe(String(7))
132  })
133
134  it('handle division with variable_', () => {
135    const vm = new Vue({
136      data: { a_: 8 },
137      template: `<div>{{ a_ / 2 | double }}</div>`,
138      filters: { double: v => v * 2 }
139    }).$mount()
140    expect(vm.$el.textContent).toBe(String(8))
141  })
142
143  it('arguments', () => {
144    const vm = new Vue({
145      template: `<div>{{ msg | add(a, 3) }}</div>`,
146      data: {
147        msg: 1,
148        a: 2
149      },
150      filters: {
151        add: (v, arg1, arg2) => v + arg1 + arg2
152      }
153    }).$mount()
154    expect(vm.$el.textContent).toBe('6')
155  })
156
157  it('quotes', () => {
158    const vm = new Vue({
159      template: `<div>{{ msg + "b | c" + 'd' | upper }}</div>`,
160      data: {
161        msg: 'a'
162      },
163      filters: {
164        upper: v => v.toUpperCase()
165      }
166    }).$mount()
167    expect(vm.$el.textContent).toBe('AB | CD')
168  })
169
170  it('double pipe', () => {
171    const vm = new Vue({
172      template: `<div>{{ b || msg | upper }}</div>`,
173      data: {
174        b: false,
175        msg: 'a'
176      },
177      filters: {
178        upper: v => v.toUpperCase()
179      }
180    }).$mount()
181    expect(vm.$el.textContent).toBe('A')
182  })
183
184  it('object literal', () => {
185    const vm = new Vue({
186      template: `<div>{{ { a: 123 } | pick('a') }}</div>`,
187      filters: {
188        pick: (v, key) => v[key]
189      }
190    }).$mount()
191    expect(vm.$el.textContent).toBe('123')
192  })
193
194  it('array literal', () => {
195    const vm = new Vue({
196      template: `<div>{{ [1, 2, 3] | reverse }}</div>`,
197      filters: {
198        reverse: arr => arr.reverse().join(',')
199      }
200    }).$mount()
201    expect(vm.$el.textContent).toBe('3,2,1')
202  })
203
204  it('warn non-existent', () => {
205    new Vue({
206      template: '<div>{{ msg | upper }}</div>',
207      data: { msg: 'foo' }
208    }).$mount()
209    expect('Failed to resolve filter: upper').toHaveBeenWarned()
210  })
211
212  it('support template string', () => {
213    expect(parseFilters('`a | ${b}c` | d')).toBe('_f("d")(`a | ${b}c`)')
214  })
215})
216
Full Screen

copy_as_gfm.js

Source: copy_as_gfm.js Github

copy
1/* eslint-disable class-methods-use-this, object-shorthand, no-unused-vars, no-use-before-define, no-new, max-len, no-restricted-syntax, guard-for-in, no-continue */
2
3import './lib/utils/common_utils';
4
5const gfmRules = {
6  // The filters referenced in lib/banzai/pipeline/gfm_pipeline.rb convert
7  // GitLab Flavored Markdown (GFM) to HTML.
8  // These handlers consequently convert that same HTML to GFM to be copied to the clipboard.
9  // Every filter in lib/banzai/pipeline/gfm_pipeline.rb that generates HTML
10  // from GFM should have a handler here, in reverse order.
11  // The GFM-to-HTML-to-GFM cycle is tested in spec/features/copy_as_gfm_spec.rb.
12  InlineDiffFilter: {
13    'span.idiff.addition'(el, text) {
14      return `{+${text}+}`;
15    },
16    'span.idiff.deletion'(el, text) {
17      return `{-${text}-}`;
18    },
19  },
20  TaskListFilter: {
21    'input[type=checkbox].task-list-item-checkbox'(el) {
22      return `[${el.checked ? 'x' : ' '}]`;
23    },
24  },
25  ReferenceFilter: {
26    '.tooltip'(el) {
27      return '';
28    },
29    'a.gfm:not([data-link=true])'(el, text) {
30      return el.dataset.original || text;
31    },
32  },
33  AutolinkFilter: {
34    'a'(el, text) {
35      // Fallback on the regular MarkdownFilter's `a` handler.
36      if (text !== el.getAttribute('href')) return false;
37
38      return text;
39    },
40  },
41  TableOfContentsFilter: {
42    'ul.section-nav'(el) {
43      return '[[_TOC_]]';
44    },
45  },
46  EmojiFilter: {
47    'img.emoji'(el) {
48      return el.getAttribute('alt');
49    },
50    'gl-emoji'(el) {
51      return `:${el.getAttribute('data-name')}:`;
52    },
53  },
54  ImageLinkFilter: {
55    'a.no-attachment-icon'(el, text) {
56      return text;
57    },
58  },
59  VideoLinkFilter: {
60    '.video-container'(el) {
61      const videoEl = el.querySelector('video');
62      if (!videoEl) return false;
63
64      return CopyAsGFM.nodeToGFM(videoEl);
65    },
66    'video'(el) {
67      return `![${el.dataset.title}](${el.getAttribute('src')})`;
68    },
69  },
70  MathFilter: {
71    'pre.code.math[data-math-style=display]'(el, text) {
72      return `\`\`\`math\n${text.trim()}\n\`\`\``;
73    },
74    'code.code.math[data-math-style=inline]'(el, text) {
75      return `$\`${text}\`$`;
76    },
77    'span.katex-display span.katex-mathml'(el) {
78      const mathAnnotation = el.querySelector('annotation[encoding="application/x-tex"]');
79      if (!mathAnnotation) return false;
80
81      return `\`\`\`math\n${CopyAsGFM.nodeToGFM(mathAnnotation)}\n\`\`\``;
82    },
83    'span.katex-mathml'(el) {
84      const mathAnnotation = el.querySelector('annotation[encoding="application/x-tex"]');
85      if (!mathAnnotation) return false;
86
87      return `$\`${CopyAsGFM.nodeToGFM(mathAnnotation)}\`$`;
88    },
89    'span.katex-html'(el) {
90      // We don't want to include the content of this element in the copied text.
91      return '';
92    },
93    'annotation[encoding="application/x-tex"]'(el, text) {
94      return text.trim();
95    },
96  },
97  SanitizationFilter: {
98    'a[name]:not([href]):empty'(el) {
99      return el.outerHTML;
100    },
101    'dl'(el, text) {
102      let lines = text.trim().split('\n');
103      // Add two spaces to the front of subsequent list items lines,
104      // or leave the line entirely blank.
105      lines = lines.map((l) => {
106        const line = l.trim();
107        if (line.length === 0) return '';
108
109        return `  ${line}`;
110      });
111
112      return `<dl>\n${lines.join('\n')}\n</dl>`;
113    },
114    'sub, dt, dd, kbd, q, samp, var, ruby, rt, rp, abbr, summary, details'(el, text) {
115      const tag = el.nodeName.toLowerCase();
116      return `<${tag}>${text}</${tag}>`;
117    },
118  },
119  SyntaxHighlightFilter: {
120    'pre.code.highlight'(el, t) {
121      const text = t.trimRight();
122
123      let lang = el.getAttribute('lang');
124      if (!lang || lang === 'plaintext') {
125        lang = '';
126      }
127
128      // Prefixes lines with 4 spaces if the code contains triple backticks
129      if (lang === '' && text.match(/^```/gm)) {
130        return text.split('\n').map((l) => {
131          const line = l.trim();
132          if (line.length === 0) return '';
133
134          return `    ${line}`;
135        }).join('\n');
136      }
137
138      return `\`\`\`${lang}\n${text}\n\`\`\``;
139    },
140    'pre > code'(el, text) {
141       // Don't wrap code blocks in ``
142      return text;
143    },
144  },
145  MarkdownFilter: {
146    'br'(el) {
147      // Two spaces at the end of a line are turned into a BR
148      return '  ';
149    },
150    'code'(el, text) {
151      let backtickCount = 1;
152      const backtickMatch = text.match(/`+/);
153      if (backtickMatch) {
154        backtickCount = backtickMatch[0].length + 1;
155      }
156
157      const backticks = Array(backtickCount + 1).join('`');
158      const spaceOrNoSpace = backtickCount > 1 ? ' ' : '';
159
160      return backticks + spaceOrNoSpace + text.trim() + spaceOrNoSpace + backticks;
161    },
162    'blockquote'(el, text) {
163      return text.trim().split('\n').map(s => `> ${s}`.trim()).join('\n');
164    },
165    'img'(el) {
166      return `![${el.getAttribute('alt')}](${el.getAttribute('src')})`;
167    },
168    'a.anchor'(el, text) {
169      // Don't render a Markdown link for the anchor link inside a heading
170      return text;
171    },
172    'a'(el, text) {
173      return `[${text}](${el.getAttribute('href')})`;
174    },
175    'li'(el, text) {
176      const lines = text.trim().split('\n');
177      const firstLine = `- ${lines.shift()}`;
178      // Add four spaces to the front of subsequent list items lines,
179      // or leave the line entirely blank.
180      const nextLines = lines.map((s) => {
181        if (s.trim().length === 0) return '';
182
183        return `    ${s}`;
184      });
185
186      return `${firstLine}\n${nextLines.join('\n')}`;
187    },
188    'ul'(el, text) {
189      return text;
190    },
191    'ol'(el, text) {
192      // LIs get a `- ` prefix by default, which we replace by `1. ` for ordered lists.
193      return text.replace(/^- /mg, '1. ');
194    },
195    'h1'(el, text) {
196      return `# ${text.trim()}`;
197    },
198    'h2'(el, text) {
199      return `## ${text.trim()}`;
200    },
201    'h3'(el, text) {
202      return `### ${text.trim()}`;
203    },
204    'h4'(el, text) {
205      return `#### ${text.trim()}`;
206    },
207    'h5'(el, text) {
208      return `##### ${text.trim()}`;
209    },
210    'h6'(el, text) {
211      return `###### ${text.trim()}`;
212    },
213    'strong'(el, text) {
214      return `**${text}**`;
215    },
216    'em'(el, text) {
217      return `_${text}_`;
218    },
219    'del'(el, text) {
220      return `~~${text}~~`;
221    },
222    'sup'(el, text) {
223      return `^${text}`;
224    },
225    'hr'(el) {
226      return '-----';
227    },
228    'table'(el) {
229      const theadEl = el.querySelector('thead');
230      const tbodyEl = el.querySelector('tbody');
231      if (!theadEl || !tbodyEl) return false;
232
233      const theadText = CopyAsGFM.nodeToGFM(theadEl);
234      const tbodyText = CopyAsGFM.nodeToGFM(tbodyEl);
235
236      return [theadText, tbodyText].join('\n');
237    },
238    'thead'(el, text) {
239      const cells = _.map(el.querySelectorAll('th'), (cell) => {
240        let chars = CopyAsGFM.nodeToGFM(cell).length + 2;
241
242        let before = '';
243        let after = '';
244        switch (cell.style.textAlign) {
245          case 'center':
246            before = ':';
247            after = ':';
248            chars -= 2;
249            break;
250          case 'right':
251            after = ':';
252            chars -= 1;
253            break;
254          default:
255            break;
256        }
257
258        chars = Math.max(chars, 3);
259
260        const middle = Array(chars + 1).join('-');
261
262        return before + middle + after;
263      });
264
265      const separatorRow = `|${cells.join('|')}|`;
266
267      return [text, separatorRow].join('\n');
268    },
269    'tr'(el) {
270      const cellEls = el.querySelectorAll('td, th');
271      if (cellEls.length === 0) return false;
272
273      const cells = _.map(cellEls, cell => CopyAsGFM.nodeToGFM(cell));
274      return `| ${cells.join(' | ')} |`;
275    },
276  },
277};
278
279class CopyAsGFM {
280  constructor() {
281    $(document).on('copy', '.md, .wiki', (e) => { CopyAsGFM.copyAsGFM(e, CopyAsGFM.transformGFMSelection); });
282    $(document).on('copy', 'pre.code.highlight, .diff-content .line_content', (e) => { CopyAsGFM.copyAsGFM(e, CopyAsGFM.transformCodeSelection); });
283    $(document).on('paste', '.js-gfm-input', CopyAsGFM.pasteGFM);
284  }
285
286  static copyAsGFM(e, transformer) {
287    const clipboardData = e.originalEvent.clipboardData;
288    if (!clipboardData) return;
289
290    const documentFragment = window.gl.utils.getSelectedFragment();
291    if (!documentFragment) return;
292
293    const el = transformer(documentFragment.cloneNode(true));
294    if (!el) return;
295
296    e.preventDefault();
297    e.stopPropagation();
298
299    clipboardData.setData('text/plain', el.textContent);
300    clipboardData.setData('text/x-gfm', this.nodeToGFM(el));
301  }
302
303  static pasteGFM(e) {
304    const clipboardData = e.originalEvent.clipboardData;
305    if (!clipboardData) return;
306
307    const text = clipboardData.getData('text/plain');
308    const gfm = clipboardData.getData('text/x-gfm');
309    if (!gfm) return;
310
311    e.preventDefault();
312
313    window.gl.utils.insertText(e.target, (textBefore, textAfter) => {
314      // If the text before the cursor contains an odd number of backticks,
315      // we are either inside an inline code span that starts with 1 backtick
316      // or a code block that starts with 3 backticks.
317      // This logic still holds when there are one or more _closed_ code spans
318      // or blocks that will have 2 or 6 backticks.
319      // This will break down when the actual code block contains an uneven
320      // number of backticks, but this is a rare edge case.
321      const backtickMatch = textBefore.match(/`/g);
322      const insideCodeBlock = backtickMatch && (backtickMatch.length % 2) === 1;
323
324      if (insideCodeBlock) {
325        return text;
326      }
327
328      return gfm;
329    });
330  }
331
332  static transformGFMSelection(documentFragment) {
333    const gfmEls = documentFragment.querySelectorAll('.md, .wiki');
334    switch (gfmEls.length) {
335      case 0: {
336        return documentFragment;
337      }
338      case 1: {
339        return gfmEls[0];
340      }
341      default: {
342        const allGfmEl = document.createElement('div');
343
344        for (let i = 0; i < gfmEls.length; i += 1) {
345          const lineEl = gfmEls[i];
346          allGfmEl.appendChild(lineEl);
347          allGfmEl.appendChild(document.createTextNode('\n\n'));
348        }
349
350        return allGfmEl;
351      }
352    }
353  }
354
355  static transformCodeSelection(documentFragment) {
356    const lineEls = documentFragment.querySelectorAll('.line');
357
358    let codeEl;
359    if (lineEls.length > 1) {
360      codeEl = document.createElement('pre');
361      codeEl.className = 'code highlight';
362
363      const lang = lineEls[0].getAttribute('lang');
364      if (lang) {
365        codeEl.setAttribute('lang', lang);
366      }
367    } else {
368      codeEl = document.createElement('code');
369    }
370
371    if (lineEls.length > 0) {
372      for (let i = 0; i < lineEls.length; i += 1) {
373        const lineEl = lineEls[i];
374        codeEl.appendChild(lineEl);
375        codeEl.appendChild(document.createTextNode('\n'));
376      }
377    } else {
378      codeEl.appendChild(documentFragment);
379    }
380
381    return codeEl;
382  }
383
384  static nodeToGFM(node, respectWhitespaceParam = false) {
385    if (node.nodeType === Node.COMMENT_NODE) {
386      return '';
387    }
388
389    if (node.nodeType === Node.TEXT_NODE) {
390      return node.textContent;
391    }
392
393    const respectWhitespace = respectWhitespaceParam || (node.nodeName === 'PRE' || node.nodeName === 'CODE');
394
395    const text = this.innerGFM(node, respectWhitespace);
396
397    if (node.nodeType === Node.DOCUMENT_FRAGMENT_NODE) {
398      return text;
399    }
400
401    for (const filter in gfmRules) {
402      const rules = gfmRules[filter];
403
404      for (const selector in rules) {
405        const func = rules[selector];
406
407        if (!window.gl.utils.nodeMatchesSelector(node, selector)) continue;
408
409        let result;
410        if (func.length === 2) {
411          // if `func` takes 2 arguments, it depends on text.
412          // if there is no text, we don't need to generate GFM for this node.
413          if (text.length === 0) continue;
414
415          result = func(node, text);
416        } else {
417          result = func(node);
418        }
419
420        if (result === false) continue;
421
422        return result;
423      }
424    }
425
426    return text;
427  }
428
429  static innerGFM(parentNode, respectWhitespace = false) {
430    const nodes = parentNode.childNodes;
431
432    const clonedParentNode = parentNode.cloneNode(true);
433    const clonedNodes = Array.prototype.slice.call(clonedParentNode.childNodes, 0);
434
435    for (let i = 0; i < nodes.length; i += 1) {
436      const node = nodes[i];
437      const clonedNode = clonedNodes[i];
438
439      const text = this.nodeToGFM(node, respectWhitespace);
440
441      // `clonedNode.replaceWith(text)` is not yet widely supported
442      clonedNode.parentNode.replaceChild(document.createTextNode(text), clonedNode);
443    }
444
445    let nodeText = clonedParentNode.innerText || clonedParentNode.textContent;
446
447    if (!respectWhitespace) {
448      nodeText = nodeText.trim();
449    }
450
451    return nodeText;
452  }
453}
454
455window.gl = window.gl || {};
456window.gl.CopyAsGFM = CopyAsGFM;
457
458new CopyAsGFM();
459
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Run JavaScript Tests on LambdaTest Cloud Grid

Execute automation tests with Appium Xcuitest Driver on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)