How to remove a div from the entire project? - html

I've got a project consisting of over 200 html files. There's a div repeated throughout most of these, looking like this:
<div class='foobar' id="abcdef123'></div>
I have found all uses of the class using the Find in Files function in Sublime Text 2 - now I want to remove them, i.e. completely delete any line containing that div (and its closing tag).
Is there an easy way to do it in Sublime Text 2?
EDIT: I have forgotten to mention that sometimes the div has additional classes and the ID is always different. How would I write a regexp to deal with that?

In Notepad++, open all 200 files and replace with the following regular expression.
<div class='foobar[^']*' id="[^']*"></div>
and replace it by nothing. I don't know Sublimetext2.

Related

Find Replace text FOO with Style "Heading 1" with <h1>Foo</h1>

I am trying to find an easy way to convert my Word documents to HTML without the awful save-as that is built in. These are structured documents (designed for our screen-reader (JAWS) users), and so they use Heading 1, 2, 3, 4 & the Table of Contents.
We plan to convert these to DAISY audiobooks (https://en.wikipedia.org/wiki/DAISY_Digital_Talking_Book ) , so we need pretty clean, but structured, HTML to convert.
I tried the find-replace, using Styles, but it would just replace anything in the text part of the search. I could convert it from any one style to another, but adding text in the box messed it up.
(I think I see that CSS for DAISY means that instead of just <h2> it will have to be <level2 class=='section' <h2> and closing tags), but that's step 2 after I handle this part.)
I just want to be able to find any text using Style 2 and add text to the start of that line saying "yep, here's some style 2" so that I can do the HTML/CSS stuff.
Thanks!
You can do that with a simple Find/Replace. For example, specify the Heading 1 Style for the Find parameter and use:
Replace = <h1>^&</h1>
For a macro you could incorporate that into, see: Convert a Word Range to a String with HTML tags in VBA

Replacing only first HTML tag on a page in RegEx

I would like to search for only the first occurrence of an HTML tag (and it's contents) and replace it for another. I want the search and replace to stop after it's found the first occurrence on a page.
For example, at the top of each page in a directory is:
<h3>This is my title</h3>
I want to search and replace the h3 tag with an h1 tag and leaving the contents of tag the same. So that the outputted result would be:
<h1>This is my title</h1>
The "this is my title" portion is different on each page. I will be using a Microsoft Server program on the server (called fnr.exe) that does search and replace and can handle regex.
I only want this to occur on first instance of each document that I am running this find and replace with.
I have tried
find: /h3>/g
replace: /h1>
That did not work. I'm not sure what else to do.
This is what my MS program looks like:
I've also tried to use another program which seems popular for windows called Notepad++. This is a screenshot of that attempt. It replaced all occurances. (For testing on this one, I tried to find only the first h2 tag and replace it with h1. It replaced all the h2 tags.
I don't have any MS programs so you're going to have to test this out on your own but I think this should do what you are after.
Search for
^([\s\S]*?)<h3>(.*?)</h3>
replace with
$1<h1>$2</h1>
Demo and explanation of regex, https://regex101.com/r/tB6rV2/2
Can you not just search for /h3>/g and replace with h1>

ruby tags for Sphinx/rst

I create HTML documents from a rst-formated text, with the help of Sphinx. I need to display some Japanese words with furiganas (=small characters above the words), something like that :
I'd like to produce HTML displaying furiganas thanks to the < ruby > tag.
I can't figure out how to get this result. I tried to:
insert raw HTML code with the .. raw:: html directive but it breaks my line into several paragraphs.
use the :superscript: directive but the text in furigana is written beside the text, not above.
use the :role: directive to create a link between the text and a CSS class of my own. But the :role: directive can only be applied to a segment of text, not to TWO segments as required by the furiganas (=text + text above it).
Any idea to help me ?
As long as I know, there's no simple way to get the expected result.
For a specific project, I choosed not to generate the furiganas with the help of Sphinx but to modify the .html files afterwards. See the add_ons/add_furiganas.py script and the result here. Yes, it's a quick-and-dirty trick :(

How to delete a similar fragment on several HTML files?

I'm converting a website to a PDF, but there are images in there and along all of them there is a text that when clicked gets you to image itself.
I think this would be the code responsible for showing that text, since I deleted it in one of the files and the text and link is not shown anymore.
<div class="v1"><a target="_self" href="images/graphics/1.jpg">[View full size image]</a></div>
The problem is that there are about 200 more HTML documents containing this similar text, only changing href.
Would there be any easy way to get rid of all this without having to go one by one? Maybe a regular expression for sed?
If the expression is always on one line and the only difference is in href, sed is a possible solution:
sed -e 's,<div class="v1"><a target="_self" href="[^"]*">\[View full size image\]</a></div>,,'
I used an alternative separator , so / does not have to be escaped in closing tags. The brackets in the links's text need to be escaped, though.
Yes, regular expressions are likely the easiest solution here. If it's simply a question of removing this line from all your files then I'd just open them up in an editor (Sublime Text 2 does this well) and perform a regex search and replace. The following search pattern will likely work:
<div class=\"v1\"><a target=\"_self\" href=\"[^"]+\">\[View full size image\]</a></div>

Regular Expression To Select An Entire Line That Contains a HTML Class

I'm using TextMate to edit a project that I'm doing(HTML files) and I have some <div> tags assigned with the class=navigation property, but I need to change this <div>'s for a new design that I'm planning, but they are much(about 47 results if I search for class=navigation).
So I need a regular expression to match the entire line that this property is found, but which is it?
I'm not a regex expert, but I would think that ^.*class=navigation.*$ would work.