简体   繁体   English

单击文本文件并指向特定的行号

[英]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. 我正在构建一个小型应用程序,在该应用程序中,perl程序将读取/处理模拟输出并生成用于进一步分析数据的html文件。

  • So far, I was able to present the data in the html file. 到目前为止,我已经能够在html文件中显示数据。 Under some sections, the data would be like this: 在某些部分下,数据将如下所示:

    Files for Scenario A 方案A的文件

/username/directory/file.txt,35 /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. 我希望用户单击该文件应打开并指向第35行。我在下面尝试过,单击该文件即会打开,但行号无效。

  • /home/user/file.v,35 /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. 首先是个坏消息:看起来没有一种方法可以单击HTML链接来在编辑器中的.txt文件中打开特定的行号。

    However, there is a way to do this if your results can be HTML files instead of .txt files. 但是,如果您的结果可以是HTML文件而不是.txt文件,则有一种方法可以执行此操作。 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: 在这种情况下,您可以将结果的每一行放置(让我们将文件results.html放在其自己的标记中,每个标记results.html其行号作为ID,例如:

    <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: 然后,在带有链接的主HTML文件中,您可以这样链接到文件中的每个ID:

    <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. 如果必须编辑结果,则可以在结果中添加contenteditable标志 ,以使其在浏览器中可编辑。 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.) 然后,为了进行近似保存,您可以编写一个javascript函数, 将编辑后的文本复制到其剪贴板中 ,或找出一种下载方法( 此问题看起来像是一个有前途的资源)。

    I know that this probably wasn't the answer that you were hoping for, but hopefully it'll help. 我知道这可能不是您想要的答案,但是希望它会有所帮助。

    声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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