Trouble in converting PCRE Regex to sed - html

I'm running into trouble on how to use a working PCRE regex in sed. I found a related topic, but unfortunately it's not working for me (I'm working on Linux not MacOS X if that should be necessary information).
I have some HTML code of which I need a special part - however not between the same tags. The regex I have is working according to some regex testing sites (like regex101 or regexr.com), however, when trying to use it on sed, it shows me the whole file instead of the wanted part.
My regex is:
/((<div id="main-content" class="wiki-content">)([\w\d\s\S]*))(<\/rdf:RDF>\n-->)/g
It grabs a part starting with the specific div and collects everything including the following RDF part.
The text I'm working with looks (with the interesting part - the rest around I cut due to length and also this part only appears once the file) as follows (inlcuding the gaps):
[...]
a href="#page-metadata-start" class="assistive">Go to start of metadata</a>
<div id="page-metadata-end" class="assistive"></div>
<div id="main-content" class="wiki-content">
<p><br/></p><p><br/></p><div class="panel conf-macro output-block" data-hasbody="true" data-macro-name="panel" style="border-color: #004237;border-width: 1px;"><div class="panelHeader" style="border-bottom-width: 1px;border-bottom-color: #004237;background-color: #004237;color: white;"><b>Inhalt</b></div><div class="panelContent">
<p> </p><div class="toc-macro client-side-toc-macro conf-macro output-block" data-hasbody="false" data-headerelements="H1,H2,H3,H4,H5,H6,H7" data-macro-name="toc"> </div><p> </p>
</div></div><h1 id="id-01-Dokumentation-1EinstiegindiePlanung">1 Einstieg in die Planung</h1><p><br/></p><h2 id="id-01-Dokumentation-1.1Startseite">1.1 Startseite</h2><p>Nach der Anmeldung im System findet sich der User auf der Startseite wieder. Von hier aus gelangt er zur "Planning Map".</p><p>Durch das Umschalten der Company auf die Counter Company kann der Planer die zuvor eingetragenen Werte kontrollieren. Diese erscheinen nach dem Umschalten in der zweiten<br/>Tabelle als negativer Wert auf dem gemappten IC Account.</p><p><br/></p><div class="table-wrap"><table class="wrapped confluenceTable"><colgroup><col/><col/><col/></colgroup><tbody><tr><th class="confluenceTh">Button</th><th class="confluenceTh">Aktion</th><th class="confluenceTh">Beschreibung</th></tr><tr><p>Alle Eintragungen werden auf der untersten Ebene (weißer Hintergrund) ausgeführt. Monate, die nicht mehr beplant werden können sind farblich hinterlegt. Ebenfalls farblich hinterlegt sind<br/>die Accounts, die hier nicht beplant werden können (IC / Capex und Rule belegte Accounts).</p><p><br/></p><div class="table-wrap"><table class="wrapped confluenceTable"><colgroup><col/><col/><col/></colgroup><tbody><tr><th class="confluenceTh">Button</th><th class="confluenceTh">Aktion</th><th class="confluenceTh">Beschreibung</th></tr><tr><td colspan="1" class="confluenceTd">Back</td><td colspan="1" class="confluenceTd">Sheet Wechsel</td><td colspan="1" class="confluenceTd">Zurück zum Sheet Planning Map</td></tr><tr><td colspan="1" class="confluenceTd">Refresh</td><td colspan="1" class="confluenceTd">Prozess ausführen</td><td colspan="1" class="confluenceTd">Sheet wird nochmals neu aufgebaut</td></tr></tbody></table></div>
</div>
<!--
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
<rdf:Description
rdf:about="https://confluence.example.org/confluence/display/KUN/01+-+Dokumentation"
dc:identifier="https://confluence.example.org/confluence/display/KUN/01+-+Dokumentation"
dc:title="01 - Dokumentation"
trackback:ping="https://confluence.example.org/confluence/rpc/trackback/47022143"/>
</rdf:RDF>
-->
[...]
So when I try this regex on the mentioned test websites, it marks the part I need (between <div id="main-content" class="wiki-content"> and </rdf:RDF>\n-->).
But when using sed -r '/((<div id="main-content" class="wiki-content">)([\w\d\s\S]*))(<\/rdf:RDF>\n-->)/g' testfile.txt it shows me the complete file content instead only the part I'm looking for (sed -E... produces the same).
I can't work out, where my problem is, so any help would be very much appreciated. Also, I'm not a professional regex user...

I'm not sure about how it will work in your case, as I need probably some more data, but this one could work for you:
sed -ne '/<div id="main-content" class="wiki-content">/,/-->/{p}' file.html

Related

VS Code - How to continue on the next line?

everytime when I press enter to continue in the next line, VS Code jumps backs on the last line. I tried to put <br> at the end of the last line, but as you can see on the screenshot, that also doesn't help. I guess I have to change something within the settings of VS Code, but I didn't find anything.
Here and image
Here the whole code
Anybody an idea what I can do?
This is not an error. I didn't see the code that time as it was not opening sorry.
Just create a new p tag as And between it put br tag
This is not an error. you are using it wrongly.
<p>Hi und Willkommen auf SAWÖ.at!</p>
<br>
<p> Da du hier gelandet bist, hast du vermutlich dasselbe Problem, das wir einmal hatten: Du willst selbstständig als Webesigner und/
oder Developer arbeiten, weißt jedoch nicht, wie du im bürokratischen
Österreichden formellen Teil hinbekommst. Und du bist wahrscheinlich auch verwirrt, weil es da so viele verschiedene Fachbegriffe gibt wie zB Freiberufler, freie Berufe, Freelancer, Gewerbe usw... Keine Angst, jetzt ist Schluss mit dem Chaos! Wir erklärendir Step bei Step die wichtigsten Dinge, versprochen!</p>

Which is the proper or best way to use i18n with many html tags on rails?

I have a code like that needs to be added to i18n, and I was wondering which would be the best/safest way to do it, For now I put it as is on i18n and called it on ruby code with a variable and html_safe, but I dont know if it implies any security danger, I also thought of passing the html tags as parameters of those i18n variables
<p>Através dos princípios da<strong> economia colaborativa </strong> e do <strong>
<span id="yellow">poder da tecnologia</span></strong> nosso modelo de negócio
alia a <strong> <span id="green"> expertise do executive search </span></strong>
<strong><span id="red">, a </span></strong>importância das relações humanas <strong> e o<span id="blue">alcance das redes</span>
You might want to have localized snippets for the whole thing instead (Rails Guides: Localized views):
spanish version in own file
# marketing.es.erb
<p>Através dos princípios da<strong> economia colaborativa </strong> e do <strong>
<span id="yellow">poder da tecnologia</span></strong> nosso modelo de negócio
alia a <strong> <span id="green"> expertise do executive search </span></strong>
<strong><span id="red">, a </span></strong>importância das relações humanas <strong> e o<span id="blue">alcance das redes</span>
and then the english one
# marketing.en.erb
<p>Something<strong> in english</strong>... <strong>
<span id="yellow">... </span></strong>
And automatically include the correct partial
(other content)
<%= render :marketing %>

How to translate Trac custom content added with site.html?

We have customized our Trac instance to display additional content to the newticket page, with the following site.html file (as explained in documentation):
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:py="http://genshi.edgewall.org/"
py:strip="">
<form py:match="div[#id='content' and #class='ticket']/form[#action='/newticket#ticket']" py:attrs="select('#*')">
<div class="warning">
<p>You are about to create a new JOSM ticket.
</p>
<p>Please make sure to always use this link in About Dialog (Shift-F1) to come here:</p>
<img src="raw-attachment/wiki/Help/Action/About/bugreport_small.png" alt="Bug report link in About dialog" height="53" width="361" />
<p>Clicking on this link prefills the bug report with useful information for us (Status Report).
</p>
<p>In any case, don't be shy :) Please let us a way to contact you if needed (either by creating an account or entering your e-mail address below (it won't be publicly visible but will allow us to reach you, and you will be notified about ticket progress).
</p>
</div>
${select('*')}
</form>
</html>
I don't see anything in the documentation about translation. How can we translate this text now?
Unfortunately this is not easy until something like the proposal for custom labels has been realized.
Currently it requires adding your additional msgids to Trac core PO files and recompiling and installing that custom Trac version - quite ugly and not remotely as modifiable as the template.
Providing custom translations within a plugin would not be effective, because plugin translations would reside in a translation domain, that is not evaluated for Trac core templates like the (new) ticket page.
I have finally come up with a small JavaScript solution.
It's simple when you only need a few languages with a text that doesn't change:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:py="http://genshi.edgewall.org/"
py:strip="">
<form py:match="div[#id='content' and #class='ticket']/form[#action='/newticket#ticket']" py:attrs="select('#*')">
<div class="warning">
<table style="border:0; border-collapse:separate; border-spacing:0 10px" class="wiki">
<tr><td style="background:#FFFC75; border:1px solid #ccc; border-right:0" valign="top">
<p id="josm_warning_01">You are about to create a new JOSM ticket.
</p>
<p id="josm_warning_02">Please make sure to always use Help/Report bug or this link in About Dialog (Shift-F1) to come here:</p>
<img src="raw-attachment/wiki/Help/Action/ReportBug/reportbug.png" alt="Bug report menu entry" height="84" width="207" />
<img src="raw-attachment/wiki/Help/Action/About/bugreport_small.png" alt="Bug report link in About dialog" height="53" width="361" />
</td></tr>
</table>
</div>
<script type="text/javascript">
if (navigator.language.indexOf('fr') == 0) {
document.getElementById("josm_warning_01").innerHTML = 'Vous êtes sur le point de créer un nouveau ticket JOSM.';
document.getElementById("josm_warning_02").innerHTML = 'S\'il vous plaît, assurez-vous de toujours utiliser Aide/Rapporter un bug ou ce lien dans la fenêtre À propos (Shift-F1) pour venir ici:';
} else if (navigator.language.indexOf('de') == 0) {
document.getElementById("josm_warning_01").innerHTML = 'Sie sind dabei, ein neues JOSM-Ticket zu erstellen.';
document.getElementById("josm_warning_02").innerHTML = 'Bitte nutzen Sie immer Hilfe → Fehler melden oder diesen Link im "Über JOSM..."-Fenster, um hierher zu gelangen:';
}
</script>
${select('*')}
</form>
</html>

