SHPAML still alive?

47 views
Skip to first unread message

zak

unread,
Jul 14, 2012, 2:50:56 AM7/14/12
to shp...@googlegroups.com
Is SHPAML still being actively developed? No one seems to have posted since January so I'm just checking up on the project.

James Robert

unread,
Jul 14, 2012, 1:04:48 PM7/14/12
to shp...@googlegroups.com
Yup, I think

Andy Mikhaylenko

unread,
Jul 15, 2012, 8:46:07 AM7/15/12
to shp...@googlegroups.com
> Is SHPAML still being actively developed? No one seems to have posted since January so I'm just checking up on the project.

Updates are required if: a) the task is not solved, b) the task has changed, c) a bug is found, or d) the underlying technologies have changed so that existing codebase needs to be changed, too.

I guess none of the above has recently taken place.

Andy

James Robert

unread,
Jul 15, 2012, 10:19:18 AM7/15/12
to shp...@googlegroups.com
Yes the project is still alive (pardon my last response, I sent it before finishing by accident on my phone)

I think it's reached a point of stability where we're all just getting things done and not worrying too much about shpaml now that it's become just another tool in the toolbox.

I've used it on numerous projects over the last few years. and continue to do so.

I think mailing list activity has also been reduced now that we've updated and improved the documentation (shpaml.com)

That said, if you find a bug or have any suggestions, please send a message for sure!

James

Steve Howell

unread,
Jul 15, 2012, 10:53:03 AM7/15/12
to shp...@googlegroups.com
That's more or less the case.  After the initial development, there were pretty few bug reports, and there's not much technology underneath the covers except for Python itself.  It's a pretty simple project with few dependencies.


From: Andy Mikhaylenko <neit...@gmail.com>
To: shp...@googlegroups.com
Sent: Sunday, July 15, 2012 5:46 AM
Subject: Re: SHPAML still alive?

zak

unread,
Sep 3, 2012, 11:29:55 AM9/3/12
to shp...@googlegroups.com, Steve Howell
I've got a suggestion...I think what shpaml needs is a way to convert HTML back into shpaml. That would be hugely useful when working with a team of people who are all using the same codebase. That feature is currently missing and I think it'd be a great addition to the project.

Niklas Hambüchen

unread,
Sep 3, 2012, 12:07:21 PM9/3/12
to shp...@googlegroups.com, Steve Howell, zak
Yes, I agree on that, and I remember somebody asking for that some time
ago.

It shouldn't be difficult as long as the HTML is somewhat well-formed.

James Robert

unread,
Sep 3, 2012, 12:55:46 PM9/3/12
to shp...@googlegroups.com
sounds great! does that mean you're going to build the first version? ;)

in all seriousness, it's an interesting idea, but one thing to consider:

- shpaml won't necessarily generate the same amount of whitespace as an arbitrary block of xml

