Skip to content
Snippets Groups Projects
Select Git revision
  • 59bcdc78cf230212a46a5c5fcfefd7ff00421d3d
  • upstream default protected
  • master
3 results

index.js

Blame
  • index.js 5.89 KiB
    // Process ![test]( x =100x200)
    //                    ^^^^^^^^ this size specification
    
    'use strict';
    
    var parseImageSize = require('./helpers/parse_image_size');
    var normalizeReference = require('./helpers/normalize_reference.js');
    
    function image_with_size(md) {
      return function(state, silent) {
        var code,
            href,
            label,
            labelEnd,
            labelStart,
            pos,
            ref,
            res,
            title,
            width = '',
            height = '',
            tokens,
            start,
            oldPos = state.pos,
            max = state.posMax;
    
        if (state.src.charCodeAt(state.pos) !== 0x21/* ! */) { return false; }
        if (state.src.charCodeAt(state.pos + 1) !== 0x5B/* [ */) { return false; }
    
        labelStart = state.pos + 2;
        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; }
    
        pos = labelEnd + 1;
        if (pos < max && state.src.charCodeAt(pos) === 0x28/* ( */) {
    
          //
          // Inline link
          //
    
          // [link](  <href>  "title"  )
          //        ^^ skipping these spaces
          pos++;
          for (; pos < max; pos++) {
            code = state.src.charCodeAt(pos);
            if (code !== 0x20 && code !== 0x0A) { break; }
          }
          if (pos >= max) { return false; }
    
          // [link](  <href>  "title"  )
          //          ^^^^^^ parsing link destination
          start = pos;
          res = md.helpers.parseLinkDestination(state.src, pos, state.posMax);
          if (res.ok && state.md.inline.validateLink(res.str)) {
            href = res.str;
            pos = res.pos;
          } else {
            href = '';
          }
    
          // [link](  <href>  "title"  )
          //                ^^ skipping these spaces
          start = pos;
          for (; pos < max; pos++) {
            code = state.src.charCodeAt(pos);
            if (code !== 0x20 && code !== 0x0A) { break; }
          }