sassoftware / vscode-sas-extension

This SAS Extension for Visual Studio Code provides support for the SAS language, including features such as SAS syntax highlighting, code completion, hover help, code folding, outline, SAS code snippets and run SAS code.
https://sassoftware.github.io/vscode-sas-extension/
Apache License 2.0
121 stars 48 forks source link

Get working hyperlinks in displayed ODS HTML5 output #695

Open jbodart-argenx opened 11 months ago

jbodart-argenx commented 11 months ago

Is your feature request related to a problem? Please describe. I'm always frustrated when I generate an ODS HTML output containing hyperlinks to local files, that is automatically rendered in VScode, as for some reason clicking the hyperlinks does nothing, while I was hoping it would open the hyperlinked file.

Describe the solution you'd like I would like the hyperlinked file to open either in VScode preferably or alternatively in the default application for that file type

Describe alternatives you've considered Alternatively, a way to open the ODS HTML5 output file in an external browser window (in which the hyperlinks would work)

Environment SAS version 9.4 (local - DOM) on windows 10 desktop

scottdover commented 11 months ago

Hey @jbodart-argenx. Would there be a way to provide a sample of what might produce this kind of output?

jbodart-argenx commented 11 months ago

I will provide some sample code

jbodart-argenx commented 11 months ago

Here is the sample code. I saved it to my home folder and ran it in VScode SAS extension.


%global home pdffref txtfref;

%*- determine a home output folder -*;
%if %sysfunc(symexist(HOME)) %then %do;
   %let home = %sysfunc(sysget(HOME));
%end;
%if %length(%superq(home))=0 or %sysfunc(fileexist(%superq(home)))=0 and %sysfunc(symexist(HOMEPATH)) %then %do;
   %let home = %sysfunc(sysget(HOMEPATH));
%end;
%if %length(%superq(home))=0 or %sysfunc(fileexist(%superq(home)))=0 and %sysfunc(symexist(USERPROFILE)) %then %do;
   %let home = %sysfunc(sysget(USERPROFILE));
%end;
%if %length(%superq(home))=0 or %sysfunc(fileexist(%superq(home)))=0 %then %do;
   %let home = %sysfunc(pathname(sasuser));
%end;

%put &=home;

%*- generate txt and pdf files in that folder -*;
%let pdffref = ;
%let txtfref = ;
%let rc = %sysfunc(filename(pdffref, &home./sample_males.pdf));
%put &=rc &=pdffref : %sysfunc(pathname(&pdffref, F));
%let rc = %sysfunc(filename(txtfref, &home./sample_males.txt));
%put &=rc &=txtfref :  %sysfunc(pathname(&txtfref, F));

ods pdf file = &pdffref;
ods listing file = &txtfref;

title "Sample of Male students";
proc print data=sashelp.class;
   where sex="M";
run;
ods pdf close;
ods listing close;

%let pdffref = ;
%let txtfref = ;
%let rc = %sysfunc(filename(pdffref, &home./sample_females.pdf));
%let rc = %sysfunc(filename(txtfref, &home./sample_females.txt));

ods pdf file = &pdffref;
ods listing file = &txtfref;

title "Sample of Female students";
proc print data=sashelp.class;
   where sex="F";
run;

ods pdf close;
ods listing close;

%*- generate ods html5 (default destination) output with links to generated files (not working in VScode 'Result' view) -*;

title "External files created";
proc sql print;
   select distinct xpath, xengine, cats('<a href="file:///', tranwrd(cats(xpath), ' ', '%20'),'" >link</a>') as link 
      from sashelp.vextfl
      where xengine not in ('TEMP') and scan(xpath, -1, '.') in ('txt' 'pdf' 'html' 'htm')
      order by xpath
      ;
quit;

*- create links in VScode output pane to the same files (these should be working) -*;
data _null_;
   set sashelp.vextfl;
   where xengine not in ('TEMP') and scan(xpath, -1, '.') in ('txt' 'pdf' 'html' 'htm');
   xpath = cats('<a href="file:///', tranwrd(cats(xpath), ' ', '%20'),'" >link</a>');
   put xpath;
run;

The Result looks like this: image Clicking the hyperlinks in column 'link' of the bottom output displayed in VScode has no effect. But when I open the same html file in a browser, clicking on any of the links opens the corresponding target file. (Note: the link to the html file points to itself, but can be shown by right click -> open link in new tab)

scnwwu commented 11 months ago

Currently, if you run it in SAS Notebook, the link can be opened within VS Code.

jbodart-argenx commented 11 months ago

Thanks, using SAS Notebook might be a workaround, but:

snlwih commented 4 days ago

When running SAS code that prints a column in a table containing HTML anchors I see the following behaviour in SAS Studio (SAS Viya):

  1. HTML anchors containing href='file:///...' do not seem to work.
    • Using "Open link in new tab" results in a generated URL of "about:blank#blocked"
    • Using "Copy link address" and then manually pasting it in the address-bar of another tab in the browser works absolutely fine.
      1. HTML anchors containing href='https://some.website.com...' seem to work fine. They open a new tab in the browser

When using the same SAS code in a .sas file opened in the SAS Extension and using a Viya connection (REST) I see same/similar behaviour.

When pasting the SAS code in a cell in a SAS notebook, both link types work and open results tab with the contents of the files on the local file system as long as the link points to a file. When the link points to a folder VSCode shows a warning panel with an "Open Folder" button.

Have some extremely simple SAS code attached. (had to add a .txt extension as it didn't allow me to upload a .sas file as an attachment) SAS-ODS-output-containing-HTML-Anchor-tag.sas.txt