Skip to content

Commit 0f008c8

Browse files
committed
feature #777 Make links to the documentation clickable (voronkovich)
This PR was squashed before being merged into the master branch (closes #777). Discussion ---------- Make links to the documentation clickable It's so tiring to copy & paste urls... ![clickable-links](https://user-images.githubusercontent.com/2299535/38275448-8cdb028e-379a-11e8-9107-498b505e228f.png) Commits ------- 034e5e5 Make links to the documentation clickable
2 parents 3c5d376 + 034e5e5 commit 0f008c8

File tree

6 files changed

+83
-15
lines changed

6 files changed

+83
-15
lines changed

assets/js/app.js

+3
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,6 @@ import 'bootstrap-sass/assets/javascripts/bootstrap/modal.js';
77

88
// loads the code syntax highlighting library
99
import './highlight.js';
10+
11+
// Creates links to the Symfony documentation
12+
import './doclinks.js';

assets/js/doclinks.js

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
'use strict';
2+
3+
// Wraps some elements in anchor tags referencing to the Symfony documentation
4+
$(function() {
5+
var $modal = $('#sourceCodeModal');
6+
var $controllerCode = $modal.find('code.php');
7+
var $templateCode = $modal.find('code.twig');
8+
9+
function anchor(url, content) {
10+
return '<a class="doclink" target="_blank" href="' + url + '">' + content + '</a>';
11+
};
12+
13+
// Wraps links to the Symfony documentation
14+
$modal.find('.hljs-comment').each(function() {
15+
$(this).html($(this).html().replace(/https:\/\/symfony.com\/doc\/[\w/.#-]+/g, function(url) {
16+
return anchor(url, url);
17+
}));
18+
});
19+
20+
// Wraps Symfony's annotations
21+
var annotations = {
22+
'@Cache': 'https://symfony.com/doc/current/bundles/SensioFrameworkExtraBundle/annotations/cache.html',
23+
'@Method': 'https://symfony.com/doc/current/bundles/SensioFrameworkExtraBundle/annotations/routing.html#route-method',
24+
'@ParamConverter': 'https://symfony.com/doc/current/bundles/SensioFrameworkExtraBundle/annotations/converters.html',
25+
'@Route': 'https://symfony.com/doc/current/bundles/SensioFrameworkExtraBundle/annotations/routing.html#usage',
26+
'@Security': 'https://symfony.com/doc/current/bundles/SensioFrameworkExtraBundle/annotations/security.html'
27+
};
28+
29+
$controllerCode.find('.hljs-doctag').each(function() {
30+
var annotation = $(this).text();
31+
32+
if (annotations[annotation]) {
33+
$(this).html(anchor(annotations[annotation], annotation));
34+
}
35+
});
36+
37+
// Wraps Twig's tags
38+
$templateCode.find('.hljs-template-tag > .hljs-name').each(function() {
39+
var tag = $(this).text();
40+
41+
if ('else' === tag || tag.match(/^end/)) {
42+
return;
43+
}
44+
45+
var url = 'https://twig.symfony.com/doc/2.x/tags/' + tag + '.html#' + tag;
46+
47+
$(this).html(anchor(url, tag));
48+
});
49+
50+
// Wraps Twig's functions
51+
$templateCode.find('.hljs-template-variable > .hljs-name').each(function() {
52+
var func = $(this).text();
53+
54+
var url = 'https://twig.symfony.com/doc/2.x/functions/' + func + '.html#' + func;
55+
56+
$(this).html(anchor(url, func));
57+
});
58+
});

assets/scss/app.scss

+4
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ i {
4343
vertical-align: middle;
4444
}
4545

46+
.doclink {
47+
color: inherit
48+
}
49+
4650
/* Utilities
4751
------------------------------------------------------------------------- */
4852
.m-b-0 { margin-bottom: 0 }

public/build/css/app.css

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)