Posted by therzog on March 18, 2008 at 5:11pm
| Project: | Markdown with SmartyPants |
| Version: | 6.x-1.0 |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | needs review |
Issue Summary
It would be great if markdown would fully support drupal internal urls, like [drupal link](node/1000). This means patching markdown.php. Here is a patch. I gave it to michel also, but he doesn't seem like a drupal enthusiast, so I'm not sure if he'll use it.
--- marksmarty.module 2008-01-22 17:25:27.000000000 -0500
+++ marksmarty.new.module 2008-03-18 13:15:51.000000000 -0400
@@ -111,7 +111,31 @@
* Module Functions
********************************************************************/
+ /*
+ * We subclass the Markdown parser to implement support for drupal internal links
+ */
+
+class DrupalMarkdownParser {
+
+ function urlWrapper($url) {
+ $frag = null;
+ $query = null;
+
+ // support ordinary query strings and marks
+ if( strrpos($url, '#') !== FALSE ) {
+ list($url,$frag) = explode('#', $url, 2);
+ }
+
+ if( strpos($url, '?') !== FALSE ) {
+ list($url,$query) = explode('?', $url, 2);
+ }
+
+ return url($url, $query, $frag);
+ }
+}
+
function _marksmarty_process($text, $format) {
+ @define( 'MARKDOWN_PARSER_CLASS' 'DrupalMarkdownParser' );
require_once(dirname(__FILE__) .'/markdown.php');
require_once(dirname(__FILE__) .'/smartypants.php');
if (variable_get("marksmarty_is_markdown_on_$format", 1) == 1) {
@@ -169,4 +193,4 @@
);
return $form;
-}
\ No newline at end of file
+}
--- markdown.php 2008-01-22 16:57:25.000000000 -0500
+++ markdown.new.php 2008-03-18 13:09:26.000000000 -0400
@@ -708,6 +708,7 @@
if (isset($this->urls[$link_id])) {
$url = $this->urls[$link_id];
+ $url = $this->urlWrapper($url);
$url = $this->encodeAmpsAndAngles($url);
$result = "<a href=\"$url\"";
@@ -732,6 +733,7 @@
$url = $matches[3] == '' ? $matches[4] : $matches[3];
$title =& $matches[7];
+ $url = $this->urlWrapper($url);
$url = $this->encodeAmpsAndAngles($url);
$result = "<a href=\"$url\"";
@@ -748,6 +750,13 @@
}
+ function urlWrapper($url) {
+ # subclasses can override this function to convert internal urls to ordinary html (like for drupal)
+ # we just return the unadultered url
+
+ return $url;
+ }
+
function doImages($text) {
#
# Turn Markdown image shortcuts into <img> tags.
@@ -2633,4 +2642,4 @@
software, even if advised of the possibility of such damage.
*/
-?>
\ No newline at end of file
+?>
Comments
#1
Seems like a minimally invasive patch with good utility. I'll await more comments but it looks committable to me ... Perhaps you could find a place to document this. Maybe in the block?
#2
With some more documentation. Also with improved support for relative links.
#3
+1
Very useful addition.
#4
Hello Drupal,
I search upload package module, and i got that module for drupal 5. I worked on the module for drupal 6 and its in working state. So please let me know how can i add this module to drupal community