Skip to content
Snippets Groups Projects
Commit a351d2a5 authored by tatsy's avatar tatsy
Browse files

Revise index.js to use wrapped markdown-it instance

parent 8536034b
No related branches found
No related tags found
No related merge requests found
language: node_js
node_js:
- '0.10'
script: make test-ci
script:
- make test-ci
deploy:
provider: npm
email: tatsy.mail@gmail.com
api_key:
secure: NPmR0/0uUF3sL6PI7rhO7pNOxa0doCcp7MXbRvOcenw9mF6CVFJNSfCJmCST59gGCVarYxzR8s3oGsTGvNB7i3WF6mv4WcH3lS7ZY/8PPWEiCzFu7H6J/faULO3zj2ZarxGSEesilWZYs8dF0Dkkxe+cafiEMVnU3wK9WfR4t10=
on:
tags: true
repo: tatsy/markdown-it-imsize
......@@ -3,11 +3,11 @@
'use strict';
var mdit = require('markdown-it')();
var parseImageSize = require('./helpers/parse_image_size');
var normalizeReference = require('./helpers/normalize_reference.js');
function image_with_size(state, silent) {
function image_with_size(md) {
return function(state, silent) {
var code,
href,
label,
......@@ -28,7 +28,7 @@ function image_with_size(state, silent) {
if (state.src.charCodeAt(state.pos + 1) !== 0x5B/* [ */) { return false; }
labelStart = state.pos + 2;
labelEnd = mdit.helpers.parseLinkLabel(state, state.pos + 1, false);
labelEnd = md.helpers.parseLinkLabel(state, state.pos + 1, false);
// parser failed to find ']', so it's not a valid link
if (labelEnd < 0) { return false; }
......@@ -52,7 +52,7 @@ function image_with_size(state, silent) {
// [link]( <href> "title" )
// ^^^^^^ parsing link destination
start = pos;
res = mdit.helpers.parseLinkDestination(state.src, pos, state.posMax);
res = md.helpers.parseLinkDestination(state.src, pos, state.posMax);
if (res.ok && state.md.inline.validateLink(res.str)) {
href = res.str;
pos = res.pos;
......@@ -70,7 +70,7 @@ function image_with_size(state, silent) {
// [link]( <href> "title" )
// ^^^^^^^ parsing link title
res = mdit.helpers.parseLinkTitle(state.src, pos, state.posMax);
res = md.helpers.parseLinkTitle(state.src, pos, state.posMax);
if (pos < max && start !== pos && res.ok) {
title = res.str;
pos = res.pos;
......@@ -130,7 +130,7 @@ function image_with_size(state, silent) {
if (pos < max && state.src.charCodeAt(pos) === 0x5B/* [ */) {
start = pos + 1;
pos = mdit.helpers.parseLinkLabel(state, pos);
pos = md.helpers.parseLinkLabel(state, pos);
if (pos >= 0) {
label = state.src.slice(start, pos++);
} else {
......@@ -183,13 +183,16 @@ function image_with_size(state, silent) {
state.pos = pos;
state.posMax = max;
return true;
};
}
function tokenize_imsize(tokens, idx, options, env, self) {
var src = ' src="' + mdit.utils.escapeHtml(tokens[idx].src) + '"';
function tokenize_imsize(md) {
return function(tokens, idx, options, env, self) {
var src = ' src="' + md.utils.escapeHtml(tokens[idx].src) + '"';
var title = '';
if (tokens[idx].title) {
title = ' title="' + mdit.utils.escapeHtml(mdit.utils.replaceEntities(tokens[idx].title)) + '"';
title = ' title="' + md.utils.escapeHtml(md.utils.replaceEntities(tokens[idx].title)) + '"';
}
var alt = ' alt="' + self.renderInlineAsText(tokens[idx].tokens, options, env) + '"';
var width = tokens[idx].width !== '' ? ' width="' + tokens[idx].width + '"' : '';
......@@ -197,9 +200,10 @@ function tokenize_imsize(tokens, idx, options, env, self) {
var size = width + height;
var suffix = options.xhtmlOut ? ' /' : '';
return '<img' + src + alt + title + size + suffix + '>';
};
}
module.exports = function imsize_plugin(md) {
md.renderer.rules.imsize = tokenize_imsize;
md.inline.ruler.before('emphasis', 'imsize', image_with_size);
md.renderer.rules.imsize = tokenize_imsize(md);
md.inline.ruler.before('emphasis', 'imsize', image_with_size(md));
};
{
"name": "markdown-it-imsize",
"version": "0.1.0",
"version": "0.1.2",
"description": "Markdown-it plugin to specify image size",
"main": "index.js",
"scripts": {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment