-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update link target attributes in livescript htmls
- Loading branch information
1 parent
5c5400f
commit 78c1f8d
Showing
16 changed files
with
204 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
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
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
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
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
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
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
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,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 |