[dlang.org] getting the redesign wrapped up

Adam D. Ruppe via Digitalmars-d digitalmars-d at puremagic.com
Mon Jan 11 17:48:34 PST 2016


On Tuesday, 12 January 2016 at 01:02:44 UTC, Martin Nowak wrote:
> I could use some help on the html processing though.
> Wasn't there a binding for an html parser or does someone know 
> a suitable tool?

My dom.d in loose mode is able to read ddoc's output. Here's a 
skeleton program you can use to get started:

---

import arsd.dom;

import std.file;
import std.stdio;

string hyphenateText(string input) {
         return input; // FIXME: implement algorithm here
}

void doHyphenation(Element element) {
         if(element.hasClass("donthyphenate"))
                 return;
         if(element.tagName == "script")
                 return;
         // you might filter other things too

         if(auto tn = cast(TextNode) element) {
                 tn.contents = hyphenateText(tn.contents);
         } else {
                 foreach(child; element.childNodes)
                         doHyphenation(child);
         }
}

void main() {
         auto document = new Document();
         document.enableAddingSpecialTagsToDom();
         // FIXME: pass a different html filename here
         document.parseUtf8(readText("intro.html"), false, false);

         doHyphenation(document.mainBody);

         writeln(document);
}

---



dom.d is available here:

https://github.com/adamdruppe/arsd

just download the single file, no need for anything else, it has 
no dependencies

also available on dub:

http://code.dlang.org/packages/arsd-official%3Adom/~master


More information about the Digitalmars-d mailing list