markdown-it / markdown-it-footnote

Footnotes plugin for markdown-it markdown parser
https://markdown-it.github.io/
MIT License
212 stars 59 forks source link

The legacy #ref is broken on JSON based applications. (MEAN.JS) #5

Closed AlexisTM closed 9 years ago

AlexisTM commented 9 years ago

Dear,

I am creating an HTML5 application with angular. To work I need to add the base URL in the html header.

<base href="/">

Then when I click en the footnote, it do not redirect to the correct url.

http://micd.herokuapp.com/#fnref2:1

Instead of

http://micd.herokuapp.com/articles/556acc58cbf0d10b000be0c8#fnref2:1

I wonder if you have any clues to make the plugin compatible or to fix the legacy HTML # .

Thanks !

puzrin commented 9 years ago

No ideas. I think this problem is not directly related to this package http://stackoverflow.com/questions/1889076/is-it-recommended-to-use-the-base-html-tag.

Anyway renderer look is customizeable https://github.com/markdown-it/markdown-it-footnote/blob/master/index.js#L46-L51. You can hack it as you wish if you find solution.

AlexisTM commented 9 years ago

Thanks! The solution was to customize the functions! (Posted in cas someone wonder)

var md = window.markdownit()
    .use(window.markdownitFootnote);

md.renderer.rules.footnote_ref = function (tokens, idx) {
  var n = Number(tokens[idx].meta.id + 1).toString();
  var id = 'fnref' + n;
  var uri = window.location.pathname;
  if (tokens[idx].meta.subId > 0) {
    id += ':' + tokens[idx].meta.subId;
  }
  return '<sup class="footnote-ref"><a href="' + uri + '#fn' + n + '" id="' + id + '">[' + n + ']</a></sup>';
};

md.renderer.rules.footnote_anchor = function(tokens, idx) {
  var n = Number(tokens[idx].meta.id + 1).toString();
  var id = 'fnref' + n;
  var uri = window.location.pathname;
  if (tokens[idx].meta.subId > 0) {
    id += ':' + tokens[idx].meta.subId;
  }
  return ' <a href="' + uri + '#' + id + '" class="footnote-backref">\u21a9</a>'; /* ↩ */
};