Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose callback function to element #33

Merged
merged 1 commit into from
Aug 10, 2016

Conversation

TimvdLippe
Copy link
Contributor

This allows users to set custom callbacks to modify the outputted HTML. We use this in our project to modify GitHub issue references as follows:

<marked-element markdown="[[body]]" callback="[[callback(owner,name)]]"></marked-element>
callback: function(owner, name) {
  return function(err, text) {
    return text.replace(/&?#(\d+)/g, function(match, digits) {
      // Character was escaped, we should modify these numbers
      if (match.charAt(0) === '&') {
        return match;
      }
      return '<a href="https://www.github.com/' + owner + '/' + name + '/issues/' + digits + '" target="_blank">#' + digits + '</a>';
    });
  };
}

@TimvdLippe
Copy link
Contributor Author

Friendly ping. Still relying on my own fork for this feature.

@notwaldorf
Copy link
Contributor

/cc @FredKSchott

@TimvdLippe
Copy link
Contributor Author

Friendly ping, this very small change allows us to mimic the GitHub markdown flavors.

@FredKSchott
Copy link
Contributor

Oh man, thought I had looked at this already 😞
@TimvdLippe thanks for the reminder! I'll take a look at this later today.

type: Function,
value: function() {
return function(err, text) {
return text;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want errors to be swallowed by default? I assume this changes marked's behavior to propagate errors asynchronously instead of throwing them synchronously. Can this be null/undefined instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I have turned it into null per https://github.com/chjj/marked/blob/master/lib/marked.js#L1148. Sorry for the long wait, I was on vacation 😂

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no problem, for this PR I'd be a hypocrite to complain :)

@FredKSchott
Copy link
Contributor

👍 New feature looks great! Just 1 question around default behavior.

@FredKSchott
Copy link
Contributor

LGTM, Thanks @TimvdLippe! Merging now

@FredKSchott FredKSchott merged commit ecd3dc1 into PolymerElements:master Aug 10, 2016
@TimvdLippe TimvdLippe deleted the expose-callback branch August 10, 2016 19:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants