image.js 733 B

12345678910111213141516171819202122232425262728293031
  1. 'use strict';
  2. var uri = require('../util/enclose-uri');
  3. var title = require('../util/enclose-title');
  4. module.exports = image;
  5. /* Stringify an image.
  6. *
  7. * Is smart about enclosing `url` (see `encloseURI()`) and
  8. * `title` (see `encloseTitle()`).
  9. *
  10. * ![foo](</fav icon.png> 'My "favourite" icon')
  11. *
  12. * Supports named entities in `url`, `alt`, and `title`
  13. * when in `settings.encode` mode.
  14. */
  15. function image(node) {
  16. var self = this;
  17. var content = uri(self.encode(node.url || '', node));
  18. var exit = self.enterLink();
  19. var alt = self.encode(self.escape(node.alt || '', node));
  20. exit();
  21. if (node.title) {
  22. content += ' ' + title(self.encode(node.title, node));
  23. }
  24. return '![' + alt + '](' + content + ')';
  25. }