From t_leitner at gmx.at Fri Dec 16 12:41:13 2011 From: t_leitner at gmx.at (Thomas Leitner) Date: Fri, 16 Dec 2011 18:41:13 +0100 Subject: [kramdown-users] [Ann] kramdown 0.13.4 Message-ID: <20111216184113.255dec67@noweto> ## About kramdown kramdown (sic, not Kramdown or KramDown, just kramdown) is a *free* GPL-licensed [Ruby](http://www.ruby-lang.org) library for parsing a superset of Markdown. It is completely written in Ruby, supports standard Markdown (with some minor modifications) and various extensions that have been made popular by the [PHP Markdown Extra] package and [Maruku]. Homepage for installation instructions and documentation: http://kramdown.rubyforge.org ## kramdown 0.13.4 released This is mostly a bug fix release and it is recommened to update to this version. ## Changes * 1 minor change: - Added a converter that extracts the TOC of a document (requested by Brendan Hay). Note that this is only useful if you use kramdown as a library! * 7 bug fixes - Fixed a typo: It should be `--output` and not `--ouput` (patch by postmodern) - Fixed HTML converter to correctly output empty `span` tags (patch by John Croisant) - Fixed bug [RF#29350]: Parsing of HTML tags with mismatched case now works - Fixed bug [RF#29426]: Content of `style` tags is treated as raw text now - HTML converter now uses `rel` instead of `rev` to be HTML5 compatible (patch by Joe Fiorini) - Fixed Ruby 1.9.3 related warnings - Fixed HTML parser to work around an implementation change of Array#delete_if in Ruby 1.9.3 [RF#29350]: http://rubyforge.org/tracker/index.php?func=detail&aid=29350&group_id=7403&atid=28673 [RF#29426]: http://rubyforge.org/tracker/index.php?func=detail&aid=29426&group_id=7403&atid=28673 From t_leitner at gmx.at Sat Dec 17 03:33:19 2011 From: t_leitner at gmx.at (Thomas Leitner) Date: Sat, 17 Dec 2011 09:33:19 +0100 Subject: [kramdown-users] url-encoding feature suggestion In-Reply-To: <09FD6D4E-5EDD-428D-A6FB-2A22E0150832@tidbits.com> References: <09FD6D4E-5EDD-428D-A6FB-2A22E0150832@tidbits.com> Message-ID: <20111217093319.6dabd8fc@noweto> On 2011-08-18 07:52 -0700 Matt Neuburg wrote: > Wouldn't it be cool if kramdown would do URL-encoding? For example, > suppose I put this (the URL being copied out of my browser - I hope > this comes through the email): > > [A town in Slovakia](http://en.wikipedia.org/wiki/Ko?ice) > > The result is: > > A town in Slovakia > > But it should be URL-encoded: > > A town in > Slovakia > > I can fix this in my own post-processing in RubyFrontier, of course, > but I suggest that having kramdown perform the URL-encoding itself > would be a cool feature. m. I have looked a bit around and it seems that no other markup processor does this. The problem is: How to detect an already correctly encoded URL? This is not possible, I think, and therefore kramdown has to assume that the URLs are already nicely encoded. Best regards, Thomas From t_leitner at gmx.at Sat Dec 17 06:08:33 2011 From: t_leitner at gmx.at (Thomas Leitner) Date: Sat, 17 Dec 2011 12:08:33 +0100 Subject: [kramdown-users] nofollow to links In-Reply-To: References: Message-ID: <20111217120833.7f57ecb7@noweto> On 2011-09-18 10:39 +0200 Nicholas Wieland wrote: > Hi, is it possible to add attributes to links I generate through > kramdown? The markdown is inserted by users, I can't touch it, but > maybe I can have some kind of filter that in some cases adds the > attributes I need to the generated html. This can be done by customizing the HTML converter. Here is an example of a custom HTML converter used by [webgen]: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ module Webgen::ContentProcessor class KramdownHtmlConverter < ::Kramdown::Converter::Html def initialize(root, options, context) #:nodoc: super(root, options) @context = context @do_convert = if context.options.has_key?('contentprocessor.kramdown.handle_links') context.options['contentprocessor.kramdown.handle_links'] else context.website.config['contentprocessor.kramdown.handle_links'] end end # Convert the element tree under +root+ to HTML using the webgen +context+ object. def self.convert(root, options, context) new(root, options, context).convert(root) end def convert_a(el, indent) el.attr['href'] = @context.tag('relocatable', {'path' => el.attr['href']}) if @do_convert "#{inner(el, indent)}" end def convert_img(el, indent) el.attr['src'] = @context.tag('relocatable', {'path' => el.attr['src']}) if @do_convert "" end end end ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ As you can see, the `a` and `img` tag output is customized. You could do it in a similar way. Best regards, Thomas [webgen]: http://webgen.rubyforge.org From matt at tidbits.com Sat Dec 17 12:25:50 2011 From: matt at tidbits.com (Matt Neuburg) Date: Sat, 17 Dec 2011 09:25:50 -0800 Subject: [kramdown-users] url-encoding feature suggestion In-Reply-To: <20111217093319.6dabd8fc@noweto> References: <09FD6D4E-5EDD-428D-A6FB-2A22E0150832@tidbits.com> <20111217093319.6dabd8fc@noweto> Message-ID: <529C579F-51C1-4564-A70C-9B52ABE9EEDD@tidbits.com> On Dec 17, 2011, at 12:33 AM, Thomas Leitner wrote: > On 2011-08-18 07:52 -0700 Matt Neuburg wrote: >> Wouldn't it be cool if kramdown would do URL-encoding? For example, >> suppose I put this (the URL being copied out of my browser - I hope >> this comes through the email): >> >> [A town in Slovakia](http://en.wikipedia.org/wiki/Ko?ice) >> >> The result is: >> >> A town in Slovakia >> >> But it should be URL-encoded: >> >> A town in >> Slovakia >> >> I can fix this in my own post-processing in RubyFrontier, of course, >> but I suggest that having kramdown perform the URL-encoding itself >> would be a cool feature. m. > > I have looked a bit around and it seems that no other markup processor > does this. The problem is: How to detect an already correctly encoded > URL? This is not possible, I think, and therefore kramdown has to > assume that the URLs are already nicely encoded. require 'URI' def encode_if_not_encoded(s) s2 = URI.decode(s) (s == s2) ? URI.encode(s) : s end s = 'http://en.wikipedia.org/wiki/Ko?ice' s = encode_if_not_encoded(s) p s s = encode_if_not_encoded(s) p s m. -- matt neuburg, phd = matt at tidbits.com, http://www.apeth.net/matt/ pantes anthropoi tou eidenai oregontai phusei Among the 2007 MacTech Top 25, http://tinyurl.com/2rh4pf Programming iOS 4! http://www.apeth.net/matt/default.html#iosbook RubyFrontier! http://www.apeth.com/RubyFrontierDocs/default.html TidBITS, Mac news and reviews since 1990, http://www.tidbits.com From t_leitner at gmx.at Sun Dec 18 03:09:51 2011 From: t_leitner at gmx.at (Thomas Leitner) Date: Sun, 18 Dec 2011 09:09:51 +0100 Subject: [kramdown-users] url-encoding feature suggestion In-Reply-To: <529C579F-51C1-4564-A70C-9B52ABE9EEDD@tidbits.com> References: <09FD6D4E-5EDD-428D-A6FB-2A22E0150832@tidbits.com> <20111217093319.6dabd8fc@noweto> <529C579F-51C1-4564-A70C-9B52ABE9EEDD@tidbits.com> Message-ID: <20111218090951.61dcbefb@noweto> On 2011-12-17 09:25 -0800 Matt Neuburg wrote: > On Dec 17, 2011, at 12:33 AM, Thomas Leitner wrote: > > I have looked a bit around and it seems that no other markup > > processor does this. The problem is: How to detect an already > > correctly encoded URL? This is not possible, I think, and therefore > > kramdown has to assume that the URLs are already nicely encoded. > > require 'URI' > > def encode_if_not_encoded(s) > s2 = URI.decode(s) > (s == s2) ? URI.encode(s) : s > end > > s = 'http://en.wikipedia.org/wiki/Ko?ice' > s = encode_if_not_encoded(s) > p s > s = encode_if_not_encoded(s) > p s Okay, but what about URLs that look like they are correctly encoded but are not? For example, the URL `http://example.com/hallo/%2520`. If we state that kramdown automatically encodes URLs, this URL would be left as is using your `encode_if_not_encoded` method. But what if this URL is *not* already encoded and should be encoded to `http://example.com/hallo/%252520`? I have to admit that this is a rather pathological case but nonetheless... Another reason for leaving it as it is: Now you can just copy and paste a kramdown document into a mail or anywhere else and the links will *just work*. If we would allow invalid URLs in a kramdown document, this would not be the case anymore. For example, your link above doesn't work in my mail client. Best regards, Thomas