Message Boards Message Boards

1
|
2132 Views
|
1 Reply
|
4 Total Likes
View groups...
Share
Share this post:
GROUPS:

Convert simple HTML to notebook cells (looking for implementations)

Posted 11 years ago
I was wondering, has anyone written tools to convert simple HTML to notebook cells?  I'm only interested in the simplest tags of course, such as b, i, strong, em, a, hr, br, p, h1, h2, etc.  I do not need tables, complex layouts, div or span (possibly with CSS), img, etc.  Just the simplest things.

I can imagine several ways to tackle the problem, but it would take some amount of time implement this right and debug it.  Also one of the difficulties is that boxes don't seem to nest so easily.  Think of a situatio such as
text <strong>bold <em>bold and italic</em> end</strong> plain

So is there anyone here who has already tackled the problem?
POSTED BY: Szabolcs Horvát
I have been using this programming pattern lately: (use Import instead if Import String if needed...)
XMLdata = ImportString["......",{"HTML","XMLObject"}];

body = Cases[ XMLdata ,XMLElement["body",_,content_]:>content,Infinity][[1]];

Row[body //. {XMLElement["strong",cellOptions_,content_]:>Style[Row[content],Bold],
XMLElement["em",cellOptions_,content_]:>Style[Row[content],Italic]}]

I hope this helps,

Luc
POSTED BY: Luc Barthelet
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract