-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathscribe.perl
executable file
·2010 lines (1785 loc) · 76.5 KB
/
scribe.perl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/perl
#
# Converts an IRC log to formatted minutes in HTML.
#
# See scribe2doc.html for the manual.
# This is a rewrite of David Booth's scribe.perl
#
# TODO: option --inputFormat to select the format, rather than try
# each parser in turn.
#
# TODO: Allow (and ignore) the unused options of old scribe.perl?
#
# TODO: Add a command ('oops'? 'undo'? 'ignore'? u///g?) to remove an
# incorrect s///g, because s|s/.../.../g|| doesn't remove it.
#
# TODO: Warn about unrecognized or impossible dates after "Date: ..."
#
# TODO: A streaming mode (using --inputFormat) that formats each line
# as soon as it is read? (s/// and i//// will not work. ScribeNick is
# not retroactive. Broken lines, as in Mirc logs, are not recombined.)
#
# TODO: Make "next meeting" accept a date ("7 Aug") or a period ("in 2
# weeks") and infer a URL?
#
# TODO: If trackbot assigns a number ("ISSUE-3") to an issue, use that
# number instead of the generic "Issue". Also use it in the
# #IssueSummary.
#
# TODO: An option to omit the special handling of W3C's bots
# (currently zakim, rrsagent, agendabot and trackbot).
#
# TODO: Make commands such as scribeoptions:-implicit and
# scribeoptions:-allowspace apply only until they are overridden by
# another?
#
# TODO: RRSAgent has commands to edit or drop actions (because it
# doesn't understand s///). Should we support those?
#
# TODO: An option to add rel=nofollow to links? (In case RRSAgent is
# used to create Google karma for sites.)
#
# TODO: A command to skip several lines or end the minutes before the
# end of the input. ("StopMinutesHere", "ResumeMinutesHere"?)
#
# TODO: Should s/// commands ignore lines by the W3C bots?
#
# TODO: Ivan's minutes generator distinguishes participants (present+)
# from guests (guest+). Should scribe.perl, too?
#
# TODO: Syntax highlighting of verbatim text if there is a language
# indicated after the backquotes (as in GitHub's markdown)? (```java
# ...```)
#
# TODO: Also allow three tildes (~~~) instead of three backquotes, as
# in Markdown?
#
# TODO: A way to include (phrase-level) HTML directly?
#
# TODO: When the minutes don't start with "topic:", the first
# <section> is empty. Remove it.
#
# TODO: A way to indicate that a phrase is in a particular language?
#
# TODO: Add formatting/styling to Zakim's "question" feature?
#
# TODO: Recognize the bots if they joined under another nick name.
#
# TODO: Allow text pasted from The Lounge as input format.
#
# Copyright © 2017-2025 World Wide Web Consortium. This work is
# distributed under the W3C® Software License:
# https://www.w3.org/copyright/software-license-2023/
# or see the file COPYING included in this distribution.
#
# Created: 3 Feb 2017
# Author: Bert Bos <[email protected]>
# Conversion proceeds in six steps:
#
# 1) Various parsers are tried to convert the lines of the input
# into an array of records (see below for the structure of the
# records).
#
# 2) Processing of "s/old/new/" and "i/where/what/" commands.
#
# 3) Scanning for embedded scribeOptions, as they may affect the parsing.
#
# 4) Finding the initial scribe, from a command line option or by
# scanning for the first scribe/scribenick command.
#
# 5) Each record is interpreted, looking for topics, present & regrets,
# actions, resolutions, scribes, statements or summaries minuted by
# the scribes, and remarks by other people on IRC. Each record is
# modified and classified accordingly.
#
# 6) The array of records is converted to an HTML fragment and that
# fragment, together with the collected topics, actions, etc. are
# inserted into an HTML template and printed.
#
# Each record has four fields: {type, speaker, id, text}
# If type is 'i' (irc), <speaker> is the person who typed <text>.
# If type is 'I' (irc), <speaker> is the person who typed verbatim <text>.
# If type is 's' (scribe), <speaker> is the person who said <text> on the phone.
# If type is 'd' (description) <text> is a summary by the scribe.
# If type is 'D' (description) <text> is verbatim text by the scribe.
# If type is 'slideset', <text> is the IRC-formatted link to the slideset
# If type is 'slide', <text> is the number of the slide in the slideset and <id> is the link to the individual slide
# If type is 't' (topic), <text> is the title for a new topic.
# If type is 'T' (subtopic), <text> is the title for a new subtopic.
# If type is 'a' (action), <text> is an action and <id> is a unique ID.
# If type is 'r' (resolution), <text> is a resolution and <id> is a unique ID.
# if type is 'u' (issue), <text> is an issue, <id> a unique ID.
# If type is 'c' (change), the record is a s/// or i/// not (yet) successful
# If type is 'o' (omit), the record is to be ignored.
# If type is 'n' (named anchor), the record is a target anchor.
# If type is 'b' ('bot), the record is info from trackbot.
# If type is 'B' ('bot), <text> is info from trackbot about an issue <id>.
# If type is 'repo', <text> is a list of GitHub repositories.
# If type is 'drop', <text> is a list of GitHub repositories to remove.
use strict;
use warnings;
use Getopt::Long qw(GetOptionsFromString :config auto_version auto_help);
use Pod::Usage;
use v5.16; # We use "each @ARRAY" (5.012) and fc (5.16)
use locale ':collate'; # Sort using current locale
use utf8; # This script contains characters in UTF-8
use File::Basename;
use Encode qw/decode/; # For decode('UTF-8',...)
use Encode::Guess; # For guess_encoding()
use POSIX 'floor';
use LWP::UserAgent ();
use MIME::Base64;
# Pattern for URLs. Note: single quote (') does not end a URL.
# The pattern consists of two alternatives. The first one matches a
# URL that is not preceded by a "(" and it allows ")" in the URL. The
# second does not allow ")". This is needed to allow markdown-style
# links, which use "(" and ")" to delimit the URL.
my $urlpat =
'(?:(?<!\()(?:[a-z]+://|mailto:[^\s<@]+\@|geo:[0-9.]|urn:[a-z0-9-]+:)[^\s<>"‘’“”«»‹›]+|(?:[a-z]+://|mailto:[^\s<@]+\@|geo:[0-9.]|urn:[a-z0-9-]+:)[^\s<>"‘’“”«»‹›)]+)';
# $scribepat is something like "foo" or "foo = John Smith" or "foo/John Smith".
my $scribepat = '([^ ,/=]+) *(?:[=\/] *([^ ,](?:[^,]*[^ ,])?) *)?';
# A speaker name doesn't contain [ "::>] and doesn't start with "..".
# (":" is a full-width colon, Unicode U+FF1A.)
my $speakerpat = '(?:[^. ::">]|\\.[^. ::">])[^ ::">]*';
# Some words are unlikely to be speaker names
my $specialpat = '(?:propos(?:ed|al)|issue-\d+|action-\d+|github)';
# A pattern for a GitHub repository.
my $githuburl = '\b(?:(?i)https://github.com/[a-z0-9._-]+/[a-z0-9._-]+)';
# Command line options:
my $styleset = 'public'; # Or 'team', 'member' or 'fancy'
my $embed_diagnostics = 0; # If 1, put warnings in the HTML, not on STDERR
my $implicitcont = 0; # If 1, lines without '…' are continuations, too
my $spacecont = 0; # If 1, initial space may replace '…'
my $keeplines = 1; # If 1, put <br> between continuation lines
my $final = 0; # If 1, don't include "DRAFT" warning in minutes
my $scribenick; # Nick of the current scribe in lowercase
my $dash_topics = 0; # If 1, "--" means the next line is a topic
my $use_zakim = 1; # If 1, treat conversations with Zakim specially
my $scribeonly = 0; # If 1, omit IRC comments by others
my $emphasis = 0; # If 1, _xxx_, *xxx* and /xxx/ highlight things
my $old_style = 0; # If 1, use the old (pre-2017) style sheets
my $url_display = 'break'; # How to display in-your-face URLs
my $logo; # undef = W3C logo; string = HTML fragment
my $collapse_limit = 30; # Longer participant lists are collapsed
my $stylesheet; # URL of style sheet, undef = use defaults
my $mathjax = # undef = no math; string is MathJax URL
'https://www.w3.org/scripts/MathJax/3/es5/mml-chtml.js';
my $islide = # String is i-slide library URL
'https://w3c.github.io/i-slide/i-slide-2.js?selector=a.islide';
my $github = 1; # If 0, don't make links for GitHub issues
my $ghurlbot = 1; # If 0, hide conversations with GHURLbot
# Global variables:
my $has_math = 0; # Set to 1 by to_mathml()
my @diagnostics; # Collected warnings and other info
my $recordingstart; # Time of recording start secs since midnight)
my $recordingend; # Time of recording end (secs since midnight)
my @repositories = (); # List of repo URLs for expanding issue refs
my %ids; # All IDs (used to ensure unique IDs)
# my $clashes = 0; # For statistics: # of hash conflicts
# Used to download slideset when necessary
my $ua = LWP::UserAgent->new(timeout => 10);
# Each parser takes a reference to an array of text lines (without
# newlines) and a reference to an array of records. It returns 0
# (failed to parse) or 1 (success) and it appends successfully parsed
# lines to the array of records, with {type} set to 'i' and {speaker}
# and {text} set to the text and the nick of the person who typed that
# text. If a line includes a time stamp, the parser converts it to
# seconds since midnight and puts it in {time}.
# It should not try to parse the text futher for actions, resolutions,
# etc.
#
# IRC messages ("X joined channel Y"), private messages,
# and off-the-record text ("/me waves") are omitted.
#
# The parsers are tried in turn until one succeeds, so their order is
# important. E.g., the Plain_Text_Format should probably be towards
# the end.
my @parsers = (\&RRSAgent_text_format, \&Bip_Format, \&Mirc_Text_Format,
\&Yahoo_IM_Format, \&Bert_IRSSI_Format, \&Irssi_Format,
\&Qwebirc_paste_format, \&IRCCloud_format,
\&Quassel_paste_format, \&Plain_Text_Format);
# RRSAgent_text_format -- parse an IRC log as generated by RRSAgent
sub RRSAgent_text_format($$$$)
{
my ($lines_ref, $records_ref, $nlines_ref, $err_ref) = @_;
$$nlines_ref = 0;
foreach (@$lines_ref) {
$$nlines_ref++;
$$err_ref = $_;
if (/^(?:\d\d:\d\d:\d\d )?<([^ >]+)> \1 has (?:joined|left|changed the topic to:) /) {
# Ignore lines like "<jfm> jfm has joined #foo"
} elsif (/^(\d\d):(\d\d):(\d\d) <([^ >]+)> (.*)/) {
push(@$records_ref, {type=>'i', speaker=>$4, text=>$5,
time=> 3600 * $1 + 60 * $2 + $3});
} elsif (/^<([^ >]+)> (.*)/) {
push(@$records_ref, {type=>'i', speaker=>$1, text=>$2});
} elsif (/^\s*$/) {
# Ignore empty lines
} else {
return 0; # Unknown format, give up
}
}
return 1;
}
# Bip_Format -- parse an IRC log generated by bip
sub Bip_Format($$$$)
{
my ($lines_ref, $records_ref, $nlines_ref, $err_ref) = @_;
$$nlines_ref = 0;
foreach (@$lines_ref) {
$$nlines_ref++;
$$err_ref = $_;
if (/^\d\d-\d\d-\d{4} \d\d:\d\d:\d\d -!- /) {
# IRC server message, ignore
} elsif (/^\d\d-\d\d-\d{4} \d\d:\d\d:\d\d [<>] \* /) {
# /me message, ignore
} elsif (/^\d\d-\d\d-\d{4} (\d\d):(\d\d):(\d\d) < ([^ !:]+)![^ :]+: (.*)$/){
push(@$records_ref, {type=>'i', speaker=>$4, text=>$5,
time=> 3600 * $1 + 60 * $2 + $3});
} elsif (/^\d\d-\d\d-\d{4} (\d\d):(\d\d):(\d\d) > ([^ :]+): (.*)$/) {
push(@$records_ref, {type=>'i', speaker=>$4, text=>$5,
time=> 3600 * $1 + 60 * $2 + $3});
} elsif (/^\s*$/) {
# Ignore empty lines
} else {
return 0; # Unrecognized line, return failure
}
}
return 1;
}
# Mirc_Text_Format -- log format from saving a MIRC buffer
sub Mirc_Text_Format($$$$)
{
my ($lines_ref, $records_ref, $nlines_ref, $err_ref) = @_;
$$nlines_ref = 0;
foreach (@$lines_ref) {
$$nlines_ref++;
$$err_ref = $_;
if (/^\s*$/) {
# Empty line, ignore
} elsif (/^Start of \S+ buffer/) {
# Skip this (should be first line)
} elsif (/^End of \S+ buffer/) {
# Skip this (should be last line)
} elsif (/^\s*\*/) {
# Skip /me lines
} elsif (/^<([^ >]+)> (.*)$/) {
push(@$records_ref, {type=>'i', speaker=>$1, text=>$2});
} elsif (/^( .*)$/ && @$records_ref) { # Continuation line
$$records_ref[@$records_ref-1]->{text} .= $1;
} else {
return 0; # Unknown format
}
}
return 1;
}
# Yahoo_IM_Format -- saved log from a Yahoo IM session
sub Yahoo_IM_Format($$$$)
{
my ($lines_ref, $records_ref, $nlines_ref, $err_ref) = @_;
$$nlines_ref = 0;
foreach (@$lines_ref) {
$$nlines_ref++;
$$err_ref = $_;
if (/^([^ :]+): (.*)$/) {
push(@$records_ref, {type=>'i', speaker=>$1, text=>$2});
} elsif (/^\s*$/) {
# Ignore empty lines
} else {
return 0;
}
}
return 1;
}
# Bert_IRSSI_Format - Bert's IRSSI theme, based on elho, which should also work
sub Bert_IRSSI_Format($$$$)
{
my ($lines_ref, $records_ref, $nlines_ref, $err_ref) = @_;
$$nlines_ref = 0;
foreach (@$lines_ref) {
$$nlines_ref++;
$$err_ref = $_;
next if /^---/; # IRSSI comment about logging start/stop
next if /^[0-9:]+\s*[<>-]+ \| (\S+).*( has (?:joined|left).*)/;
next if /^[0-9:]+\s*«Quit» \| (\S+).* has signed off/;
next if /^[0-9:]+\s*«[^»]+» \|/; # IRSSI comment about users, topic, etc.
next if /^[0-9:]+\s*\* \|/; # Skip a /me command
next if /^\s*$/; # Skip empty line
if (/^(?:\w\w\w\d\d )?\[?(\d\d):(\d\d)\]?[\s@+%]*(\S+) \| (.*)/) {
push(@$records_ref, {type=>'i', speaker=>$3, text=>$4,
time=> 3600 * $1 + 60 * $2});
} else {
return 0;
}
}
return 1;
}
# Irssi_Format - logs from Coralie's Irssi
sub Irssi_Format($$$$)
{
my ($lines_ref, $records_ref, $nlines_ref, $err_ref) = @_;
$$nlines_ref = 0;
foreach (@$lines_ref) {
$$nlines_ref++;
$$err_ref = $_;
next if /^---/; # IRSSI comment about logging start/stop
next if /^[0-9:TZ-]+\s+-!-/; # Skip join/leave and other info
next if /^[0-9:TZ-]+\s+\*/; # Skip a /me command
next if /^\s*$/; # Skip empty line
if (/^[0-9-]+T(\d\d):(\d\d):(\d\d)Z\s+<([^>]+)> (.*)/) {
push(@$records_ref, {type=>'i', speaker=>$4, text=>$5,
time=> 3600 * $1 + 60 * $2 + $3});
} else {
return 0;
}
}
return 1;
}
# Qwebirc_paste_format -- copy-paste from the qwebirc web-based client
sub Qwebirc_paste_format($$$$)
{
my ($lines_ref, $records_ref, $nlines_ref, $err_ref) = @_;
$$nlines_ref = 0;
foreach (@$lines_ref) {
$$nlines_ref++;
$$err_ref = $_;
next if /^\[[0-9:]+\] ==/; # Join, quit, change nick, change topic, mode
next if /^\[[0-9:]+\] \*/; # A message with /me
next if /^\s*$/; # Empty line
if (/^\[(\d\d):(\d\d)\] <([^>]+)> (.*)$/) {
push @$records_ref, {type=>'i', speaker=>$3, text=>$4,
time=> 3600 * $1 + 60 * $2};
} else {
return 0; # This is not qwebirc
}
}
return 1;
}
# IRCCloud_format - the log format of the IRCCloud web service
sub IRCCloud_format($$$$)
{
my ($lines_ref, $records_ref, $nlines_ref, $err_ref) = @_;
$$nlines_ref = 0;
foreach (@$lines_ref) {
$$nlines_ref++;
$$err_ref = $_;
next if /^#[^ ]+$/; # IRC channel name
next if /^\[[0-9 :-]+\] → Joined /; # IRCCloud joined the channel
next if /^\[[0-9 :-]+\] → [^ ]+ joined /; # Somebody joined the channel
next if /^\[[0-9 :-]+\] ⇐ [^ ]+ quit /; # Somebody disconnected
next if /^\[[0-9 :-]+\] ⇐ You disconnected/; # User left IRCCloud
next if /^\[[0-9 :-]+\] ← [^ ]+ left /; # Somebody left the channel
next if /^\[[0-9 :-]+\] — [^ ]+ /; # A /me line
next if /^\[[0-9 :-]+\] \* [^ ]+ /; # Changed nick, changed mode...
if (/^\[[0-9-]+ (\d\d):(\d\d):(\d\d)\] <([^>]+)> (.*)$/) { # $4 said $5
push @$records_ref, {type=>'i', speaker=>$4, text=>$5,
time=> 3600 * $1 + 60 * $2 + $3};
} else {
return 0; # Not an IRCCloud log line
}
}
return 1; # All lines recognized
}
# Quassel_paste_format -- copy-paste from the Quassel chat window
sub Quassel_paste_format($$$$)
{
my ($lines_ref, $records_ref, $nlines_ref, $err_ref) = @_;
# In fact, the date and time between the square brackets can be
# anything, including month names and arbitrary punctuation. We only
# look for hh:mm and hh:mm:ss, with or without pm.
#
$$nlines_ref = 0;
foreach (@$lines_ref) {
$$nlines_ref++;
$$err_ref = $_;
next if /^\[.*?\] -->/; # Somebody joined the channel
next if /^\[.*?\] <--/; # Somebody quit the channel
next if /^\[.*?\] <->/; # Somebody changed nick
next if /^\[.*?\] \* /; # Change of topic, channel created...
next if /^\[.*?\] -\*-/; # Somebody used /me
next if /^\[.*?\] \*\*\*/; # Channel mode change
next if /^\[.*?\] - \{/; # Message "Day changed to ..."
next if /^\s*$/; # Skip empty line
if (/^\[[^]]*(\d\d?):(\d\d)(?::(\d\d))?\s*pm[^]]*\] <([^>]+)> (.*)$/i) {
push @$records_ref, {type=>'i', speaker=>$4, text=>$5,
time=> 3600 * $1 + 60 * (12 + $2) + ($3 // 0)};
} elsif (/^\[[^]]*(\d\d?):(\d\d)(?::(\d\d))?[^]]*\] <([^>]+)> (.*)$/){
push @$records_ref, {type=>'i', speaker=>$4, text=>$5,
time=> 3600 * $1 + 60 * $2 + ($3 // 0)};
} elsif (/^\[.*?\] <([^>]+)> (.*)$/) {
push @$records_ref, {type=>'i', speaker=>$1, text=>$2};
} else {
return 0;
}
}
return 1;
}
# Plain_Text_Format -- a simple text format as a scribe might write in an editor
sub Plain_Text_Format($$$$)
{
my ($lines_ref, $records_ref, $nlines_ref, $err_ref) = @_;
# This format is meant for taking minutes without IRC. Example:
#
# Topic: Closing issues
# Jim: I want to talk about issue 1.
# ... And 2, if possible.
# [General agreeement]
#
# Lines should not start with dates or times, or with bracketed
# nicknames ("<...>"), as in typical IRC logs. E.g., the following
# lines cause the parser to conclude that the input is *not*
# Plain_Text_Format:
#
# * 09:34:14 <Sue> Topic: next meeting
# * 2007-04-04 10:50 Jim: +1
# * <Aude> Not now.
#
$$nlines_ref = 0;
foreach (@$lines_ref) {
$$nlines_ref++;
$$err_ref = $_;
return 0 if /^[0-9:-]+[:-][0-9:-]/; # Seems to start w/ a date/time
return 0 if /^<[^ >]+> /; # Seems to start with a <nick>
if (/^(.+)$/) { # Not empty
push (@$records_ref, {type=>'i', speaker=>'scribe', text=>$1});
}
}
return 1;
}
# fc_uniq -- return the list of case-insensitively distinct strings in a list
sub fc_uniq(@)
{
my %seen;
return grep {!$seen{fc $_}++} @_;
}
# repository_to_url -- expand a repository name to a full URL, or undef
sub repository_to_url($)
{
my ($repo) = @_;
# A full repository URL is "BASE_URL/OWNER/REPO". If BASE_URL is
# missing, use the one from the previous repo in the list, or
# https://github.com/. If OWNER is missing, use the one from the
# previous repo, or "w3c".
#
return $repositories[0] if ! $repo; # First repo or undef
my ($base, $owner, $name) = $repo =~
/^([a-z]+:\/\/(?:[^\/?#]*\/)*?)?([^\/?#]+\/)?([^\/?#]+)\/?$/i;
return "$base$owner$name" if $base; # Just omit the final /, if any
return @repositories ? $repositories[0] =~ s/[^\/]+\/[^\/]+$/$owner$name/r :
"https://github.com/$owner$name" if $owner;
return undef if ! $name; # Malformed repo name
return "https://github.com/w3c/$name" if ! @repositories; # Assume w3c
return $repositories[0] =~ s/[^\/]+$/$name/r; # Copy base/owner from previous
}
# to_mathml -- call latexmlmath to convert a LaTeX math expression to MathML
sub to_mathml($)
{
my ($s) = @_;
my ($in, $out);
$in = $s;
$in =~ s/\\/\\\\/g;
$in =~ s/\"/\\\"/g;
$in =~ s/\$/\\\$/g;
$in =~ s/\`/\\\`/g;
# $out = `latexmlmath "$in" 2>/dev/null`;
$out = decode('UTF-8', `latexmlmath "$in" 2>/dev/null`);
push(@diagnostics, "Failed math formula: $s") if $? != 0;
return $s if $? != 0; # An error occurred, return original string
$out =~ s/<\?xml[^>]*\?>\n?//;
$has_math = 1;
return $out;
}
{
my %tag = ('_' => 'u', '/' => 'em', '*' => 'strong', '`' => 'code');
# to_emph -- replace emphasis marks and math
sub to_emph($);
sub to_emph($)
{
# Note: $` and $' must be stored in local variables before the
# recursive call, because they are global variables and might be
# changed in that call.
#
for ($_[0]) {
if (m{(?:^|\s|\p{P})\K([_/*`])(.+?)\g{1}(?=\p{P}|\s|$)}) {
my ($a, $z, $t, $m) = ($`, $', $1, $2);
return to_emph($a)."<$tag{$t}>".to_emph($m)."</$tag{$t}>".to_emph($z);
} elsif (/(?:^|[^\\])\K\$\$[^\$]+\$\$/) { # $$...$$ not preceded by a '\'
my ($a, $m, $z) = ($`, $&, $');
return to_emph($a) . to_mathml($m) . to_emph($z);
} elsif (/(?:^|[^\\])\K\$[^\$]+\$/) { # $...$ not preceded by a '\'
my ($a, $m, $z) = ($`, $&, $');
return to_emph($a) . to_mathml($m) . to_emph($z);
} elsif (/\\\$/) { # Escaped $
my ($a, $z) = ($`, $');
return to_emph($a) . '$' . to_emph($z);
} else {
return $_;
}
}
}
}
# break_url -- apply -urlDisplay option to a URL
sub break_url($)
{
my ($s) = @_;
# HTML delimiters are already escaped.
# If the URL is a well-known one, replace it with an
# abbreviation. Otherwise, if the urlDisplay option is 'break',
# insert <wbr> tags to make the URL breakable. Otherwise, if the
# urlDisplay option is 'shorten', elide the middle part of the
# URL. Otherwise return the URL unchanged.
return "$1/<wbr>$2"
if $s =~ /^https:\/\/2.zoppoz.workers.dev:443\/https\/github.com\/([^\/]+)\/([^\/]+)\/?$/;
return "$1/<wbr>$2#$4"
if $s =~ /^https:\/\/2.zoppoz.workers.dev:443\/https\/github.com\/([^\/]+)\/([^\/]+)\/(issues|pull)\/([0-9]+)$/;
return "$1/<wbr>$2#$4 (comment)"
if $s =~ /^https:\/\/2.zoppoz.workers.dev:443\/https\/github.com\/([^\/]+)\/([^\/]+)\/(issues|pull)\/([0-9]+)#issuecomment-/;
return $s =~ s|/\b|/<wbr>|gr
if $url_display eq 'break';
return $s =~ s/^((?:[^&]|&[^;]+;){5})(?:[^&]|&[^;]+;)*((?:[^&]|&[^;]+;){6})$/$1…$2/r
if $url_display eq 'shorten';
return $s;
}
# mklink -- return HTML for a URL with anchortext: link, image or just text
sub mklink($$$$)
{
my ($link, $type, $url, $anchortext) = @_;
# $link determines whether to make a link (>0) or just show the text (<0).
# $type determines whether to make a text ("->") or an image ("-->").
$url = esc($url);
if ($link > 0) {
my $s = '<a href="' . $url . '">';
if ($type eq '-->') {
$s .= '<img src="' . $url . '" alt="' . esc($anchortext) . '">';
} elsif ($anchortext ne '') {
$s .= esc($anchortext, $emphasis);
} else {
$s .= break_url($url); # Otherwise the URL itself is the anchor text
}
return "$s</a>";
} else {
return $anchortext ne '' ? esc($anchortext) : break_url($url);
}
}
# esc -- escape HTML delimiters (<>&"), optionally handle emphasis & Ralph links
sub esc($;$$$$);
sub esc($;$$$$)
{
my ($s, $emph, $link, $break_urls, $github) = @_;
my ($replacement, $pre, $url, $post, $type, $r);
if ($link) {
# Wrap Ralph-links and bare URLs in <a>.
# 1a) A double-quoted Ralph link: ... -> URL "ANCHOR" ...
# 1b) A single-quoted Ralph link: ... -> URL 'ANCHOR' ...
# 1a) An unquoted Ralph link: ... -> URL ANCHOR
# 2) A Xueyuan link: ANCHOR -> URL
# 3) An Ivan link: ... -> ANCHOR URL ...
# 4a) A double-quoted inverted Xueyuan link: ... URL -> "ANCHOR" ...
# 4b) A single-quoted inverted Xueyuan link: ... URL -> 'ANCHOR' ...
# 4c) An unquoted inverted Xueyuan link: ... URL -> ANCHOR
# 5) A markdown link: ... [ANCHOR](URL)
# 6) A bare URL: ... URL ...
# With --> instead of ->, the link is embedded as an image (<img>).
# If $link < 0, omit the <a> tag and just insert the text or image.
# Loop until we found all URLs.
$replacement = '';
while (($pre, $url, $post) = $s =~ /^(.*?)($urlpat)(.*)$/i) {
# Look for "->" or "-->" before or after the URL.
if ($pre =~ /(--?>) *$/p) { # Ralph, Xueyuan or missing anchor text
$type = $1;
$pre = $`;
if ($post =~ /^ *"([^"\t]*)"/p || $post =~ /^ *'([^'\t]*)'/p ||
$post =~ /^ *([^'" \t][^\t]*[^ \t]) */p ||
$post =~ /^ *([^'" \t]) */p) { # Ralph link
$r = mklink($link, $type, $url, $1);
$replacement .= esc($pre, $emph, 0, 0, $github) . $r;
$s = $';
} elsif ($pre =~ / *([^ \t][^\t]*[^ \t]|[^ \t]) *$/p) { # Xueyuan link
$r = mklink($link, $type, $url, $1);
$replacement .= esc($`, $emph, 0, 0, $github) . $r;
$s = $post;
} else { # Missing anchor text
$replacement .= esc($pre, $emph, 0, 0, $github)
. mklink($link, $type, $url, '');
$s = $post;
}
} elsif ($pre =~ /(--?>) *(.+?) *$/p) { # Ivan link
$r = mklink($link, $1, $url, $2);
$replacement .= esc($`, $emph, 0, 0, $github) . $r;
$s = $post;
} elsif ($post =~ /^ *(--?>) *"([^"\t]*)"/p ||
$post =~ /^ *(--?>) *'([^'\t]*)'/p ||
$post =~ /^ *(--?>) *([^ \t][^\t]*[^ \t]) */p ||
$post =~ /^ *(--?>) *([^ \t]) */p ||
$post =~ /^ *(--?>) *()/p) { # Inverted Xueyuan link
$r = mklink($link, $1, $url, $2);
$replacement .= esc($pre, $emph, 0, 0, $github) . $r;
$s = $';
} elsif ($post =~ /^\)/ && $pre =~ /!\[([^\]]+)\]\($/p) { # Markdown image
$r = mklink($link, "-->", $url, $1);
$replacement .= esc($`) . $r;
$s = $post =~ s/^\)//r;
} elsif ($post =~ /^\)/ && $pre =~ /\[([^\]]+)\]\($/p) { # Markdown link
$r = mklink($link, "->", $url, $1);
$replacement .= esc($`, $emph) . $r;
$s = $post =~ s/^\)//r;
} else { # Bare URL.
$replacement .= esc($pre, $emph, 0, 0, $github)
. mklink($link, '->', $url, '');
$s = $post;
}
}
$s = $replacement . esc($s, $emph, 0, 0, $github);
} elsif ($break_urls) { # Shorten or break URLs
$s = esc($s, $emph);
$s =~ s/($urlpat)/break_url($1)/gie;
} elsif ($github) {
$replacement = '';
while ($s =~ /(?:^|\W)\K((?:[a-z0-9._-]+\/)?[a-z0-9._-]+)?#([0-9]+)(?=\W|$)/i) {
$s = $';
my ($repo, $issue) = ($1 // '', $2);
$replacement .= esc($`, $emph);
$replacement .= ($r = repository_to_url($repo))
? '<a href="'.esc("$r/issues/$issue")."\">$repo#$issue</a>"
: "$repo#$issue";
}
$s = $replacement . esc($s, $emph);
} else {
$s =~ s/&/&/g;
$s =~ s/</</g;
$s =~ s/>/>/g;
$s =~ s/"/"/g;
if ($emph) {
$s =~ s/:-\)/☺/g;
$s =~ s/;-\)/😉\x{FE0E}/g;
$s =~ s/:-\(/☹/g;
$s =~ s{:-/}{😕\x{FE0E}}g;
$s =~ s/,-\)/😜\x{FE0E}/g;
$s =~ s{\\o/}{🙌\x{FE0E}}g;
$s =~ s/(?:^|[^-])\K-->/⟶/g;
$s =~ s/(?:^|[^-])\K->/→/g;
$s =~ s/(?:^|[^=])\K==>/⟹/g;
$s =~ s/(?:^|[^=])\K=>/⇒/g;
$s =~ s/<--(?!-)/⟵/g;
$s =~ s/<-(?!-)/←/g;
$s =~ s/<==(?!=)/⟸/g;
$s =~ s/<=(?!=)/⇐/g;
$s = to_emph($s); # Italics, bold, underline, monospace, math
}
}
return $s;
}
# is_cur_scribe -- true if $nick is in %$curscribes_ref, ignores trailing "_"
sub is_cur_scribe($$)
{
my ($nick, $curscribes_ref) = @_;
return $$curscribes_ref{fc($nick =~ s/_+$//r)} || $$curscribes_ref{'*'};
}
# add_scribes -- add scribes to the scribe list and the current scribes
sub add_scribes($$$$)
{
my ($names, $curscribes_ref, $scribes_ref, $scribenames_ref) = @_;
# We may assume $names matches zero or more comma-separated $scribepat
foreach (split(/ *, */, $names)) { # Split at commas
my ($nick, $real) = /^$scribepat$/; # Split into nick and real name
my $n = fc($nick =~ s/_+$//r); # Case-insensitive, without trailing _
$$curscribes_ref{$n} = 1; # Add nick as current scribe
push @$scribes_ref, $n; # Add nick to overall scribe list
# Add a new real name, or use the nick as real name if there was none.
if ($real) {$$scribenames_ref{$n} = $real;}
elsif (!$$scribenames_ref{$n}) {$$scribenames_ref{$n} = $nick;}
}
}
# delete_scribes -- remove from current scribe list
sub delete_scribes($$)
{
my ($names, $curscribes_ref) = @_;
# We may assume $names matches zero or more comma-separated $scribepat
foreach (split(/ *, */, $names)) { # Split at commas
my ($nick, $real) = /^$scribepat$/; # Split into name and real name
my $n = fc($nick =~ s/_+$//r); # Case-insensitive, without trailing _
delete $$curscribes_ref{$n}; # Remove from curscribes
}
}
# link_to_recording -- return an HTML link to the recording at $time, or ""
sub link_to_recording($$)
{
my ($url, $time) = @_;
my ($offset, $endoffset);
return '' if !defined $url || !defined $recordingstart || !defined $time;
$offset = $time - $recordingstart;
# If they are more than 8 hours apart, we assume we're comparing
# across midnight and add 24 hours.
$offset += 24 * 3600 if $offset < -8 * 3600;
return '' if $offset < 0; # We're before the start of the recording
# Check if we are already after the end of the recording.
if (defined $recordingend) {
$endoffset = $recordingend - $time;
$endoffset += 24 * 3600 if $endoffset < -8 * 3600;
return '' if $endoffset <= 0;
}
return sprintf " <a href=\"%1\$s#t=%2\$s\" class=recording title=\"matching video record\">🎞\x{FE0E}</a>", esc($url), $offset;
}
# add_repositories -- expand repository names to full URLs and remember them
sub add_repositories($)
{
my $repos = shift;
my $r;
# $repos is a comma- or space-separated list of possibly abbreviated
# repository names. Expand them to full URLs and prefix the
# resulting list of URLs to the global @repositories. E.g.,
# "foo/bar, other/bar, baz" is expanded to
# "https://github.com/foo/bar, https://github.com/other/bar,
# https://github.com/other/baz".
#
foreach (split /[ ,]+/, $repos) {
if (($r = repository_to_url($_))) {
unshift @repositories, $r;
} else {
push @diagnostics, "Could not interpret as a repository: $_";
}
}
}
# remove_repositories -- remove one or more repositories from the list
sub remove_repositories($)
{
my ($repos) = @_;
my $r;
foreach (split /[ ,]+/, $repos) {
if (($r = repository_to_url($_))) {
@repositories = grep $_ ne $r, @repositories;
} else {
push @diagnostics, "Could not interpret as a repository: $_";
}
}
}
# make_id -- make a unique ID based on a seed value and a hash of a text
sub make_id($$)
{
my $hash = $_[0];
$hash = (($hash + $_) << 7) + ($hash >> 11) for unpack('U0C*', $_[1]);
$hash &= 0xFFFF;
# $clashes++, $hash++ while exists $ids{$hash};
$hash++ while exists $ids{$hash};
$ids{$hash} = 1;
return sprintf "%04x", $hash;
}
# Main body
my $revision = '$Revision: 244 $'
=~ s/\$Revision: //r
=~ s/ \$//r;
my $versiondate = '$Date: Thu Feb 27 01:23:09 2025 UTC $'
=~ s/\$Date: //r
=~ s/ \$//r;
my @scribes; # List of scribes
my %scribenames; # Map scribe nicknames to real names
my @records; # Array of parsed lines
my $date; # Date of the meeting
my $meeting = "(MEETING TITLE)"; # Name of the meeting (HTML-escaped)
my $prev_meeting = ''; # HTML-formatted link to previous meeting
my $next_meeting = ''; # HTML-formatted link to next meeting
my %present; # List of participants
my %regrets; # List of regrets
my $minutes_url; # URL of the minutes according to RRSAgent
my $logging_url; # URL of the log according to RRSAgent
my $agenda = ''; # HTML-formatted link to an agenda
my %chairs; # List of meeting chairs
my %lastspeaker; # Current speaker (separate for each scribe)
my $speakerid = 's00'; # Generates unique ID for each speaker
my $has_slides = 0; # Set to 1 if there is at least one slideset
my $lastslideset; # URL of the slideset being presented
my $embeddedslideset; # id of the link element that embeds a data url
# encoding of the slideset (for i-slide)
my $embeddedslidesetcounter = 0;# counter of embedded slidesets
my $recording; # URL of the recording of the meeting
my $recording_link; # HTML-formatted link to the recording
my %speakers; # Unique ID for each speaker
my %namedanchors; # Set of already used IDs for NamedAnchorsHere
my %curscribes; # Indexes are the current scribenicks
my %verbatim; # End of preformatted mode for nick: ``` or ]]
my $agenda_icon = '<img alt="Agenda." title="Agenda" ' .
'src="https://www.w3.org/StyleSheets/scribe2/chronometer.png">';
my $irclog_icon = '<img alt="IRC log." title="IRC log" ' .
'src="https://www.w3.org/StyleSheets/scribe2/text-plain.png">';
my $previous_icon = '<img alt="Previous meeting." title="Previous meeting" ' .
'src="https://www.w3.org/StyleSheets/scribe2/go-previous.png">';
my $next_icon = '<img alt="Next meeting." title="Next meeting" ' .
'src="https://www.w3.org/StyleSheets/scribe2/go-next.png">';
my $w3clogo = '<a href="https://www.w3.org/"><img src="https://www.w3.org/' .
'StyleSheets/TR/2016/logos/W3C" alt=W3C border=0 height=48 width=72></a>';
my %bots = (fc('RRSAgent') => 1, # Nicks that probably aren't scribe
fc('trackbot') => 1,
fc('ghurlbot') => 1,
fc('gb') => 1,
fc('github-bot') => 1,
fc('agendabot') => 1,
fc('Zakim') => 1);
my %options = ("team" => sub {$styleset = 'team'},
"member" => sub {$styleset = 'member'},
"fancy" => sub {$styleset = 'fancy'},
"embedDiagnostics!" => \$embed_diagnostics,
"implicitContinuations!" => \$implicitcont,
"allowSpaceContinuation!" => \$spacecont,
"keepLines!" => \$keeplines,
"urlDisplay=s" => sub {
if ($_[1] =~ /^(?:break|shorten|full$)/i) {$url_display=$_[1]}
else {die "--urlDisplay must be break, shorten or full\n"}},
"final!" => \$final,
"draft!" => sub {$final = ! $_[1]},
"scribenick=s" => \$scribenick,
"dashTopics!" => \$dash_topics,
"useZakimTopics!" => \$use_zakim,
"scribeOnly!" => \$scribeonly,
"emphasis!" => \$emphasis,
"mathjax=s" => \$mathjax,
"islide=s" => \$islide,
"oldStyle!" => \$old_style,
"stylesheet:s" => \$stylesheet,
"logo:s" => \$logo,
"nologo" => sub {$logo = ''},
"collapseLimit:i" => \$collapse_limit,
"githubIssues!" => \$github,
"ghurlbot!" => \$ghurlbot,
"minutes=s" => \$minutes_url);
my @month = ('', 'January', 'February', 'March', 'April', 'May', 'June', 'July',
'August', 'September', 'October', 'November', 'December');
# Automatically encode output to stdout and stderr as UTF-8. We do not
# automatically decode stdin as UTF-8, because the program might
# occasionally be used on old files that are in Latin-1.
# guess_encoding() below detects that case.
#
binmode(STDOUT, ':utf8');
binmode(STDERR, ':utf8');
GetOptionsFromString($ENV{"SCRIBEOPTIONS"}, %options) if $ENV{"SCRIBEOPTIONS"};
GetOptions(%options) or pod2usage(2);
# Step 1: Read all lines into a temporary array; replace tabs by
# spaces and remove carriage returns and newlines; then try each
# parser in turn to parse them into records, until one succeeds.
#
do {
local $/;
my $input = <>;
# Try to guess the encoding: ASCII, UTF-8/16/32 or Latin-1.
my $decoder = guess_encoding($input, 'latin-1');
# Decode the input. If not known or ambiguous, try UTF-8.
$input = ref($decoder) ? $decoder->decode($input) : decode('UTF-8', $input);
# Split into lines, remove newlines, replace tabs by spaces.
my @input = map tr/\t/ /r, split(/\r?\n/, $input);
$input[0] =~ s/^\x{FEFF}// if scalar @input; # Remove the BOM, if any
my ($nlines, $errline, $n, $e) = (0, '', 0, '');
do {
last if &$_(\@input, \@records, \$n, \$e);
($nlines, $errline) = ($n, $e) if $n > $nlines;
@records = ();
} foreach (@parsers);
push(@diagnostics, 'Input is empty.') if !@records && !$nlines;
push(@diagnostics, "Unrecognized input at line $nlines: $errline")
if !@records && $nlines;
};
# Step 2: Process s/old/new/ and i/where/what/ commands.
#
# First mark all s/// and i/// lines as 'c', so that they don't get
# changed by other s/// lines. Then loop over all lines again and
# apply the substitutions and insertions. Successful s/// and i///
# become of type 'o' (omit).
#
# If people try to use s/// to replace URLs and they copy-paste the
# URLs from certain old minutes, there might be zero-width non-joiner
# characters in the URLs. Remove them before matching.
#
foreach (@records) {
$_->{type} = 'c' if
$_->{text} =~ /^ *(s|i)(\/|\|)(.*?)\2(.*?)(?:\2([gG])? *)?$/;
}
for (my $i = 0; $i < @records; $i++) {
if ($records[$i]->{type} eq 'c' &&
$records[$i]->{text} =~ /^ *(s|i)(\/|\|)(.*?)\2(.*?)(?:\2([gG])? *)?$/) {
my ($cmd, $delim, $old, $new, $global) = ($1, $2, $3, $4, $5);
my $old2 = $old =~ s/\x{200C}//gr; # Version without any U+200C
if ($old eq '') {
push(@diagnostics, 'Malformed: ' . $records[$i]->{text});
next;
}
push(@diagnostics, "Warning: ‘$records[$i]->{text}’ interpreted as replacing ‘$old’ by ‘$new’")
if $cmd eq 's' && $new =~ /\Q$delim\E/;
push(@diagnostics, "Warning: ‘$records[$i]->{text}’ interpreted as inserting ‘$new’ before ‘$old’")