Message Boards Message Boards

1 Reply
4 Total Likes
View groups...
Share this post:

Convert simple HTML to notebook cells (looking for implementations)

Posted 12 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],

I hope this helps,

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

Group Abstract Group Abstract