emmetio / emmet

The essential toolkit for web-developers
http://emmet.io
MIT License
4.47k stars 519 forks source link

Convert HTML to abbreviation #93

Closed sergeche closed 5 years ago

sergeche commented 12 years ago

Create converter that will parse HTML block and convert it to expression (counter-“Expand Abbreviation”).

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

giannisg commented 11 years ago

i've send an email to the creator/s but i'm reposting here, just to upvote the request:


Hi,

First of all, thanks for your great work, you've done a super job, i really admire the result.

A thought i had about your program:

Is it possible to do 'reverse coding'?

ie take the

<div id="container">
    <div class="header"></div>
    <div class="body">
        <div class="title">Title</div>
        <div class="text">Text</div>
    </div>
    <div class="footer"></div>
</div>

and transform it to

container>.header+.body>.title{Title}+.text{Text}^.footer

??

Why? well, first of all, its easier to work with the second code, and then getting it back to normal. And, most importand, if possible to use a client side javascript - or even a server side code by volunteers to write, directly, in emmet code html pages.

Think of the impact that would make.

Well, its just a thought :)

Thanks again,

Have fun, Giannis, Athens, Greece, Europe, World.


So, thats that, upvoting the idea :+1: and hoping to see it done :)

lcb931023 commented 11 years ago

Have my upvote! Imagine if we can code the pages in HTML, translate it to emmet, and then write php code that includes the emmet code which gets expanded into HTML dynamically.

adam-lynch commented 11 years ago

:hand: My drive-by two cents:

@icb931023 First I thought what you said sounds cool but really, what would be the benefit? Your PHP will have to deal with a shorter string representing your HTML sure but it will then have to do more work with it.

I guess wouldn't have to worry about typos as much (like a missing slash in a closing tag for example) since all tags will be generated for you, but you're working with expanded HTML I'm assuming (albeit starting with the concise syntax) so I'm not sure if that's a strong argument for it either. Or maybe I'm wrong in assuming you wouldn't work entirely in the concise / collapsed syntax.

I want to want this. I just can't see a convincing use case. It's not as obviously beneficial as CSS preprocessing for example.

It would be a different story if browsers / templating engines understood the Emmet syntax. That would be interesting!

vabatta commented 11 years ago

Mmm, is quite intresting to create a JS library to traduce it ;)

adam-lynch commented 11 years ago

Here's a start from the perspective of the client; Emmet's Mustache. Feel free to contribute.

@vabatta :)

DanielRuf commented 10 years ago

any updates?

ericpeeters commented 10 years ago

Would love this too. I use a styleguide page where I store all my elements, to manage this I have a giant JSON file using Emmet strings to represent the elements and I've created a JavaScript tool to spit them out on a page. But right now I have to convert them all by hand to keep this file up to date everytime something new is created. Would love a way to convert HTML to an Emmet string.

metaColin commented 10 years ago

bump

I would love to be able to convert HTML into emmet. It would be super useful for making a cheat sheet of code blocks I frequently use.

Kcko commented 10 years ago

Any change?

sergeche commented 10 years ago

@Kcko no updates. This feature has the lowest priority for me

worc commented 10 years ago

it'd be a nice feature. hierarchies are easy to read in the emmet/zen syntax and sometimes it's helpful to have a kind of rough-draft in the abbreviation when iterating an HTML fragment design.

Milliw commented 9 years ago

Would be a great feature! Imagine creating multiple blocks with *n feature and finding out later you need to change the block. Now you have to delete the blocks and rewrite the emmet code again. Going back, modifying just a part and then let it generate again would be much faster!

sergeche commented 9 years ago

@MarcoWilli Emmet has enough methods to quickly modify existing code:

You should also note that if your repeated elements contain different content (as you described as “modify later”), the reverse abbreviation string won’t be that same as you used to generate code

stevehomer commented 9 years ago

Upvote from me. New to Emmet and it would be a fantastic way of improving my skills.

chermed commented 7 years ago

Really needed this feature, here is my case:

I receive some blocks like `

1 2 3 4

`

So I want to generate more records using the first one, so now I try to reproduce abbreviation to get record abbrevaition and then I type someething like (record...)*10

Thanks

sergeche commented 7 years ago

@chermed ...or you can simply copy-paste the code snippet. Please note that the code you’ve provided is a very simple yet very rare use case. In most cases you’ll end up with something like record>field[name=name1]{text1}+field[name=name2]{text2}+field[name=name3]{text3}+... abbreviation, which is not very useful

jchoi2x commented 7 years ago

We have a microservice that renders a Html string from a template + JSON object w/ data and responds to POST requests with the rendered html string. Having to send a huge HTML string in the HTTP response introduces a bottleneck our application flow.

If there is a way to take this rendered HTML and convert it to an Emmet abbreviation which is sent as response instead, it would remove our bottleneck as our response data size takes smaller number of bytes. The microservice that receives the response can then emmet-expand the abbreviation for rendering clientside.

sergeche commented 7 years ago

@kizzlebot it seems like a viable use case, but you should consider the following:

DanielRuf commented 7 years ago

@kizzlebot why not Messagepack and / or Apache Avro?

jchoi2x commented 7 years ago

@sergeche to be more specific, "render" may be wrong the word to use. we use the html to create a PDF document via a microservice that only receives html payloads and converts it to PDF. Therefore, if it would be possible to go from html to Emmet abbreviation, the client receiving the emmet abbreviation should be able to simply expand it using the current Emmet npm module. We wouldn't need a runtime to render because the html doesn't get rendered on the clientside ever. We just need a compact payload to pass around over the wire.

garyivy commented 6 years ago

I would like to build out sample sites and convert them back to emmet snippets to make presentation typing quicker (and it the process demo emmet).

DanielRuf commented 6 years ago

Probably possible using Hyperscript / JSX and the AST.

coldmow commented 6 years ago

This does have a lot of potential. The other day I was messing with HTML frameworks like Jade and HAML and I thought they were a great replacements for the unclear HTML syntax. But I couldn't get into them for my projects because it required just that extra installation and conversion. I always used Emmet which was almost as good (it only supports a little less and does not require installation). But today when I was building a site template, I decided to use indentation while writing in Emmet and I came up with this:

.navbar>
  .logo+
  ul.menu_v>
    li.menu_itm*2+
    li.menu_item.dropd
  ^
  ul.menu_v>
    li.item_dd

This is a lot more readable than HTML. And after looking at it, I thought, wouldn't it be great if Emmet supported indentation. And after that I thought, what if there is a conversion tool that converts Emmet into HTML with indentation. That way it's a lot more fun to write and read through HTML. I mean XML had JSON happen to it. It's time for HTML to move on...

DanielRuf commented 6 years ago

You mean webcomponents, hyperscript, JSX and pug? Well, imho this is not very easy to read.

DanielRuf commented 6 years ago

Emmet is mostly used for quick prototyping and command completion / scaffolding eg in PhpStorm projects. So Emmet syntax is normally not stored in any projects, just the final html.

janic0 commented 2 years ago

I found this and it seems to be working quite well: https://uhc-elgg.ch/convert/

Kcko commented 2 years ago

I found this and it seems to be working quite well: https://uhc-elgg.ch/convert/

Great! Thx!

cvladan commented 2 years ago

I found this and it seems to be working quite well: https://uhc-elgg.ch/convert/

Yeah, thanks!