add zci__mor-at class for links
parent
617d27c394
commit
d4fedd24d4
|
@ -230,12 +230,12 @@ sub make_html {
|
||||||
# Returns a html formatted string containing the HTML character name, entity, and a link
|
# Returns a html formatted string containing the HTML character name, entity, and a link
|
||||||
my $html = "";
|
my $html = "";
|
||||||
if (scalar(@{$_[0]}) == 1) { # single line answer
|
if (scalar(@{$_[0]}) == 1) { # single line answer
|
||||||
$html = "<div>$_[0][0][0] (&$_[0][0][1];): &<span>$_[0][0][1]</span>; <a href=\"$url\">More at W3</a></div>" ; # link in the same line for single line answers
|
$html = "<div>$_[0][0][0] (&$_[0][0][1];): &<span>$_[0][0][1]</span>; <a class=\"zci__more-at\" href=\"$url\">More at W3</a></div>" ; # link in the same line for single line answers
|
||||||
} else {
|
} else {
|
||||||
foreach my $i (0 .. scalar(@{$_[0]}) - 1) { # multiple line answer
|
foreach my $i (0 .. scalar(@{$_[0]}) - 1) { # multiple line answer
|
||||||
$html = "$html" . "<div>$_[0][$i][0] (&$_[0][$i][1];): &<span>$_[0][$i][1]</span>;</div>";
|
$html = "$html" . "<div>$_[0][$i][0] (&$_[0][$i][1];): &<span>$_[0][$i][1]</span>;</div>";
|
||||||
}
|
}
|
||||||
$html = "$html" . "<div><a href=\"$url\">More at W3</a></div>";
|
$html = "$html" . "<div><a class=\"zci__more-at\" href=\"$url\">More at W3</a></div>";
|
||||||
}
|
}
|
||||||
return $html;
|
return $html;
|
||||||
};
|
};
|
||||||
|
@ -255,6 +255,7 @@ handle remainder => sub {
|
||||||
$hashes_query =~ s/\-/ /; # change '-' to ' '
|
$hashes_query =~ s/\-/ /; # change '-' to ' '
|
||||||
$hashes_query =~ s/"//; # remove double quote
|
$hashes_query =~ s/"//; # remove double quote
|
||||||
$hashes_query =~ s/'//; # remove single quote
|
$hashes_query =~ s/'//; # remove single quote
|
||||||
|
|
||||||
# If a string still exists after the stripping, lookup the accented_chars hash if it's an accented character query and if it's not an accented char look up the codes hash
|
# If a string still exists after the stripping, lookup the accented_chars hash if it's an accented character query and if it's not an accented char look up the codes hash
|
||||||
if ($hashes_query) {
|
if ($hashes_query) {
|
||||||
if ($hashes_query =~ /^(a|A|e|E|i|I|o|O|u|U)\s*(grave|acute)$/) { # search query is for an accented character
|
if ($hashes_query =~ /^(a|A|e|E|i|I|o|O|u|U)\s*(grave|acute)$/) { # search query is for an accented character
|
||||||
|
@ -285,7 +286,7 @@ handle remainder => sub {
|
||||||
$entity =~ s/^&//;
|
$entity =~ s/^&//;
|
||||||
$entity =~ s/;$//;
|
$entity =~ s/;$//;
|
||||||
my $text = "Encoded HTML Entity: &$entity;";
|
my $text = "Encoded HTML Entity: &$entity;";
|
||||||
my $html = "<div>Encoded HTML Entity (&$entity;): &<span>$entity</span>; <a href=\"$url\">More at W3</a></div>";
|
my $html = "<div>Encoded HTML Entity: &<span>$entity</span>; <a class=\"zci__more-at\" href=\"$url\">More at W3</a></div>";
|
||||||
return $text, html => $html;
|
return $text, html => $html;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,6 @@ triggers startend => 'url encode', 'encode url', 'urlencode', 'encodeurl', 'urle
|
||||||
my $url = "https://en.wikipedia.org/wiki/Url_encoding";
|
my $url = "https://en.wikipedia.org/wiki/Url_encoding";
|
||||||
handle remainder => sub {
|
handle remainder => sub {
|
||||||
my $holder = uri_encode($_);
|
my $holder = uri_encode($_);
|
||||||
return "Encoded URL: $holder", html => "<div>Encoded URL: $holder</div><div>More at <a href=\"$url\">Wikipedia</a></div>";
|
return "Encoded URL: $holder", html => "<div>Encoded URL: $holder</div><div><a class=\"zci__more-at\" href=\"$url\">More at Wikipedia</a></div>";
|
||||||
};
|
};
|
||||||
1;
|
1;
|
||||||
|
|
|
@ -12,57 +12,57 @@ ddg_goodie_test(
|
||||||
# Test 1
|
# Test 1
|
||||||
'html code em dash' => test_zci(
|
'html code em dash' => test_zci(
|
||||||
"Em dash: —",
|
"Em dash: —",
|
||||||
html => "<div>Em dash (—): &<span>mdash</span>; <a href=\"http://dev.w3.org/html5/html-author/charref\">More at W3</a></div>",
|
html => "<div>Em dash (—): &<span>mdash</span>; <a class=\"zci__more-at\" href=\"http://dev.w3.org/html5/html-author/charref\">More at W3</a></div>",
|
||||||
),
|
),
|
||||||
# Test 2 - querying accented chars
|
# Test 2 - querying accented chars
|
||||||
'html entity A-acute' => test_zci(
|
'html entity A-acute' => test_zci(
|
||||||
"A-acute: Á",
|
"A-acute: Á",
|
||||||
html => "<div>A-acute (Á): &<span>Aacute</span>; <a href=\"http://dev.w3.org/html5/html-author/charref\">More at W3</a></div>",
|
html => "<div>A-acute (Á): &<span>Aacute</span>; <a class=\"zci__more-at\" href=\"http://dev.w3.org/html5/html-author/charref\">More at W3</a></div>",
|
||||||
),
|
),
|
||||||
# Test 3
|
# Test 3
|
||||||
'html encode &' => test_zci(
|
'html encode &' => test_zci(
|
||||||
"Encoded HTML Entity: &",
|
"Encoded HTML Entity: &",
|
||||||
html => "<div>Encoded HTML Entity (&): &<span>amp</span>; <a href=\"http://dev.w3.org/html5/html-author/charref\">More at W3</a></div>",
|
html => "<div>Encoded HTML Entity: &<span>amp</span>; <a class=\"zci__more-at\" href=\"http://dev.w3.org/html5/html-author/charref\">More at W3</a></div>",
|
||||||
),
|
),
|
||||||
# Test 4 - hyphens in between don't matter
|
# Test 4 - hyphens in between don't matter
|
||||||
'html code em-dash' => test_zci(
|
'html code em-dash' => test_zci(
|
||||||
"Em dash: —",
|
"Em dash: —",
|
||||||
html => "<div>Em dash (—): &<span>mdash</span>; <a href=\"http://dev.w3.org/html5/html-author/charref\">More at W3</a></div>",
|
html => "<div>Em dash (—): &<span>mdash</span>; <a class=\"zci__more-at\" href=\"http://dev.w3.org/html5/html-author/charref\">More at W3</a></div>",
|
||||||
),
|
),
|
||||||
# Test 5 - variety in querying accented chars
|
# Test 5 - variety in querying accented chars
|
||||||
'html entity for E grave' => test_zci(
|
'html entity for E grave' => test_zci(
|
||||||
"E-grave: È",
|
"E-grave: È",
|
||||||
html => "<div>E-grave (È): &<span>Egrave</span>; <a href=\"http://dev.w3.org/html5/html-author/charref\">More at W3</a></div>",
|
html => "<div>E-grave (È): &<span>Egrave</span>; <a class=\"zci__more-at\" href=\"http://dev.w3.org/html5/html-author/charref\">More at W3</a></div>",
|
||||||
),
|
),
|
||||||
# Test 6
|
# Test 6
|
||||||
'html encode $' => test_zci(
|
'html encode $' => test_zci(
|
||||||
"Encoded HTML Entity: $",
|
"Encoded HTML Entity: $",
|
||||||
html => "<div>Encoded HTML Entity ($): &<span>#36</span>; <a href=\"http://dev.w3.org/html5/html-author/charref\">More at W3</a></div>",
|
html => "<div>Encoded HTML Entity: &<span>#36</span>; <a class=\"zci__more-at\" href=\"http://dev.w3.org/html5/html-author/charref\">More at W3</a></div>",
|
||||||
),
|
),
|
||||||
# Test 7 - two entities returned
|
# Test 7 - two entities returned
|
||||||
'html encode pound symbol' => test_zci(
|
'html encode pound symbol' => test_zci(
|
||||||
"British Pound Sterling: £\nNumber sign: #",
|
"British Pound Sterling: £\nNumber sign: #",
|
||||||
html => "<div>British Pound Sterling (£): &<span>pound</span>;</div><div>Number sign (#): &<span>#35</span>;</div><div><a href=\"http://dev.w3.org/html5/html-author/charref\">More at W3</a></div>",
|
html => "<div>British Pound Sterling (£): &<span>pound</span>;</div><div>Number sign (#): &<span>#35</span>;</div><div><a class=\"zci__more-at\" href=\"http://dev.w3.org/html5/html-author/charref\">More at W3</a></div>",
|
||||||
),
|
),
|
||||||
# Test 8 - extra words like 'for' and 'sign' can be typed in, and are taken care of in the code / new trigger
|
# Test 8 - extra words like 'for' and 'sign' can be typed in, and are taken care of in the code / new trigger
|
||||||
'htmlencode pilcrow sign' => test_zci(
|
'htmlencode pilcrow sign' => test_zci(
|
||||||
"Pilcrow: ¶",
|
"Pilcrow: ¶",
|
||||||
html => "<div>Pilcrow (¶): &<span>#182</span>; <a href=\"http://dev.w3.org/html5/html-author/charref\">More at W3</a></div>",
|
html => "<div>Pilcrow (¶): &<span>#182</span>; <a class=\"zci__more-at\" href=\"http://dev.w3.org/html5/html-author/charref\">More at W3</a></div>",
|
||||||
),
|
),
|
||||||
# Test 9 - new trigger
|
# Test 9 - new trigger
|
||||||
'html escape greater than symbol' => test_zci(
|
'html escape greater than symbol' => test_zci(
|
||||||
"Greater than: >",
|
"Greater than: >",
|
||||||
html => "<div>Greater than (>): &<span>gt</span>; <a href=\"http://dev.w3.org/html5/html-author/charref\">More at W3</a></div>",
|
html => "<div>Greater than (>): &<span>gt</span>; <a class=\"zci__more-at\" href=\"http://dev.w3.org/html5/html-author/charref\">More at W3</a></div>",
|
||||||
),
|
),
|
||||||
# Test 10 - handling too much space / new trigger
|
# Test 10 - handling too much space / new trigger
|
||||||
'space encodehtml' => test_zci(
|
'space encodehtml' => test_zci(
|
||||||
"Non-breaking space: ",
|
"Non-breaking space: ",
|
||||||
html => "<div>Non-breaking space ( ): &<span>nbsp</span>; <a href=\"http://dev.w3.org/html5/html-author/charref\">More at W3</a></div>",
|
html => "<div>Non-breaking space ( ): &<span>nbsp</span>; <a class=\"zci__more-at\" href=\"http://dev.w3.org/html5/html-author/charref\">More at W3</a></div>",
|
||||||
),
|
),
|
||||||
# Test 11 - standardized output / new trigger
|
# Test 11 - standardized output / new trigger
|
||||||
'aPostTophe escapehtml' => test_zci(
|
'ApoSTrophe escapehtml' => test_zci(
|
||||||
"Apostrophe: '",
|
"Apostrophe: '",
|
||||||
html => "<div>Apostrophe ('): &<span>#39</span>; <a href=\"http://dev.w3.org/html5/html-author/charref\">More at W3</a></div>",
|
html => "<div>Apostrophe ('): &<span>#39</span>; <a class=\"zci__more-at\" href=\"http://dev.w3.org/html5/html-author/charref\">More at W3</a></div>",
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -11,28 +11,28 @@ ddg_goodie_test(
|
||||||
[qw(DDG::Goodie::URLEncode)],
|
[qw(DDG::Goodie::URLEncode)],
|
||||||
# Test 1 - simple
|
# Test 1 - simple
|
||||||
'url encode http://nospaces.duckduckgo.com/hook em horns' => test_zci("Encoded URL: http://nospaces.duckduckgo.com/hook%20em%20horns",
|
'url encode http://nospaces.duckduckgo.com/hook em horns' => test_zci("Encoded URL: http://nospaces.duckduckgo.com/hook%20em%20horns",
|
||||||
html => "<div>Encoded URL: http://nospaces.duckduckgo.com/hook%20em%20horns</div><div>More at <a href=\"https://en.wikipedia.org/wiki/Url_encoding\">Wikipedia</a></div>"),
|
html => "<div>Encoded URL: http://nospaces.duckduckgo.com/hook%20em%20horns</div><div><a class=\"zci__more-at\" href=\"https://en.wikipedia.org/wiki/Url_encoding\">More at Wikipedia</a></div>"),
|
||||||
# Test 2 - with spaces
|
# Test 2 - with spaces
|
||||||
'encode url xkcd.com/a webcomic of%romance+math+sarcasm+language' => test_zci("Encoded URL: xkcd.com/a%20webcomic%20of%25romance+math+sarcasm+language",
|
'encode url xkcd.com/a webcomic of%romance+math+sarcasm+language' => test_zci("Encoded URL: xkcd.com/a%20webcomic%20of%25romance+math+sarcasm+language",
|
||||||
html => "<div>Encoded URL: xkcd.com/a%20webcomic%20of%25romance+math+sarcasm+language</div><div>More at <a href=\"https://en.wikipedia.org/wiki/Url_encoding\">Wikipedia</a></div>"),
|
html => "<div>Encoded URL: xkcd.com/a%20webcomic%20of%25romance+math+sarcasm+language</div><div><a class=\"zci__more-at\" href=\"https://en.wikipedia.org/wiki/Url_encoding\">More at Wikipedia</a></div>"),
|
||||||
# Test 3 - spaces between keyword and query data
|
# Test 3 - spaces between keyword and query data
|
||||||
'http://arstechnica.com/space after end url encode' => test_zci("Encoded URL: http://arstechnica.com/space%20after%20end%20",
|
'http://arstechnica.com/space after end url encode' => test_zci("Encoded URL: http://arstechnica.com/space%20after%20end%20",
|
||||||
html => "<div>Encoded URL: http://arstechnica.com/space%20after%20end%20</div><div>More at <a href=\"https://en.wikipedia.org/wiki/Url_encoding\">Wikipedia</a></div>"),
|
html => "<div>Encoded URL: http://arstechnica.com/space%20after%20end%20</div><div><a class=\"zci__more-at\" href=\"https://en.wikipedia.org/wiki/Url_encoding\">More at Wikipedia</a></div>"),
|
||||||
# Test 4 - nothing to encode
|
# Test 4 - nothing to encode
|
||||||
'apple.com/mac encode URL' => test_zci("Encoded URL: apple.com/mac",
|
'apple.com/mac encode URL' => test_zci("Encoded URL: apple.com/mac",
|
||||||
html => "<div>Encoded URL: apple.com/mac</div><div>More at <a href=\"https://en.wikipedia.org/wiki/Url_encoding\">Wikipedia</a></div>"),
|
html => "<div>Encoded URL: apple.com/mac</div><div><a class=\"zci__more-at\" href=\"https://en.wikipedia.org/wiki/Url_encoding\">More at Wikipedia</a></div>"),
|
||||||
# Test 5 - new triggers
|
# Test 5 - new triggers
|
||||||
'https://example.com/zero#clickinfo^34* encodeurl' => test_zci("Encoded URL: https://example.com/zero#clickinfo%5E34*",
|
'https://example.com/zero#clickinfo^34* encodeurl' => test_zci("Encoded URL: https://example.com/zero#clickinfo%5E34*",
|
||||||
html => "<div>Encoded URL: https://example.com/zero#clickinfo%5E34*</div><div>More at <a href=\"https://en.wikipedia.org/wiki/Url_encoding\">Wikipedia</a></div>"),
|
html => "<div>Encoded URL: https://example.com/zero#clickinfo%5E34*</div><div><a class=\"zci__more-at\" href=\"https://en.wikipedia.org/wiki/Url_encoding\">More at Wikipedia</a></div>"),
|
||||||
# Test 6 - more characters to convert / new trigger
|
# Test 6 - more characters to convert / new trigger
|
||||||
'urlencode https://example.org/the answer to"life%the-universe.and<>everything\|}{' => test_zci("Encoded URL: https://example.org/the%20answer%20to%22life%25the-universe.and%3C%3Eeverything%5C%7C%7D%7B",
|
'urlencode https://example.org/the answer to"life%the-universe.and<>everything\|}{' => test_zci("Encoded URL: https://example.org/the%20answer%20to%22life%25the-universe.and%3C%3Eeverything%5C%7C%7D%7B",
|
||||||
html => "<div>Encoded URL: https://example.org/the%20answer%20to%22life%25the-universe.and%3C%3Eeverything%5C%7C%7D%7B</div><div>More at <a href=\"https://en.wikipedia.org/wiki/Url_encoding\">Wikipedia</a></div>"),
|
html => "<div>Encoded URL: https://example.org/the%20answer%20to%22life%25the-universe.and%3C%3Eeverything%5C%7C%7D%7B</div><div><a class=\"zci__more-at\" href=\"https://en.wikipedia.org/wiki/Url_encoding\">More at Wikipedia</a></div>"),
|
||||||
# Test 7 - even more characters / new trigger
|
# Test 7 - even more characters / new trigger
|
||||||
'urlescape https://example.org/the-alchemist_`purified gold...in&the/middle!OfTheSandstorm' => test_zci("Encoded URL: https://example.org/the-alchemist_%60purified%20gold...in&the/middle!OfTheSandstorm",
|
'urlescape https://example.org/the-alchemist_`purified gold...in&the/middle!OfTheSandstorm' => test_zci("Encoded URL: https://example.org/the-alchemist_%60purified%20gold...in&the/middle!OfTheSandstorm",
|
||||||
html => "<div>Encoded URL: https://example.org/the-alchemist_%60purified%20gold...in&the/middle!OfTheSandstorm</div><div>More at <a href=\"https://en.wikipedia.org/wiki/Url_encoding\">Wikipedia</a></div>"),
|
html => "<div>Encoded URL: https://example.org/the-alchemist_%60purified%20gold...in&the/middle!OfTheSandstorm</div><div><a class=\"zci__more-at\" href=\"https://en.wikipedia.org/wiki/Url_encoding\">More at Wikipedia</a></div>"),
|
||||||
# Test 8 - brackets and parantheses / new trigger
|
# Test 8 - brackets and parantheses / new trigger
|
||||||
'www.herokuapp.com/(){}[] urlencode' => test_zci("Encoded URL: www.herokuapp.com/()%7B%7D[]",
|
'www.herokuapp.com/(){}[] urlencode' => test_zci("Encoded URL: www.herokuapp.com/()%7B%7D[]",
|
||||||
html => "<div>Encoded URL: www.herokuapp.com/()%7B%7D[]</div><div>More at <a href=\"https://en.wikipedia.org/wiki/Url_encoding\">Wikipedia</a></div>"),
|
html => "<div>Encoded URL: www.herokuapp.com/()%7B%7D[]</div><div><a class=\"zci__more-at\" href=\"https://en.wikipedia.org/wiki/Url_encoding\">More at Wikipedia</a></div>"),
|
||||||
);
|
);
|
||||||
|
|
||||||
done_testing;
|
done_testing;
|
||||||
|
|
Loading…
Reference in New Issue