I need to interpret text copied from emails. Currently, the users copy the text of the email and paste it into an HTML text area. I already have a 90% solution, but here is one case that is stumping me. The data is stored in a table in the email. Here is one row of that data, which could easily have 50 rows or more, in a similar format:
<tr>
<td valign=3D"top" style=3D"background:white;padding:0in 0in 0in 0in">
<p class=3D"MsoNormal"><span style=3D"color:black">WI</span><o:p></o:p></p>
</td>
<td valign=3D"top" style=3D"background:white;padding:0in 0in 0in 0in">
<p class=3D"MsoNormal"><span style=3D"color:black">BARABOO 53913</span><o:p></o:p></p>
</td>
<td valign=3D"top" style=3D"background:white;padding:0in 0in 0in 0in">
<p class=3D"MsoNormal"><span style=3D"color:black">8:00</span><o:p></o:p></p>
</td>
<td valign=3D"top" style=3D"background:white;padding:0in 0in 0in 0in">
<p class=3D"MsoNormal"><span style=3D"color:black">VAN</span><o:p></o:p></p>
</td>
<td valign=3D"top" style=3D"background:white;padding:0in 0in 0in 0in">
<p class=3D"MsoNormal"><span style=3D"color:black">WI</span><o:p></o:p></p>
</td>
<td valign=3D"top" style=3D"background:white;padding:0in 0in 0in 0in">
<p class=3D"MsoNormal"><span style=3D"color:black">8/29/2015</span><o:p></o:p></p>
</td>
</tr>
This is an example of the sort of things I have to accomodate, although I actually want to accomodate a lot more.
When the user pastes that row, it turns into this:
WI
BARABOO 53913
8:00
VAN
WI
8/29/2015
Keep in mind that I am receiving many rows, so they all get run together. The number, order, and format of the columns are completely inconsistent, sometimes even within the same document.
If I could get this, I can use my already existing code to parse it:
WI BARABOO 53913 8:00 VAN WI 8/29/2015
But I have pretty much nothing to work with. If I had the raw HTML, I could parse it safely (It is never displayed), but I can't get it. Does anyone know how I can get this as raw HTML or some other coherent format? I doubt if it matters, but in most cases, the source of the copy will be MS Outlook.
edit: the whole goal is to make this machine-parsable. I don't need help with the parsing, I have that covered. I just need something useful to parse.
You can get the pasted HTML maintained if you replace your text area with a "contentEditable" element, such as a <div>
. Try this for example, it will alert the html "source" you paste into it:
var paste = document.getElementById('paste');
paste.onpaste = function() { setTimeout(function() { alert(paste.innerHTML); }, 1); };
#paste {
width:200px;
height:60px;
border: 2px solid blue;
}
<div id="paste" contentEditable="true"></div>
It looks like the paste event, for Chrome and Firefox, may have a clipboardData
property of type DataTransfer. That has a getData
method that takes a content type, so you may be able to do this to check if the content is HTML:
textArea.addEventListener('paste', function (e) {
var html = e.clipboardData && e.clipboardData.getData('text/html');
if (html) {
// handle HTML table logic
}
});
Update:
Interestingly, IE has a beforepaste event which looks like it has a similar clipboardData
object, so maybe you can handle that browser using this technique.
I want to know how to execute some function when I close my browser... so the detail is I making website that going to sell items and the scenario is user login to my website and then they select some ...
I want to know how to execute some function when I close my browser... so the detail is I making website that going to sell items and the scenario is user login to my website and then they select some ...
I'm using bootstrap-select and everything is working fine,until options of my select tag are filled with data from php file. I have seen each post on this topic, but there is no answer. So here is an ...
I'm using bootstrap-select and everything is working fine,until options of my select tag are filled with data from php file. I have seen each post on this topic, but there is no answer. So here is an ...
I am having Collapse Panel in Bootstrap which is opening on a click on the title of the tab. I am trying to figure out to open using the hover of the mouse on the total width of the tab but I am not ...
I am having Collapse Panel in Bootstrap which is opening on a click on the title of the tab. I am trying to figure out to open using the hover of the mouse on the total width of the tab but I am not ...
I'm trying to move the dropdown that DataTables uses to determine how many rows to display. One way I thought of was to use jQuery's prependTo()/appendTo() functions, but it feels a bit too hack-y. I ...
I'm trying to move the dropdown that DataTables uses to determine how many rows to display. One way I thought of was to use jQuery's prependTo()/appendTo() functions, but it feels a bit too hack-y. I ...