简体   繁体   中英

Click on text file and point to a specific line number

  • 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?

    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, eg:

    <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.

    The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

     
    粤ICP备18138465号  © 2020-2024 STACKOOM.COM