--- markdown.php.orig 2008-03-18 21:39:44.000000000 -0400
+++ markdown.php 2008-03-18 22:15:51.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 = "urlWrapper($url);
$url = $this->encodeAmpsAndAngles($url);
$result = "hashPart($result);
}
+ function urlWrapper($url) {
+ # urlWrapper gets called whenever Markdown creates a link
+ # subclasses can override this function to convert internal urls to ordinary html (like for drupal)
+ # by default we just return the unadultered url
+
+ return $url;
+ }
function doImages($text) {
#
@@ -2633,4 +2642,4 @@
software, even if advised of the possibility of such damage.
*/
-?>
\ No newline at end of file
+?>
--- marksmarty.module.orig 2008-01-22 17:25:27.000000000 -0500
+++ marksmarty.module 2008-03-18 22:14:37.000000000 -0400
@@ -111,7 +111,45 @@
* Module Functions
********************************************************************/
+ /*
+ * We subclass the Markdown parser to implement support for drupal internal links
+ */
+
+class DrupalMarkdownParser {
+
+ /* urlWrapper gets called when the Markdown parser creates a link. By default the parser does no
+ * transformation, so links are ordinary absolute or relative html links. Here, we transform
+ * drupal internal links to ordinary html links
+ */
+ function urlWrapper($original_url) {
+ $frag = null;
+ $query = null;
+
+ $url = $original_url;
+
+ // 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);
+ }
+
+ /* We use drupal_get_path_alias to sniff whether drupal thinks this is an internal link.
+ * If it isn't then we return the original link. This lets us support both drupal internal links
+ * and ordinary absolute and relative html links, such as /path/file
+ */
+ if( drupal_get_path_alias($url) === $url ) {
+ return $original_url;
+ }
+
+ return url($url, $query, $frag);
+ }
+}
+
function _marksmarty_process($text, $format) {
+ @define( 'MARKDOWN_PARSER_CLASS', 'DrupalMarkdownParser' ); // specify class that Markdown will declare for a parser
require_once(dirname(__FILE__) .'/markdown.php');
require_once(dirname(__FILE__) .'/smartypants.php');
if (variable_get("marksmarty_is_markdown_on_$format", 1) == 1) {
@@ -169,4 +207,4 @@
);
return $form;
-}
\ No newline at end of file
+}