this can affect things in subtle ways (like having a single space in a tag that would otherwise be empty, adding/removing a space between 2 tags that should (or shouldn't) have a space.

I guess what I'm saying is: It'd be nice to have that, but it's not as easy as it sounds to get the details right.

I'm definitely open to discussing it further though!

James

zak

unread,
Sep 3, 2012, 3:07:38 PM9/3/12
to shp...@googlegroups.com, jia...@gmail.com
It's really not worth discussing if we're all just going to pass around the responsibility of actually building the feature. I honestly would like to start building it right away, but I don't understand regex nearly well enough to begin, so it'll take me a while to learn.

Steve Howell

unread,
Sep 4, 2012, 3:40:50 PM9/4/12
to shp...@googlegroups.com
Shpaml's not exactly haml, but it's close enough that a tool like this can be helpful:



From: zak <zakd...@gmail.com>
To: shp...@googlegroups.com
Cc: jia...@gmail.com
Sent: Monday, September 3, 2012 12:07 PM

Subject: Re: SHPAML still alive?

Niklas Hambüchen

unread,
Sep 4, 2012, 4:46:12 PM9/4/12
to shp...@googlegroups.com, zak, jia...@gmail.com
You don't need regex for this. HTML -> SHPAML is easier than SHPAML -> HTML.

You just take an HTML-to-your-language-of-choice parser (probably a
forgiving one so that slightly malformed legacy HTML doesn't always
fail), and format the data structure that your HTML parser gives you in
SHPAML manner.

Niklas Hambüchen

unread,
Sep 4, 2012, 11:47:11 PM9/4/12
to shp...@googlegroups.com, zak, jia...@gmail.com
OK, I hacked the first bits of a prototype on this in the last hours.

It's progressing at good pace, but I probably don't have much time this
week; if I haven't posted anything about this within a month, ping me
please :)

PS:
First info: You have to expect the outcoming SHPAML being really
wellformed, e.g. it will put attr="value" even if you wrote attr=value
because usually parsers remove the information whether there were quotes
or not.

If somebody feels like helping a bit: I read that somewhere
(unfortunately don't remember where) that attributes can have multiple
values (and I do not mean attr="v1 v2" or attr=v1 attr=v2). Has anyone
got a clue about this?

Steve Howell

unread,
Sep 5, 2012, 12:14:21 AM9/5/12
to shp...@googlegroups.com
Hi Niklas,

I'm the original author of shpaml, and I'm excited that you're working on this.  I'll throw my two cents in.

First, I like your decision to output "well formed" shpaml, certainly for version one.  For me the most compelling feature of the language is the removal of end tags, and then almost everything else is gravy.  I also like the sugar for div tags, id parameters, and class parameters, all of which are shamelessly stolen from haml.   I actually pushed back on some features--including the removal of quotes from attributes--because I felt they went a little too far.  After trying them out, I was glad that folks pushed for them.  But, in creating a tool to help migrate people, I think a few extra quotes are pretty harmless, as long as they get the big win from nice indentation and less clutter related to div tags.

With regard to multiple attributes, I don't know whether they're specifically kosher in the html world, but you should be able to map them to shpaml with pretty little difficulty, and know that shpaml will round trip them.  For example, "> foo x=3 x=3" will map just fine to '<foo x="3" x="3" />'.

One of my goals with the translator was to keep it fairly dumb about html itself and fairly liberal about what it would translate.  My goal was to reduce visual clutter in the source document, but then I leave it to the programmer to make sure that the output produced by the translator worked within their goals.  And, of course, there are plenty of tools to help in that.  One workflow, for example, is to write in shpaml, then wire up your editor to automatically translate it, then integrate with a more full featured templating language, and then automatically validate the final HTML with a validator.  When you list all the steps, it sounds somewhat cumbersome, but it's all fairly easy to script.


From: Niklas Hambüchen <n...@deditus.de>
To: shp...@googlegroups.com
Cc: zak <zakd...@gmail.com>; jia...@gmail.com
Sent: Tuesday, September 4, 2012 8:47 PM

Subject: Re: SHPAML still alive?

Niklas Hambüchen

unread,
Sep 5, 2012, 11:13:29 AM9/5/12
to shp...@googlegroups.com, Steve Howell
Hey Steve,


On 05/09/12 05:14, Steve Howell wrote:
I'm the original author of shpaml, and I'm excited that you're working on this.
I know, since I've been using shpaml for some years now :)


First, I like your decision to output "well formed" shpaml, certainly for version one.  For me the most compelling feature of the language is the removal of end tags, and then almost everything else is gravy.  I also like the sugar for div tags, id parameters, and class parameters, all of which are shamelessly stolen from haml.   I actually pushed back on some features--including the removal of quotes from attributes--because I felt they went a little too far.  After trying them out, I was glad that folks pushed for them.  But, in creating a tool to help migrate people, I think a few extra quotes are pretty harmless, as long as they get the big win from nice indentation and less clutter related to div tags.
I fully agree.
I'm a big fan of #id, .class and the likes, but I'm also aware that they are for the HTML world and for XML, they are probably a burden.
Ideally I will add some flag that allows turning these features off.

One of my goals with the translator was to keep it fairly dumb about html itself and fairly liberal about what it would translate.  My goal was to reduce visual clutter in the source document, but then I leave it to the programmer to make sure that the output produced by the translator worked within their goals.  And, of course, there are plenty of tools to help in that.  One workflow, for example, is to write in shpaml, then wire up your editor to automatically translate it, then integrate with a more full featured templating language, and then automatically validate the final HTML with a validator.  When you list all the steps, it sounds somewhat cumbersome, but it's all fairly easy to script.
Yes, shpaml not being a templating language itself is what makes it appealing.

Can you tell me if shpaml can deal with fully qualified XML namespacing stuff?

Niklas

Steve Howell

unread,
Sep 5, 2012, 11:17:57 AM9/5/12
to shp...@googlegroups.com
For XML translations, you always have the option to simply write XML itself, which shpaml will just pass through verbatim.  Do you have a specific example of XML that you're hoping to produce?


From: Niklas Hambüchen <n...@deditus.de>
To: shp...@googlegroups.com
Cc: Steve Howell <show...@yahoo.com>
Sent: Wednesday, September 5, 2012 8:13 AM

Subject: Re: SHPAML still alive?

Niklas Hambüchen

unread,
Sep 5, 2012, 11:21:15 AM9/5/12
to shp...@googlegroups.com, Steve Howell
I was just wondering if shpaml will compile

h:table
  h:tr
    h:td | Apples
    h:td | Bananas

to

<h:table>
  <h:tr>
    <h:td>Apples</h:td>
    <h:td>Bananas</h:td>
  </h:tr>
</h:table>

I would guess yes, as it probably just treats "h:table" as the tag string, right?

Steve Howell

unread,
Sep 5, 2012, 11:49:06 AM9/5/12
to shp...@googlegroups.com
That's correct.


Enter your code into the text window and then hit the "Convert!" button.


From: Niklas Hambüchen <n...@deditus.de>
To: shp...@googlegroups.com
Cc: Steve Howell <show...@yahoo.com>
Sent: Wednesday, September 5, 2012 8:21 AM

Niklas Hambüchen

unread,
Sep 6, 2012, 12:03:56 AM9/6/12
to shp...@googlegroups.com, Steve Howell
OK, preliminary version is here (accepting HTML via POST):

curl -F "html=</path/to/your/file.html" http://shpaml.nh2.me/unshpaml

It's not tested properly and doesn't do class -> . / id -> # rewriting yet.
Message has been deleted

zak

unread,
Sep 13, 2012, 5:25:29 AM9/13/12
to shp...@googlegroups.com, Steve Howell
I'm getting a bad gateway error on your link.

Niklas Hambüchen

unread,
Sep 13, 2012, 11:31:51 AM9/13/12
to shp...@googlegroups.com, zak, Steve Howell
Yep, I implemented #id, .class, and div-by-default and haven't restarted it properly.

It's up again.

Niklas Hambüchen

unread,
Sep 13, 2012, 11:43:03 AM9/13/12
to shp...@googlegroups.com, zak, Steve Howell
By the way:

The thing is in no way done yet, but the basic translation works.

Still, if you experience a crash/error or similar, please let me know here.

timothy crosley

unread,
Sep 20, 2012, 9:04:17 PM9/20/12
to shp...@googlegroups.com, zak, Steve Howell
Hi Everyone,

I just open sourced a  a simple html2sphaml parser I wrote: it's available on git up and by doing a 
   pip install html2sphaml
   -or-
   easy_install sphaml

It produces output that includes all basic sphaml syntaxt features: also since its based on the cleanHtml parser the code is super minimal:

#! /usr/bin/python

import sys
import codecs
from WebElements import Base
from WebElements.Parser import WebElementTree
from WebElements.StringUtils import interpretAsString

Base.INDENTATION = " "

class ShpamlTree(WebElementTree):
    def endTag(self):
        return ""

    def startTag(self):
        if not self.tagName:
            return u''

        self.attributes['name'] = self.fullName()
        self.attributes['style'] = self.style

        startTag = self.tagName
        ID = self.fullId()
        if ID:
            startTag += "#" + ID
        for cssClass in self.classes:
            startTag += "." + cssClass
        startTag += " "

        for key, value in self.attributes.iteritems():
            value = interpretAsString(value)
            if value:
                if value == '<BLANK>':
                    value = ""

                if value == '<EMPTY>':
                    startTag += key + " "
                else:
                    if not " " in value and not '"' in value:
                        startTag += key + '=' + value + ' '
                    else:
                        startTag += key + '="' + value.replace('"', '&quot;') + '" '

        if self.tagSelfCloses:
            startTag = '> ' + startTag
        elif not self.childElements:
            startTag = startTag[:-1] + "\n%(indent)s::comment\n%(indent)s%(indent)sempty " % {"indent":Base.INDENTATION}
        elif len(self.childElements) == 1 and type(self.childElements[0]) == Base.TextNode:
            textNode = self.childElements[0]
            if not "\n" in textNode.text():
                startTag += "| " + textNode.text() + " "
                self.removeChild(textNode)

        return startTag[:-1]

def parseFile(fileName, saveChanges=True):
    with open(fileName, 'r') as fileObj:
        text = fileObj.read().decode('utf8')
        tree = ShpamlTree(text)

        print tree.toHtml(formatted=True)

    return tree

def printDoc():
    print "Html2Shpaml 0.1 is a forgiving html to shpaml converter"
    print "usage: Html2Shpaml (filename)"
    print ""
    print "Directly prints Shpaml syntaxt - with can then be redirected into a file"

def main(argv):
    if len(argv) < 2:
        printDoc()
    elif len(argv) == 2:
        parseFile(argv[1])
    else:
        printDoc()

if __name__ == '__main__':
    main(sys.argv)

Let me know what you think, Thanks!

Timothy
Reply all
Reply to author
Forward
0 new messages