Looking for HTML / CSS Ada decoder / encoder

I’m looking for a library which can parse HTML / CSS text file into an Ada data structure and can create an HTML/ CSS text file from this Ada data structure.

Any idea which may help developing an Ada Web Editor is welcome :slight_smile:

Thanks, Pascal.

Hi Pascal,

Unfortunatly, I think that the closer lib will be XMLAda for HTML, and nothing for CSS.

I am not sure that there is such lib in Ada, but it could be welcome.

Maybe @stcarrez have some hints? :thinking:

Quentin

There was a general parsing library, OpenToken by Sparre Anderson (IIRC), and there was a paper/article on how it could be used to embed in itself so that the two languages of HTML and attributes (esp the Style attribute, IIRC) could be handled. — Mr. Sparre died and the project was taken over, reworked/redone and renamed as FastToken, though I cannot remember by whom at the moment.

Another project to look into is Wasabee, which aims to be a web-browser.

It would be quite easy with Simple Components. The problem is a reasonable syntax description (where?) and the level of validation you want, e.g. unknown selectors etc. Web tends to be permissible.

You can take a look at the JSON parser implementation.

To parse CSS, I’ve created the following project some time ago:

It parses CSS and provides some Ada API to access the CSS according to CSS Object Model (CSSOM) API.

To parse HTML, XML/Ada is not appropriate at all because the parser is strict and barks at the first error. Most HTML content don’t close several tags and using XML/Ada will fail. However, I’ve written an HTML parser in the Ada Wiki project and it allows to parse HTML with syntax errors (most HTML are incorrectly formed).

The parser is in ada-wiki/src/wiki-html_parser.ads at c0bf8bf734441f9183ac612d0f712c1c04c386b8 · stcarrez/ada-wiki · GitHub and ada-wiki/src/wiki-html_parser.adb at c0bf8bf734441f9183ac612d0f712c1c04c386b8 · stcarrez/ada-wiki · GitHub but this is an internal package for the library.

Enjoy

2 Likes