2
  • I am building a small application where a perl program would read/process the simulation output and generate a html file for further analyzing the data.

  • So far, I was able to present the data in the html file. Under some sections, the data would be like this:

    Files for Scenario A

/username/directory/file.txt,35

I wanted the user to click on this the file should open and point to line 35. I tried below, and on click, the file opens but the line number is not effective.

  • /home/user/file.v,35
  • Please let me know if there is a way to do this?

    • It's not quite clear what you're asking. Do you want an HTML link that will scroll you to a specific line line of HTML in a browser? A way to open a file in an editor and scroll directly to a line of HTML? Something else? – ldtcoop Jul 10 '19 at 23:10
    • html file would have the filename and line number info. Once user clicks on it, I want the file to be opened in browser, and point to the line number. – Pavan Kumar Jul 11 '19 at 06:54
    • So you want to click on a URL in your editor and have that link open in your browser? – ldtcoop Jul 11 '19 at 16:16
    • Sorry if I was not clear. The html file will be in my unix current working directory. User would open the html file with browser lets say Firefox. Once html file is loaded, user would see "absolute path to the file and interested line number". I want to see if there is a way for user to click on the file path, and then the file would open in editor, so that user can review the line and make code changes if required. – Pavan Kumar Jul 11 '19 at 18:56

    1 Answers1

    2

    First the bad news: It doesn't look like there is a way to click an HTML link to open a specific line number in a .txt file in an editor.

    However, there is a way to do this if your results can be HTML files instead of .txt files. In that case, you could put each line of your results (let's call the file results.html in its own tag each with its line number as its id, e.g.:

    <p id="1">Result 1</p>
    <p id="2">Result 2</p>
    <p id="3">Result 3</p>
    

    Then, in your main HTML file with the links, you could link to each id in the file like this:

    <a href="/username/directory/results.html#1">Link to Line 1</a>
    <a href="/username/directory/results.html#2">Link to Line 2</a>
    <a href="/username/directory/results.html#3">Link to Line 3</a>
    

    The downside of this is that you can't edit the results like you can in an editor. If editing the results is a must, you could add the contenteditable flag to the results to make them editable in the browser. Then, to approximate saving, you could write a javascript function to either copy the edited text to their clipboard, or figure out a way to download it (this SO question looks like a promising resource for that.)

    I know that this probably wasn't the answer that you were hoping for, but hopefully it'll help.

    ldtcoop
    • 680
    • 4
    • 14