File: hyperref.perl

package info (click to toggle)
latex2html 2023-debian1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 6,924 kB
  • sloc: perl: 34,024; makefile: 437; sh: 32
file content (87 lines) | stat: -rwxr-xr-x 2,807 bytes parent folder | download | duplicates (3)
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
#!/usr/bin/perl

# this file is loaded if a file contains
# \usepackage{hyperref}

# allows latex2html to process files containing
# the \href command defined by hyperref.sty
# and therefore allows latex2html to process files
# written for hyperref.sty without modifying them for latex2html

# WARNING: html.sty / html.perl also declares its own instance of \hyperref
# with an incompatible interface. Additionally declared is \hyperrefhyper
# whose interface is like that of \hyperref from hyperref.sty.
#
# If both hyperref.sty and html.sty are necessary,
# and \hyperref from hyperref.sty is needed, the following workaround may do:
#
# \usepackage{hyperref}
# \usepackage{html}
# \renewcommand{\hyperref}[2][]{\hyperrefhyper[#1]{#2}}

package main;

# Suppress option warning messages:

sub do_hyperref_colorlinks {}
sub do_hyperref_backref {}
sub do_hyperref_pagebackref {}
sub do_hyperref_pdfstartview_FitH {}
sub do_hyperref_breaklinks {}

sub do_cmd_href {
    local($_) = @_;
    local($url, $anchor);
    $url = &missing_braces unless (
	(s/$next_pair_pr_rx/$url = $2;''/eo)
	||(s/$next_pair_rx/$url = $2;''/eo));
    $anchor = &missing_braces unless (
	(s/$next_pair_pr_rx/$anchor=$2;''/eo)
	||(s/$next_pair_rx/$anchor=$2;''/eo));
    # and recode the ~ (don't turn it to space)
    $url =~ s/~/~/go;
    "<a href=\"$url\">$anchor</a>".$_;
}

sub do_cmd_hyperref {
    local($_) = @_;
    local($opt, $dummy) = &get_next_optional_argument;
    if ($opt ne '') {
        return (&process_hyperref($cross_ref_mark,$opt));
    }
    local($url, $anchor, $name, $text);
    $url = &missing_braces unless (
	(s/$next_pair_pr_rx/$url = $2;''/eo)
	||(s/$next_pair_rx/$url = $2;''/eo));
    $anchor = &missing_braces unless (
	(s/$next_pair_pr_rx/$anchor=$2;''/eo)
	||(s/$next_pair_rx/$anchor=$2;''/eo));
    $name = &missing_braces unless (
	(s/$next_pair_pr_rx/$name=$2;''/eo)
	||(s/$next_pair_rx/$name=$2;''/eo));
    $text = &missing_braces unless (
	(s/$next_pair_pr_rx/$text=$2;''/eo)
	||(s/$next_pair_rx/$text=$2;''/eo));
    $anchor = $anchor . '.' . $name   if $name   ne '';
    $url    = $url    . '#' . $anchor if $anchor ne '';
    # and recode the ~ (don't turn it to space)
    $url =~ s/~/&#126;/go;
    "<a href=\"$url\">$text</a>".$_;
}

sub process_hyperref {
    local($ref_mark, $label) = @_;
    local($id, $text);
    $text = &missing_braces unless
	((s/$next_pair_pr_rx/($id, $text) = ($1, $2); ''/eo)
	||(s/$next_pair_rx/($id, $text) = ($1, $2); ''/eo));
    $label =~ s/<[^>]*>//go ; #RRM: Remove any HTML tags
    $label =~ s/$label_rx/_/g;	# replace non alphanumeric characters

    print "\nLINK: $ref_mark\#$label\#$id  :$text:" if ($VERBOSITY > 3);

    # The quotes around the HREF are inserted later
    join('',"<A HREF=$ref_mark#$label#$id>$text<\/A>", $_);
}

1;