Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>On first thought you might try using the unix find and sed commands. However, doing so would require strong knowledge of regex and likely would end up being a lot more than a simple one-liner. Due to the fact that you are not simply replacing one known string and need to avoid replacing spaces outside of the filenames I would recommend to do this by writing a script using an xml parser.</p> <p>Here's the basic outline of what you would need to do if you were to write such a script in Python:</p> <p>1) Import the <a href="http://docs.python.org/2/library/os.html" rel="nofollow">OS</a> and <a href="http://docs.python.org/2/library/xml.etree.elementtree.html" rel="nofollow">ElementTree lib</a>: <code>import os</code> and <code>from optparse import OptionParser import xml.etree.ElementTree as ET</code><br> 2) Get the list of HTML files you would like to modify using Python's "<a href="http://docs.python.org/2/library/os.html" rel="nofollow">listdir</a>" or "<a href="http://docs.python.org/2/library/glob.html" rel="nofollow">glob</a>". 3) For each file get all <code>img</code> or <code>a</code> tags depending on which tags contain the <code>href</code> attributes which need to be changed. For example, you can get all <code>img</code> tags in a file like this:</p> <pre><code>file = ET.parse(filename) doc = file.getroot() imgs = doc.findall('.//img') </code></pre> <p>4) And finally, for each <code>img</code> or <code>a</code> tag, replace all spaces with underscores in the tags <code>href</code> attribute.</p> <p>I hope this helps. Let me know if I've misunderstood your question. Additionally, it might be possible to solve this using the tool you mentioned or a similar one, although I find it unlikely and it will likely require a fair amount of regex.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload