What is meta? ×
Meta Stack Exchange is where users like you discuss bugs, features, and support issues that affect the software powering all 127 Stack Exchange communities.

In an answer, I was adding some links to the documentation, after I wrote some PHP code. As result, the code was altered.

Take as example the following Markdown with an indented code block.

    if (isset($item['load_functions'][1]) && !empty($item['map'][1]) && $item['load_functions'][1] == 'node_load') {
      $node = $router_item['map'][1];
    }
    else {
      // The menu item is not for a node.
    }

After I add the first link (in a regular paragraph), I get the following, as expected.

    if (isset($item['load_functions'][1]) && !empty($item['map'][1]) && $item['load_functions'][1] == 'node_load') {
      $node = $router_item['map'][1];
    }
    else {
      // The menu item is not for a node.
    }

See [menu_get_object()][1]

[1]: http://api.drupal.org/api/drupal/includes!menu.inc/function/menu_get_object/7

After I add the second link, I get the following, where the [1] indexes in the code block have been interpreted as links.

    if (isset($item['load_functions'][1]) && !empty($item['map'][2]) && $item['load_functions'][3] == 'node_load') {
      $node = $router_item['map'][4];
    }
    else {
      // The menu item is not for a node.
    }

See [menu_get_object()][5]

And see [menu_get_item()][6]

[1]: http://api.drupal.org/api/drupal/includes!menu.inc/function/menu_get_object/7
[2]: http://api.drupal.org/api/drupal/includes!menu.inc/function/menu_get_object/7
[3]: http://api.drupal.org/api/drupal/includes!menu.inc/function/menu_get_object/7
[4]: http://api.drupal.org/api/drupal/includes!menu.inc/function/menu_get_object/7
[5]: http://api.drupal.org/api/drupal/includes!menu.inc/function/menu_get_object/7
[6]: http://api.drupal.org/api/drupal/includes!menu.inc/function/menu_get_item/7

Notice that the code is correctly indented with 4 spaces.

I was able to reproduce the bug in the sandbox. I also tried with another browser, as I noticed I was using a not supported browser (Firefox 19.0a1). With Safari 6.0.2, the result is the same.

The issues are two:

  • Perfectly valid code is rewritten.
  • Markdown links pointing to the same URL are rewritten. Even in the case I didn't write PHP code, but Markdown markup, there isn't any need to re-write all the links.

Suppose I have the following markdown.

[Example link][1]

[Same example link][1]

[The same link once again][1]

[1]: http://api.drupal.org/api/drupal/includes!menu.inc/function/menu_get_item/7

If I add another link, the other links should not be changed. This is what instead happens.

[Example link][1]

[Same example link][2]

[The same link once again][3]

[Another link][4]

[1]: http://api.drupal.org/api/drupal/includes!menu.inc/function/menu_get_item/7
[2]: http://api.drupal.org/api/drupal/includes!menu.inc/function/menu_get_item/7
[3]: http://api.drupal.org/api/drupal/includes!menu.inc/function/menu_get_item/7
[4]: http://api.drupal.org/api/drupal/includes!menu.inc/function/menu_get_object/7

See the sandbox example.

share|improve this question
7  
Well spotted! +1. –  Second Rikudo Nov 7 '12 at 17:24
    
Also happens in Chrome. –  Hannele Jun 14 '13 at 14:44
    
Similar problems happens with code in backticks –  MSalters Oct 8 '13 at 10:30
add comment

1 Answer

I had the same problem and whilst investigating this, Tim Stone kindly pointed me to this Question in the tavern (starting here).

He explained this "is an existing bug" and "the problem is mostly that the editor piece is (mostly) unaware of the parser behaviour, so it doesn't have the context to make smart decisions most of the time."
He would also look into "how difficult it would be to submit a patch to PageDown to fix it here shortly" (yippie)!

Current workaround:
Don't use the editor's hyperlink function (both button and keyboard shortcut ctrl+L).
Instead, add the links manually:

  • [text](url)
  • <a href="url">text</a>
  • or url-list: [text][url_number]
    with accompanying
      [url_number]: url
    (at the bottom of the answer)

Hope this helps for now!

Kitten draws red freehand-circle around important things in life

share|improve this answer
    
In my case, the four spaces at the beginning of the text could be taken as meaning "this text is code that doesn't need to be touched." That is why we indent the code with four spaces: to let the parser know it's text it doesn't need to parse. Then, it is not necessary to pass from one link to four links as in the last case. The editor is just JavaScript code that doesn't need to rewrite existing links, which is not something the Markdown parser would do. –  kiamlaluno Apr 11 at 16:37
add comment

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .