Ticket #21 (assigned enhancement)

Opened 3 years ago

Last modified 2 years ago

Extend BlueCloth with URL resolver

Reported by: Anders Engström <aengstrom@…> Owned by: deveiant
Priority: normal Milestone: Markdown 1.0.1
Component: API Version: 0.0.4b
Severity: normal Keywords: rfe url resolver non-markdown
Cc:

Description (last modified by deveiant) (diff)

Hi.

I'm using BlueCloth to automate the generation of a website. I have a bunch of Markdown files (such as INDEX, README, INSTALL etc.) that I process with BlueCloth into a website (containing index.html, readme.html, install.html etc.).

I've extended BlueCloth (0.0.4b) with some code that allows me to plug in an external URL resolver for links that can not be resolved in the current document. This makes it easy for me to reference pages in my website without cluttering the Markdown text with links like [this][readme.html].

Instead I can put the following in my document:

some text with an un-resolved [link][README] 
that should point to the README document.

The above is transformed to:

some text with an un-resolved <a href="readme.html" title="Readme">link</a> 
that should point to the README document.

My extension to BlueCloth allows me to code something like:

class Resolver
    def resolve(link_id)
        if link_id == "readme"
           ["readme.html", "Readme"] #URL and Title
        else
            nil
        end
    end
end

parser = BlueCloth.new(some_text)
parser.url_resolver = Resolver.new
puts parser.to_html

Allowing users to extend BlueCloth with custom url-resolvers would be a nice feature IMO.

My modification of BlueCloth is pretty trivial - but let me know if you want me to send in the code as a patch :)

Best Regards //Anders

Attachments

url_resolver_patch.tar.gz (18.7 kB) - added by Anders Engström <aengstrom@…> 3 years ago.
Patch for URL-Resolver

Change History

Changed 3 years ago by deveiant

  • status changed from new to assigned
  • description modified (diff)

Hell yes, please do send a patch. This looks really cool

Changed 3 years ago by Anders Engström <aengstrom@…>

Patch for URL-Resolver

Changed 3 years ago by Anders Engström <aengstrom@…>

[Copied over from the related patch ticket on Rubyforge -Ed]

Here's a patch for BlueCloth (0.0.4b). It extends BlueCloth with a "url_resolver" attribute that can be used to delegate URL-lookups to an external object.

I haven't defined any 'url-resolver' "interface" - I'm not sure how you'd like to implement the feature :) But the attached code shows how I've patched BlueCloth for my purpose. I expect you to implement the actual feature in a different way :)

There's a small test-case included (patch_test.rb) as well as the modified bluecloth.rb (bluecloth_patched.rb) and the original from 0.0.4b.

I've also included a patchfile (url_resolver.patch) that can be applied using the standard patch tool ('patch -p0 < url_resolver.patch' should do it).

Changed 3 years ago by deveiant

[I'm just pasting in the rest of the conversation here instead of putting it in individual comments. -Ed]

Date: 2004-09-02 13:06 Sender: Anders Engström

Logged In: YES user_id=738

I notice that the url-resolver hack is not included in the latest release 1.0.0b. Are there any plans to include the patch (http://deveiate.org/projects/BlueCloth/attachment/ticket/21/url_resolver_patch.tar.gz) in a future release? (Or should I continue to patch my local install of BlueCloth ;)


Date: 2004-09-02 13:26 Sender: Michael Granger

Logged In: YES user_id=158

My apologies; I meant to include it. The next release will.


Date: 2004-09-02 14:06 Sender: Anders Engström

Logged In: YES user_id=738

Hey, that's cool. I'm not expecting you to include anything just because I posted a patch that *I* find useful :)

Looking forward to the next release :)


Date: 2004-12-07 16:22 Sender: Nobody

Logged In: NO

This can also be achieved by appending the generic URLs to the end of the markdown text in standard format before processing with BlueCloth e.g.

[README]: readme.html
[me] http://www.example.com/homepage.html

etc.

seems conceptually cleaner to me.


Date: 2004-12-07 17:22 Sender: Anders Engström

Logged In: YES user_id=738

If the same process (person) is responsible for creating the markdown text and processing it, yes - it would be easier to simply append the link-defs at the end of the markdown-document before sending it to BlueCloth#to_html.

But - this might not be the case - it's not for me. You have to know which urls exist in the markdown document before inserting the link-defs. One nice usage of an URL-resolver might be to transform all ruby-talk references to the appropriate url. I.e. from [link][ruby-talk:123567] to "http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/123567".

I'd buy the "append link-defs yourself solution" if there was a way to ask BlueCloth to list all URL's found in a document - but this is not the case.

Changed 3 years ago by Tom <alltom@…>

I am in great need of this myself. My own hack wasn't quite so clean.

Changed 2 years ago by aengstrom@…

Great to see that BlueCloth is still alive! I haven't looked at the BlueCloth sources in a while, but please let me know if there's anything I can do to help with this enhancement :)

//Anders (original poster)

Note: See TracTickets for help on using tickets.