Can't delete the space and backgroundcolor in table

I'm trying to build a newsletter with tables. div boxes aren't working to 100 % percent in every mail client.
As you can see, here
is this what I prepared in Photoshop and I have some problems with the tables. How can I delete this space between the two images down and change the background color from the text ( in the middle of the pictures and the buttons ) to grey, if I'm giving it a new td ,then is nothing working. It should look like the pic I uploaded. would be very nice if you can help me out.
<td width="29"> </td>
<td width="291" valign="top">
<a target="_blank" href="#">
<img src="images/angebotbild1.jpg" style="display: block;" border="0" width="355" height="150"></a>
<div style="margin-top: 3px;"></div>
<font color="#778da7" face="Trebuchet, Arial, Verdana, Helvetica, sans-serif" size="2" style="font-size: 12px">
Wie gemacht für alle, die den etwas
anderen Sommer
erleben wollen: Diese Reise führt Sie zu den großen
Metropolen und kleinen Städten des Baltikums. Jede
davon wird Sie durch den Kontrast zwischen prunkvoller
Architektur in den historischen Stadtzentren und der
nachhaltigen in den neuen Arealen Bauweise faszinieren.
Jeder Ort erzählt hier seine eigene, spannende
Geschichte. Lassen Sie sich verzaubern.
</font>
<img border="0" src="images/button.jpg" width="335" height="60" style="display:block;" border="0" />
</td>
</tr>
</table>
jsfiddle
here is the complete code,
Change your style inside bottom a link from float:right to float:left
change img tag inside a link, and make the image width 355 instead of 335.
The bottom button is an image (button.jpg), you can only change it's background color by edit with photoshop, and don't forget to change its image size to 355px.
Next time please put your files in public area, we can not see what does it look right now and can only guess how it suppose to look like.
Since the OP answer seems to be covered already, here is an alternative output option for you for future use(s):
Rather than creating the tables yourself and manually working with the code, you can allow Photoshop to automate the process within the save for web option. This alternative allows you to save images as well as text so the text area you have in that section would simply be a slice type of No Image (Right Click with slice tool on a slice > Edit Slice Options). Now simply add the text right there within that selected slice.
When you save for web it will output a table with the images and text aligned properly. You can then clean up the text within the table with css to suit your needs.

Replace bbcode to HTML in PHP

For several weeks I learn a lot from this site.
Now I search for hours for a tip but can not find it and I decided to post a question.
I want an image from bbcode filter and a style as I add, but I do not know how to do this.
Who can tell me how can in chage this:
[attach=news-ZmAk6khfk0.jpg align=left title=title width=500 height=500 rel=rel]<br />
De formatie van Rutten creëerde in het eerste bedrijf geen uitgespeelde kansen. Vanuit de tweede lijn vielen een paar schoten te noteren. Dries Mertens en Tim Matavz hadden het vizier niet op scherp staan.
To this:
<img src=news-ZmAk6khfk0.jpg align=left title=title width=500 height=500 border=0 class=footblocks/>
Take a look at the PEAR package BBCode Parser 2. It's an excellent tool that will save you hours.
Edit: PECL also has one similar to the PEAR version: BBCode Parser