Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions assets/js/app.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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.

Loading