Skip to content

Commit

Permalink
feature #777 Make links to the documentation clickable (voronkovich)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
javiereguiluz committed Apr 19, 2018
2 parents 3c5d376 + 034e5e5 commit 0f008c8
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 15 deletions.
3 changes: 3 additions & 0 deletions assets/js/app.js
Expand Up @@ -7,3 +7,6 @@ import 'bootstrap-sass/assets/javascripts/bootstrap/modal.js';

// loads the code syntax highlighting library
import './highlight.js';

// Creates links to the Symfony documentation
import './doclinks.js';
58 changes: 58 additions & 0 deletions assets/js/doclinks.js
@@ -0,0 +1,58 @@
'use strict';

// Wraps some elements in anchor tags referencing to the Symfony documentation
$(function() {
var $modal = $('#sourceCodeModal');
var $controllerCode = $modal.find('code.php');
var $templateCode = $modal.find('code.twig');

function anchor(url, content) {
return '<a class="doclink" target="_blank" href="' + url + '">' + content + '</a>';
};

// Wraps links to the Symfony documentation
$modal.find('.hljs-comment').each(function() {
$(this).html($(this).html().replace(/https:\/\/symfony.com\/doc\/[\w/.#-]+/g, function(url) {
return anchor(url, url);
}));
});

// Wraps Symfony's annotations
var annotations = {
'@Cache': 'https://symfony.com/doc/current/bundles/SensioFrameworkExtraBundle/annotations/cache.html',
'@Method': 'https://symfony.com/doc/current/bundles/SensioFrameworkExtraBundle/annotations/routing.html#route-method',
'@ParamConverter': 'https://symfony.com/doc/current/bundles/SensioFrameworkExtraBundle/annotations/converters.html',
'@Route': 'https://symfony.com/doc/current/bundles/SensioFrameworkExtraBundle/annotations/routing.html#usage',
'@Security': 'https://symfony.com/doc/current/bundles/SensioFrameworkExtraBundle/annotations/security.html'
};

$controllerCode.find('.hljs-doctag').each(function() {
var annotation = $(this).text();

if (annotations[annotation]) {
$(this).html(anchor(annotations[annotation], annotation));
}
});

// Wraps Twig's tags
$templateCode.find('.hljs-template-tag > .hljs-name').each(function() {
var tag = $(this).text();

if ('else' === tag || tag.match(/^end/)) {
return;
}

var url = 'https://twig.symfony.com/doc/2.x/tags/' + tag + '.html#' + tag;

$(this).html(anchor(url, tag));
});

// Wraps Twig's functions
$templateCode.find('.hljs-template-variable > .hljs-name').each(function() {
var func = $(this).text();

var url = 'https://twig.symfony.com/doc/2.x/functions/' + func + '.html#' + func;

$(this).html(anchor(url, func));
});
});
4 changes: 4 additions & 0 deletions assets/scss/app.scss
Expand Up @@ -43,6 +43,10 @@ i {
vertical-align: middle;
}

.doclink {
color: inherit
}

/* Utilities
------------------------------------------------------------------------- */
.m-b-0 { margin-bottom: 0 }
Expand Down
4 changes: 2 additions & 2 deletions public/build/css/app.css

Large diffs are not rendered by default.

0 comments on commit 0f008c8

Please sign in to comment.