Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
minor #1441 Update documentation links (smnandre)
This PR was squashed before being merged into the main branch. Discussion ---------- Update documentation links * update doclinks.js (and remove jquery usage) * update some links in BlogController * remove references to SensioFrameworkExtraBundle Commits ------- cec5eb3 Update documentation links
- Loading branch information
Showing
2 changed files
with
33 additions
and
40 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,54 @@ | ||
'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'); | ||
document.addEventListener('DOMContentLoaded', function() { | ||
const modalElt = document.querySelector('#sourceCodeModal'); | ||
if (!modalElt) { | ||
return; | ||
} | ||
const controllerCode = modalElt.querySelector('code.php'); | ||
const templateCode = modalElt.querySelector('code.twig'); | ||
|
||
function anchor(url, content) { | ||
return '<a class="doclink" target="_blank" href="' + url + '">' + content + '</a>'; | ||
}; | ||
} | ||
|
||
function wrap(content, links) { | ||
return content.replace( | ||
new RegExp(Object.keys(links).join('|'), 'g'), | ||
token => anchor(links[token], token) | ||
); | ||
}; | ||
} | ||
|
||
// 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); | ||
})); | ||
// Wrap Symfony Doc urls in comments | ||
[...modalElt.querySelectorAll('.hljs-comment')].forEach((commentElt) => { | ||
commentElt.innerHTML = commentElt.innerHTML.replace(/https:\/\/symfony.com\/[\w/.#-]+/g, (url) => anchor(url, url)); | ||
}); | ||
|
||
// Wraps Symfony's attributes | ||
var attributes = { | ||
'Cache': 'https://symfony.com/doc/current/bundles/SensioFrameworkExtraBundle/annotations/cache.html', | ||
'IsGranted': 'https://symfony.com/doc/current/bundles/SensioFrameworkExtraBundle/annotations/security.html#isgranted', | ||
'ParamConverter': 'https://symfony.com/doc/current/bundles/SensioFrameworkExtraBundle/annotations/converters.html', | ||
'Route': 'https://symfony.com/doc/current/routing.html#creating-routes-as-attributes-or-annotations', | ||
'Security': 'https://symfony.com/doc/current/bundles/SensioFrameworkExtraBundle/annotations/security.html#security' | ||
// Wraps Symfony PHP attributes in code | ||
const attributes = { | ||
'Cache': 'https://symfony.com/doc/current/http_cache.html#http-cache-expiration-intro', | ||
'Route': 'https://symfony.com/doc/current/routing.html#creating-routes-as-attributes', | ||
'IsGranted': 'https://symfony.com/doc/current/security.html#security-securing-controller-annotations' | ||
}; | ||
|
||
$controllerCode.find('.hljs-meta').each(function() { | ||
var src = $(this).text(); | ||
|
||
$(this).html(wrap(src, attributes)); | ||
[...controllerCode.querySelectorAll('.hljs-meta')].forEach((elt) => { | ||
elt.innerHTML = wrap(elt.textContent, attributes); | ||
}); | ||
|
||
// Wraps Twig's tags | ||
$templateCode.find('.hljs-template-tag + .hljs-name').each(function() { | ||
var tag = $(this).text(); | ||
|
||
[...templateCode.querySelectorAll('.hljs-template-tag + .hljs-name')].forEach((elt) => { | ||
const tag = elt.textContent; | ||
if ('else' === tag || tag.match(/^end/)) { | ||
return; | ||
} | ||
|
||
var url = 'https://twig.symfony.com/doc/3.x/tags/' + tag + '.html#' + tag; | ||
|
||
$(this).html(anchor(url, tag)); | ||
const url = 'https://twig.symfony.com/doc/3.x/tags/' + tag + '.html#' + tag; | ||
elt.innerHTML = 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/3.x/functions/' + func + '.html#' + func; | ||
|
||
$(this).html(anchor(url, func)); | ||
[...templateCode.querySelectorAll('.hljs-template-variable > .hljs-name')].forEach((elt) => { | ||
const func = elt.textContent; | ||
const url = 'https://twig.symfony.com/doc/3.x/functions/' + func + '.html#' + func; | ||
elt.innerHTML = 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