Showdown: Use showdown.js in QML meet some problem

Created on 19 Mar 2016  路  4Comments  路  Source: showdownjs/showdown

Hi!

QML is declaration language that support EMCAScript(version 5.0).

So QML can use some JavaScript Lab, look here to show how to use.

follow is my code to use showdown.js in qml

In QML file:

import "showdown.js" as ShowDown     // such as HTML <script>
import QtQuick 2.0
Item {

}

In showdown.js, I make a change such as follow:

var ShowdownJar = {};
;/*! showdown 02-02-2016 */
(function(){
/**
 * Created by Tivie on 13-07-2015.
 */

...


// CommonJS/nodeJS Loader
if (typeof module !== 'undefined' && module.exports) {
  module.exports = showdown;

// AMD Loader
} else if (typeof define === 'function' && define.amd) {
  define(function () {
    // 'use strict';
    return showdown;
  });

// Regular Browser loader
} else {
  root.showdown = showdown;
  // In QML env.
  ShowDownJar.showdown = showdown;
}
}).call(this);

//# sourceMappingURL=showdown.js.map

var ShowDown = ShowDownJar.showdown;
var Converter = ShowDown.Converter;

var converter = new ShowDown.Converter();

console.log(converter.makeHtml('# title'))   // fail
//console.log(converter.makeHtml('- Label')) // fail
//console.log(converter.makeHtml('+ Label')) // fail
//console.log(converter.makeHtml('* Label'))  // fail
//console.log(converter.makeHtml('![pic](![Showdown][sd-logo])')) // OK
//console.log(converter.makeHtml('`console.log()`')) // OK

But, I meet some problem that some code throw Error in showdown.subParser 'paragraphs'. The error is TypeError: Cannot read property 'codeblock' of undefined.

I log the globals.ghCodeBlocks in showdown.js:2198 , and it log is a [].

Then I debug in browser, and log the showdown.subParser stack track.(test code is converter.makeHtml('# title')).

detab
stripBlankLines
hashPreCodeTags
githubCodeBlocks
hashHTMLBlocks
hashElement
hashElement
hashElement
hashHTMLSpans
stripLinkDefinitions
blockGamut
blockQuotes
headers
spanGamut
codeSpans
escapeSpecialCharsWithinTagAttributes
encodeBackslashEscapes
images
anchors
autoLinks
encodeAmpsAndAngles
italicsAndBold
strikethrough
hashBlock
hashBlock
lists
codeBlocks
tables
hashHTMLBlocks
hashElement
hashElement
hashElement
paragraphs
unhashHTMLSpans
unescapeSpecialChars

the follow log is debug in qml:

detab
stripBlankLines
hashPreCodeTags
githubCodeBlocks
hashHTMLBlocks
hashElement
hashElement
hashElement
hashHTMLSpans
stripLinkDefinitions
blockGamut
blockQuotes
headers
spanGamut
codeSpans
escapeSpecialCharsWithinTagAttributes
encodeBackslashEscapes
images
anchors
autoLinks
encodeAmpsAndAngles
italicsAndBold
strikethrough
hashBlock
hashBlock
lists
codeBlocks
tables
hashHTMLBlocks
hashElement
hashElement
hashElement
paragraphs

In QML env lost some step.

bug

All 4 comments

I've figure out the problem. Line endings were getting "altered" prior to npm release.

This should be fixed now.

@tivie Thank for reply. That's nice.

SInce it seems fixed, closing the issue

In browser:

'篓K0K'.search(/篓(K|G)(\d+)\1/);
RegExp.$1;        // result is "K"

But in QML:

'篓K0K'.search(/篓(K|G)(\d+)\1/);
RegExp.$1;        // result is ""

So, in showdown.js file line: 2382

    // if this is a marker for an html block...
    while (grafsOutIt.search(/篓(K|G)(\d+)\1/) >= 0) {
      var delim = RegExp.$1,         // difference between qml and browser
          num   = RegExp.$2;
     ...
    }

the resolution:

    //: [0] QTBUG-58638
    while (/篓(K|G)(\d+)\1/.test(grafsOutIt)) {
    //: [0] QTBUG-58638
        ...
    }

Is QML bug. QTBUG-58638

@tivie

Was this page helpful?
0 / 5 - 0 ratings

Related issues

DesignResponds picture DesignResponds  路  3Comments

JerryYangJin picture JerryYangJin  路  7Comments

andistuder picture andistuder  路  5Comments

Ehesp picture Ehesp  路  3Comments

ifeltsweet picture ifeltsweet  路  6Comments