markwatkinson / luminous

Accurate and powerful syntax highlighting library
http://luminous.asgaard.co.uk
GNU Lesser General Public License v2.1
51 stars 5 forks source link

Wordpress Plugin #27

Closed dcblogdev closed 11 years ago

dcblogdev commented 11 years ago

I've created a Wordpress plugin for Luminous I've included a copy of luminous inside the plugin folder (wp-luminous) but have not changed anything inside if it, to avoid any potential update issues.

markwatkinson commented 11 years ago

David,

Thanks for doing this, but it doesn't make sense for to me merge it as it would transform my repository into a Wordpress plugin containing Luminous, instead of just, well, Luminous. IMO it would make more sense to have any plugins and so on as standalone repositories, which include Luminous as a Git submodule to make syncing easier.

I've looked over your code and I have a few suggestions, I hope you don't mind if I mention them:

dcblogdev commented 11 years ago

Thanks for coming back to me, I'll leave it as a forked project then anyone who wants it can get it. Your right about the pre tag issue time permitting I'll look further into ways to combat this.

On Thu, Jan 24, 2013 at 9:06 AM, Mark Watkinson notifications@github.comwrote:

David,

Thanks for doing this, but it doesn't make sense for to me merge it as it would transform my repository into a Wordpress plugin containing Luminous, instead of just, well, Luminous. IMO it would make more sense to have any plugins and so on as standalone repositories, which include Luminous as a Git submodule to make syncing easier.

I've looked over your code and I have a few suggestions, I hope you don't mind if I mention them:

  • You don't have to hard code the language list: luminous::scanners() returns an array of $lang=>$codes, where $codes[0] will be a valid language code ($lang will be a human readable description IIRC).
  • You can therefore craft a regex to match the language attribute, and pop the value into luminous::highlight() (which will silently default to 'plain' if an invalid language is specified), rather than run the regex once per language.
  • Using the pre tag to contain code intuitively makes sense, but it will fail if you're highlighting HTML containing a closing pre tag (unless you expect everything to be escaped, but I didn't spot that any unescaping your code). This is part of a really nasty general problem when trying to extract data from an HTML fragment: it's hard to do with regexes. I don't know if WP (or PHP) provides anything better that can run in a reasonably small amount of time, so maybe it's the only practical way. I'd wonder if using non-HTML notation might be best (like [sourcecode] or [code]) ... do WP's shortcodes http://codex.wordpress.org/Shortcode_API work for this? It looks like that handles attribute parsing too. At least then when it all goes wrong, it's WP's fault :)

    — Reply to this email directly or view it on GitHubhttps://github.com/markwatkinson/luminous/pull/27#issuecomment-12642725.

Warmest Regards.

DAVID CARR Web Developer

Email: dave@daveismyname.com website: www.daveismyname.com Mobile: 07429 561 809