Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
Showing
6 changed files
with
83 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.