Skip to content

Commit

Permalink
Update link target attributes in livescript htmls
Browse files Browse the repository at this point in the history
  • Loading branch information
ehennestad committed Dec 8, 2024
1 parent 5c5400f commit 78c1f8d
Show file tree
Hide file tree
Showing 16 changed files with 204 additions and 15 deletions.
11 changes: 10 additions & 1 deletion docs/source/_static/html/tutorials/basicUsage.html
Original file line number Diff line number Diff line change
Expand Up @@ -428,4 +428,13 @@
end
##### SOURCE END #####
-->
</div></body></html>
</div><script>
// Update all links with href starting with "https:" to have target="top"
document.addEventListener("DOMContentLoaded", function() {
const links = document.querySelectorAll('a[href^="https:"]');
links.forEach(link => {
link.setAttribute("target", "top");
});
});
</script>
</body></html>
11 changes: 10 additions & 1 deletion docs/source/_static/html/tutorials/behavior.html
Original file line number Diff line number Diff line change
Expand Up @@ -366,4 +366,13 @@
fprintf('Exported NWB file to "%s"\n', 'behavior_tutorial.nwb')
##### SOURCE END #####
-->
</div></body></html>
</div><script>
// Update all links with href starting with "https:" to have target="top"
document.addEventListener("DOMContentLoaded", function() {
const links = document.querySelectorAll('a[href^="https:"]');
links.forEach(link => {
link.setAttribute("target", "top");
});
});
</script>
</body></html>
11 changes: 10 additions & 1 deletion docs/source/_static/html/tutorials/dimensionMapNoDataPipes.html
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,13 @@
%
##### SOURCE END #####
-->
</div></body></html>
</div><script>
// Update all links with href starting with "https:" to have target="top"
document.addEventListener("DOMContentLoaded", function() {
const links = document.querySelectorAll('a[href^="https:"]');
links.forEach(link => {
link.setAttribute("target", "top");
});
});
</script>
</body></html>
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,13 @@
%
##### SOURCE END #####
-->
</div></body></html>
</div><script>
// Update all links with href starting with "https:" to have target="top"
document.addEventListener("DOMContentLoaded", function() {
const links = document.querySelectorAll('a[href^="https:"]');
links.forEach(link => {
link.setAttribute("target", "top");
});
});
</script>
</body></html>
11 changes: 10 additions & 1 deletion docs/source/_static/html/tutorials/dynamic_tables.html
Original file line number Diff line number Diff line change
Expand Up @@ -574,4 +574,13 @@
%
##### SOURCE END #####
-->
</div></body></html>
</div><script>
// Update all links with href starting with "https:" to have target="top"
document.addEventListener("DOMContentLoaded", function() {
const links = document.querySelectorAll('a[href^="https:"]');
links.forEach(link => {
link.setAttribute("target", "top");
});
});
</script>
</body></html>
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,13 @@
%
##### SOURCE END #####
-->
</div></body></html>
</div><script>
// Update all links with href starting with "https:" to have target="top"
document.addEventListener("DOMContentLoaded", function() {
const links = document.querySelectorAll('a[href^="https:"]');
links.forEach(link => {
link.setAttribute("target", "top");
});
});
</script>
</body></html>
11 changes: 10 additions & 1 deletion docs/source/_static/html/tutorials/ecephys.html
Original file line number Diff line number Diff line change
Expand Up @@ -1353,4 +1353,13 @@
%%
##### SOURCE END #####
-->
</div></body></html>
</div><script>
// Update all links with href starting with "https:" to have target="top"
document.addEventListener("DOMContentLoaded", function() {
const links = document.querySelectorAll('a[href^="https:"]');
links.forEach(link => {
link.setAttribute("target", "top");
});
});
</script>
</body></html>
11 changes: 10 additions & 1 deletion docs/source/_static/html/tutorials/icephys.html
Original file line number Diff line number Diff line change
Expand Up @@ -506,4 +506,13 @@
%
##### SOURCE END #####
-->
</div></body></html>
</div><script>
// Update all links with href starting with "https:" to have target="top"
document.addEventListener("DOMContentLoaded", function() {
const links = document.querySelectorAll('a[href^="https:"]');
links.forEach(link => {
link.setAttribute("target", "top");
});
});
</script>
</body></html>
11 changes: 10 additions & 1 deletion docs/source/_static/html/tutorials/images.html
Original file line number Diff line number Diff line change
Expand Up @@ -368,4 +368,13 @@
nwbExport(nwb, "images_test.nwb");
##### SOURCE END #####
-->
</div></body></html>
</div><script>
// Update all links with href starting with "https:" to have target="top"
document.addEventListener("DOMContentLoaded", function() {
const links = document.querySelectorAll('a[href^="https:"]');
links.forEach(link => {
link.setAttribute("target", "top");
});
});
</script>
</body></html>
11 changes: 10 additions & 1 deletion docs/source/_static/html/tutorials/intro.html
Original file line number Diff line number Diff line change
Expand Up @@ -304,4 +304,13 @@
% documentation> to learn what data types are available.
##### SOURCE END #####
-->
</div></body></html>
</div><script>
// Update all links with href starting with "https:" to have target="top"
document.addEventListener("DOMContentLoaded", function() {
const links = document.querySelectorAll('a[href^="https:"]');
links.forEach(link => {
link.setAttribute("target", "top");
});
});
</script>
</body></html>
11 changes: 10 additions & 1 deletion docs/source/_static/html/tutorials/ogen.html
Original file line number Diff line number Diff line change
Expand Up @@ -198,4 +198,13 @@
nwbExport(nwb, 'ogen_tutorial.nwb');
##### SOURCE END #####
-->
</div></body></html>
</div><script>
// Update all links with href starting with "https:" to have target="top"
document.addEventListener("DOMContentLoaded", function() {
const links = document.querySelectorAll('a[href^="https:"]');
links.forEach(link => {
link.setAttribute("target", "top");
});
});
</script>
</body></html>
11 changes: 10 additions & 1 deletion docs/source/_static/html/tutorials/ophys.html
Original file line number Diff line number Diff line change
Expand Up @@ -476,4 +476,13 @@
%%
##### SOURCE END #####
-->
</div></body></html>
</div><script>
// Update all links with href starting with "https:" to have target="top"
document.addEventListener("DOMContentLoaded", function() {
const links = document.querySelectorAll('a[href^="https:"]');
links.forEach(link => {
link.setAttribute("target", "top");
});
});
</script>
</body></html>
11 changes: 10 additions & 1 deletion docs/source/_static/html/tutorials/read_demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -353,4 +353,13 @@
% out the DANDI breakout session later in this event.
##### SOURCE END #####
-->
</div></body></html>
</div><script>
// Update all links with href starting with "https:" to have target="top"
document.addEventListener("DOMContentLoaded", function() {
const links = document.querySelectorAll('a[href^="https:"]');
links.forEach(link => {
link.setAttribute("target", "top");
});
});
</script>
</body></html>
11 changes: 10 additions & 1 deletion docs/source/_static/html/tutorials/remote_read.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,13 @@
%
##### SOURCE END #####
-->
</div></body></html>
</div><script>
// Update all links with href starting with "https:" to have target="top"
document.addEventListener("DOMContentLoaded", function() {
const links = document.querySelectorAll('a[href^="https:"]');
links.forEach(link => {
link.setAttribute("target", "top");
});
});
</script>
</body></html>
11 changes: 10 additions & 1 deletion docs/source/_static/html/tutorials/scratch.html
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,13 @@
%
##### SOURCE END #####
-->
</div></body></html>
</div><script>
// Update all links with href starting with "https:" to have target="top"
document.addEventListener("DOMContentLoaded", function() {
const links = document.querySelectorAll('a[href^="https:"]');
links.forEach(link => {
link.setAttribute("target", "top");
});
});
</script>
</body></html>
54 changes: 54 additions & 0 deletions tools/documentation/private/postProcessLivescriptHtml.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
function postProcessLivescriptHtml(htmlFile)
%POSTPROCESSLIVESCRIPHTML Update links in an HTML file to open in the top frame
%
% This function reads an HTML file and updates all <a> tags with an
% href attribute starting with "https:" by adding or updating the
% target attribute to "top". The modified HTML content is written
% back to the same file.
%
% Syntax:
% postProcessLivescriptHtml(htmlFile)
%
% Input:
% htmlFile - (1,1) string: Path to the HTML file to process.
%
% Example:
% postProcessLivescriptHtml("example.html");
%
% This will ensure that links in "example.html" with href="https:"
% open in the top frame when clicked.

% The purpose of this function is to ensure links open in the top frame
% and not an iframe if tutorial htmls are embedded in an iframe.

arguments
htmlFile (1,1) string {mustBeFile}
end

% Read the content of the HTML file
htmlContent = fileread(htmlFile);

% % Add target="top" to links with href starting with https
% updatedHtmlContent = regexprep(htmlContent, ...
% '<a href="https://', ...
% '<a target="top" href="https://');
% updatedHtmlContent = regexprep(updatedHtmlContent, ...
% '<a href = "https://', ...
% '<a target = "top" href = "https://');
str = fileread('update_link_target_js.html');
updatedHtmlContent = regexprep(htmlContent, ...
"</div></body></html>", ...
sprintf("</div>%s</body></html>", str));

% Write the modified content back to the HTML file
try
fid = fopen(htmlFile, 'wt');
if fid == -1
error('Could not open the file for writing: %s', htmlFile);
end
fwrite(fid, updatedHtmlContent, 'char');
fclose(fid);
catch
error('Could not write to the file: %s', htmlFile);
end
end

0 comments on commit 78c1f8d

Please sign in to comment.