8 ms·
Markdown.css – make HTML look like plain-text
- kilovoltaire 14y agovery clever, particularly how the width of the equals signs below an h1 is made to match the text width using hidden overflow: https://github.com/mrcoles/markdown-css/blob/0d00981143172aad4f9939f6deed8106ca4000b5/markdown.css#L61 https://github.com/mrcoles/markdown-css/blob/0d00981143172aa...
- mrcoles 14y agoThe magic is the quirks in how `display: table-cell` makes it like a block, but only as wide as the text, then the pseudo element with equals signs is positioned absolutely inside. Fortunately, most browsers allow this, but firefox doesn't let things be positioned absolute inside a `table-cell`, so I make FF just fall back to `display: block` https://github.com/mrcoles/markdown-css/blob/master/markdown.css#L185 https://github.com/mrcoles/markdown-css/blob/master/markdown...
- kilovoltaire 14y agointeresting! in the same vein as the h1 equals, i like the blockquote brackets implementation as well: https://github.com/mrcoles/markdown-css/blob/0d00981143172aad4f9939f6deed8106ca4000b5/markdown.css#L122 https://github.com/mrcoles/markdown-css/blob/0d00981143172aa...
- mrcoles 14y agoyeah, the \A makes a newline and the `white-space: pre` makes that work like a <br>
- crazygringo 14y agoThat was definitely the most impressive bit for me too. I thought, how on earth was that done? Very clever. It's a shame it doesn't work for copy-paste, but honestly, it's probably even easier to write a reverse-markdown script than to figure out how to do it with CSS!
- molf 14y agoPretty cool. Would it also be possible to include the markdown markup when copying the text?
- mrcoles 14y agothe after and before pseudo elements are kind of weird. I think for it to work with copy-paste I'd have to include some JS to look at the selection, reverse markdown it, and then get it into your clipboard.
- goldfeld 14y agoQuite frankly that would be the most common useful use case for this, in my opinion. In any case this is some great css hacking!
- smj2118 14y agoAgreed, would love to use this to generate markdown!
- TwistedWeasel 14y agoIt's interesting and seems well implemented but I don't understand the use case? Why would you need this? If you want plain text inside HTML isn't what the <pre> tag is for?
- kilovoltaire 14y agonote that it's markdown, not just plain text. i think it's mostly just for fun though / as an impressive CSS trick.
- mrcoles 14y agoMostly because it's fun in a nerdy way, and it was an interesting challenge to implement. I decided to use it for a demos page on my site: http://mrcoles.com/demo/ http://mrcoles.com/demo/ Also, there's a bookmarklet at the top of the markdown-css demo that let's you apply the markdown styles to any page, which is like a harder-to-read version of readability or a quick way to see how well layed out the markup is on any page.
- deleted 14y ago[deleted]
- homosaur 14y agoWell, maybe you want the HTML formatting without the styles or all the CSS classes. Say you wanted to do something like grab all the docs off a website and then apply your own styling or put them on an internal reference. I can see that being a good use case to allow that for open documentation.
- MJR 14y agoAs a developer you may not want it - but my friends who are copywriters, editors and content strategists will LOVE this. A simple way to grab existing web content as markdown, which many are already using to write and edit their content.
- TwistedWeasel 14y agoThat makes more sense to me now. Thinking about it I see it being useful to help with some currently painful tasks like converting old wiki content that has a non-standard wiki markup syntax (or no markup at all) into markdown.
- drcoopster 14y agoI find this clever. Use cases aside, it's fun.
- danso 14y agoFinally. A proper use-case for displaying content with the :before selector.
- tantalor 14y agoThen it's only fitting that the use-case is completely useless.
- ceejayoz 14y agoIIRC, I saw :before used to great effect in print stylesheets for turning links into plain-text URLs.
- wubbfindel 14y agoPersonally I think to add an icon (using an icon font or possibly a data uri) is a great (and proper) use-case for displaying content with either the :before or :after selector.
- kumarharsh 14y agoThis is not a "proper" use case. I am not able to understand why one would want to "view" Markup in Markdown?
- president 14y agoAwesome project. Is there anything that can actually convert HTML to Markdown though?
- janerik 14y agoI use pandoc[1] for this. curl -s example.com | pandoc -f html -t markdown - [1]: http://johnmacfarlane.net/pandoc/ http://johnmacfarlane.net/pandoc/
- fiddlosopher 14y agoThis works too: pandoc -t markdown http://example.com
- janerik 14y agoNice. Didn't know pandoc can directly read from an URL, even easier.
- gridaphobe 14y agohttp://johnmacfarlane.net/pandoc/ http://johnmacfarlane.net/pandoc/
- loevborg 14y agoThe wonderful pandoc (http://johnmacfarlane.net/pandoc/README.html#general-options http://johnmacfarlane.net/pandoc/README.html#general-options) can, along with many other things.
- lanna 14y agoI'm much better at HTML than Markdown. I totally could use this when I'm forced to write Markdown.
- mbetter 14y agoYou can't, actually. Use Pandoc.
- vysakh0 14y agoPretty neat and cool! Seeing this i got reminded how awesome markdown is and i just played around with my vim markdown plugin after long time.
- leeoniya 14y agoshameless plug: client-side (or node) html > markdown, like actual conversion demo: http://leeoniya.github.com/reMarked.js/ http://leeoniya.github.com/reMarked.js/ repo: https://github.com/leeoniya/reMarked.js https://github.com/leeoniya/reMarked.js
- dazmax 14y agoIs that available as a bookmarklet, where you can select content on an existing page and extract markdown to the clipboard?
- leeoniya 14y agoit'd be fairly easy to make one, but i imagine it would have limited utility since the entire content of the page is rarely what you want. how would you go about selecting which portion you're interested in? also, i'm not certain a bookmarklet would have direct clipboard access due to security, i could be wrong tho. feel free to open up an issue on github to discuss the idea and implementation details further.
- nieve 14y agoThis may have changed in the last few years, but I believe you can simply do "window.getSelection()" in your bookmarklet to access the currently selection for Firefox/WebKit browsers.
- leeoniya 14y agomight be worth trying. however, i'm still not convinced the presented use-case would be useful rather than just cool.
- nieve 14y agoSadly you're almost certainly right. Most of the places I could see wanting to reverse-engineer the displayed HTML into Markdown are actually sites using their own hackish, inconsistently rendered output. You'd end up needing per-site tweaks and that'd kind of render the whole thing unworkable and pointless.
- samwillis 14y agoFirstly this is awsome! As much as I like kittens... This adds the markdown for images too: .markdown img { display: inline; content: ""; } .markdown img:before { content: " ")"; display: inline; color: #333333; } The trick to make it work with images is the `content: "";` on the img element to stop the browser from treating it as an image. EDIT: See it here: http://jsfiddle.net/F2mjs/ http://jsfiddle.net/F2mjs/ Anyone know how to make the link clickable?
- basicallydan 14y agoNicely done sir. Pull request ahoy!
- 67726e 14y agoWow. Was just looking into this myself. Great find.
- mrcoles 14y agoYou're using opera, right? This was already in my code, but I commented out, maybe I should just let it be in there real quick before opera changes to webkit: https://github.com/mrcoles/markdown-css/blob/016bf0863867aed0428bcfb8256d43863af0a09b/markdown.less#L191 https://github.com/mrcoles/markdown-css/blob/016bf0863867aed... If not opera, lmk what browser you're using.
- samwillis 14y agoThis is working in Chrome 24. Oh, yes it is. Its in the .less file, I had not spotted that. EDIT: You need `content: "";` in the less file and it should work.
- mrcoles 14y agoOh, interesting. Chrome does play nice with that. Also, it looks like maybe you have to make the img content "", in order for the :before to work—otherwise it doesn't show up, at least in chrome, and with that demo it appears as nothing at all in firefox. It's a cruel world… In the bookmarklet (included at top of demo) I do an extra step to make images inside links smaller and appear inside the link markdown—not what you were getting at, but it is a little something something.
- 67726e 14y agoJust curious, but what version of Opera did you get `:before` & `:after` working on? I was just trying this out on the latest Opera and couldn't get it to work.
- mrcoles 14y agoWorks for me on opera 12.14 on Mac OS X. What version and OS are you using?
- 67726e 14y agoI'm also using 12.14 on OS X 10.7.5 Opera/9.80 (Macintosh; Intel Mac OS X 10.7.5) Presto/2.12.388 Version/12.14
- mrcoles 14y agoWhat is it that you're not seeing working? screen shot of how it looks to me in opera: http://i.imgur.com/7te5TWW.png http://i.imgur.com/7te5TWW.png
- 67726e 14y agoI meant regarding the image, but I looked at the code and realized you didn't include it at all. Sorry about the confusion.
- kmf 14y agoThis is awesome. Projects like this make me appreciate the fortitude of Markdown. John has made a project that essentially got it right on the first try[1], with very few patches or additions. In a world of software development where I'm running `gem update` all the time, it's nice to have something like Markdown which really knocked it out of the park in one try. I don't have to check the docs to know if the syntax for URL linking changed, and your implementation isn't going to be any different from mine. It's nice to have a standard like that everyone can rally behind. [1]: I'm aware of projects like MMD, which AFAIK are primarily add-ons to the original Markdown syntax. I also realize that Markdown isn't perfect: Jeff Atwood has a good write-up on this from late 2009 -- http://www.codinghorror.com/blog/2009/12/responsible-open-source-code-parenting.html http://www.codinghorror.com/blog/2009/12/responsible-open-so...
- mzs 14y agoCool, but the numbered list has everything lablled as '1.' for me: ff esr 10.0.12
- theon144 14y ago>in markdown, the actual numbers don’t matter That's to be expected, you make ordered lists like that in markdown :)
- mzs 14y agoHa, I didn't know you could just use any number until just now, makes sense, doh! Thanks.
- kumarharsh 14y agoyea, its a good case using just 30. item1 999. item2 2. item3 for numbered lists but it can possibly "break" in some later versions of markdown, as said by the man himself: "If you do use lazy list numbering, however, you should still start the list with the number 1. At some point in the future, Markdown may support starting ordered lists at an arbitrary number." -- John Gruber / Daring Fireball (http://daringfireball.net/projects/markdown/syntax#list http://daringfireball.net/projects/markdown/syntax#list)
- mrcoles 14y agoYeah, technically markdown doesn't need the numbers to be incremented, so I thought it'd be more fun to explicitly not use counters. Maybe it's too confusing though. There's a discussion about it here: https://github.com/mrcoles/markdown-css/issues/1 https://github.com/mrcoles/markdown-css/issues/1
- mrcoles 14y agoUPDATE: I ended up merging that in and making the ones toggle-able, and then added a toggle link into the demo so you can see both http://mrcoles.com/demo/markdown-css/ http://mrcoles.com/demo/markdown-css/
- Foomandoonian 14y agoSame as ReMarkdown? http://fvsch.com/code/remarkdown/ http://fvsch.com/code/remarkdown/
- mrcoles 14y agoWow, that's really similar with very similar approaches. The internet is a great way to find out you're not very original. I'll add a link to that project from mine.
- Foomandoonian 14y agoKudos.
- dfc 14y agoThis is nice. The one use case its missing for me is copy/paste with formatting. Currently I use: $ pandoc -f html -t markdown http://example.org/page.htm > page.mdwn
- kevinburke 14y agoHeh, I did something a year ago to do the opposite - take a plain markdown file and give it some styles. http://kevinburke.bitbucket.org/markdowncss/ http://kevinburke.bitbucket.org/markdowncss/ HN discussion: http://news.ycombinator.com/item?id=2827892 http://news.ycombinator.com/item?id=2827892
- dergachev 14y agoIf you're interested in this, you should also know about Showdown.js, a library that converts markdown into HTML client-side: https://github.com/coreyti/showdown https://github.com/coreyti/showdown For an example use, view the source of http://dergachev.github.com/pin-screenshot-bookmarklet http://dergachev.github.com/pin-screenshot-bookmarklet
- sgt 14y agoI think could be interesting for Phrack as they are (or should be) modernizing their e-zine format. In that way, the old school boys can still keep their pure-ASCII, and others may wish to apply some other CSS to make it more pleasant to read.
- kzrdude 14y agoI still wonder why Markdown is so popular while reStructuredText is not. I find the latter much easier to read, it looks better in both plain and rendered format (and rst2pdf makes nice docs).
- ianstormtaylor 14y agoWell, one thing that definitely isn't helping is its horrible name. And as evidence, the very first thing on their site: "'reStructuredText' is ONE word, not two!" I'm definitely never going to type out that entire word, so now do I abbreviate it to reST? or ReST like some people on the site seem to be doing? It'll just get confused with REST in Google searches...
- roc 14y agoMarkdown is 'lighter' and aimed at the more general case: churning out lightly-formatted text quickly, with as few 'rules' as possible, with page layout concerns addressed by templates defined elsewhere. reStructuredText is 'heavier' and only really an improvement over Markdown if you're trying to embed page layout into the text. Which fewer people are.
- kzrdude 14y agoYou are right. I think I prefer reST because it produces documents. It's not a quick way to add markup, it's a quick way to structure a document (and provide links, sections, inline code etc).
- antihero 14y agoPersonally I found the RST documentation quite inaccessible for doing simple things.
- wyck 14y agoI don't understand this, Markdown is meant for writing. Why don't you just output real markdown with something like Jekyll, Markdown Server (node) or Showdown?
- mrcoles 14y agoIt’s meant as an interesting CSS hack to make markup look like markdown, but still function as regular HTML (including having things like links still work). There are thousands of things that compile markdown to HTML, that's not at all what this does. Try clicking on the different tabs to show the different states or the demo link to the left of them—maybe that'll make more sense?
- wyck 14y agoI still don't get it, why should I make something look like markdown when it can be actual markdown. Links work in markdown, you can eve use something like maruku to have html elements (divs, id's etc) in actual markdown. Markdown is portable, fake markdown isn't.
- almost 14y agoThis is cool :) I do a similar thing on my site[1]to make it look like Org-mode files (which is what I use to write it). I enjoy the fact that so much processing goes into making it look just like it did to begin with :p 1: http://almostobsolete.net http://almostobsolete.net
- asimjalis 14y agoThis is hilarious. Thank you :)
- unfoldedorigami 14y agoJust submitted a pull request to auto-increment the ordered list numbering so it doesn't repeat 1. over and over. https://github.com/mrcoles/markdown-css/pull/4 https://github.com/mrcoles/markdown-css/pull/4
- chc 14y agoI'm pretty sure that was an intentional design choice to make the text look more like Markdown. Ordered lists increment by default — they went out of their way to disable that.
- huhsamovar 14y agoDoes anybody else think we've come full circle now? I don't see how this is at all useful. Just upload a .md file.