Is it possible to use relative links to files in Live Editor?
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Martin Roempert
le 11 Août 2017
Réponse apportée : Mikhail
le 10 Oct 2018
If I export a hyperlink created in Live Editor *.mlx file to HTML I simply want a
<a href = "doc.html">
but I always get some
<a href = "http://doc.html">
or
<a href = "file://doc.html">
and I do not want to have absolute pathes in the generated HTML.
By the way ... if I set the Target URL to
D:\doc.html
I get the expected result in the generated HTML.
<a href = "file:///D:/doc.html">
But this is not what I want.
0 commentaires
Réponse acceptée
Baptiste Ottino
le 11 Août 2017
Modifié(e) : Baptiste Ottino
le 11 Août 2017
Yes, this is pretty annoying. I found a work-around using the live editor markup. Instead of using the "hyperlink" button, write the link in the following syntax in your mlx file:
[the label of the link](doc.html)
If you write the right-hand bracket last, the label will highlight automatically in blue just like a normal hyperlink would, but you won't have the annoying http: formatting.
EDIT
I realize that I didn't really answered your initial question. The goal of my first answer was to let you have the correct links in your mlx files. Now let's see how to make it work in html.
I work with R2016b, and I get the same issue when I use the "export as html" button. I will need a bit more thought to find a proper fix, but here are two ways of fixing this:
First solution (dirty hotfix)
Overload the function
% for R2016b
matlab.internal.richeditor.openAndConvert
% for 2017a
matlab.internal.liveeditor.openAndConvert
or just modify it if you have admin tools, so that when you publish through the button, those lines are executed:
% Construct the name of your html-file from your mlx-file
[~, mlxName, mlxExt] = fileparts(mlxFile);
filePath = strcat(mlxName, '.html');
% Read the html file
fin = fopen(filePath, 'r');
text = fread(fin, '*char')';
fclose(fin);
% delete bad URLs paths
text=strrep(text,'https://localhost:61415/toolbox/matlab/codetools/liveeditor/','');
% Write back the html file
fout = fopen(filePath, 'w');
fprintf(fout, '%s', text);
fclose(fout);
It is a bit of a brute force solution, but it works.
Second solution (for best output)
Personally, I have been very disappointed by the way the live editor publishes html. For one thing, it does not let you choose your xsl stylesheet, so you're stucke with the default. It also plots your equations and plots in bitmap and not in vectorial.
I have been working on a script that fixes these issues. Unfortunately, I am still waiting for my compagny to give me the green light for publication on mathworks, since it was developped during work hours. I'll give you the general idea though: save the live script as a m-file, and publish to html using the publish function.
function mlx2html(mlxFile)
% Construct the name of your m-file from your mlx-file
% (slightly different name to prevent shadowing)
[~, mlxName, mlxExt] = fileparts(mlxFile);
mFile = strcat(mlxName,'_ouput', '.m');
% Convert mlx-file to m-file
% for R2016b
matlab.internal.richeditor.openAndConvert(mlxFile, mFile);
% for 2017a
% matlab.internal.liveeditor.openAndConvert(mlxFile, mFile);
% Publish the m-file in html
publish(mFile)
end
Use this solution if you úse this publish function to have good looking html pages. If I do post my code, I will be sure to comment here. Best of luck!
3 commentaires
Baptiste Ottino
le 11 Août 2017
Hello Martin,
Unfortunately, I don't know of an easy fix. I edited my first answer to give you some advice on how to proceed.
Plus de réponses (1)
Mikhail
le 10 Oct 2018
Looks like export to HTML doesn't do things to relative links anymore as of R2018b.
0 commentaires
Voir également
Catégories
En savoir plus sur Entering Commands dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!