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

Use showdown.js in QML meet some problem #246

Closed
qyvlik opened this issue Mar 19, 2016 · 4 comments
Closed

Use showdown.js in QML meet some problem #246

qyvlik opened this issue Mar 19, 2016 · 4 comments
Assignees
Labels

Comments

@qyvlik
Copy link

qyvlik commented Mar 19, 2016

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.

@tivie tivie self-assigned this Jun 21, 2016
@tivie tivie added the bug label Jun 21, 2016
@tivie
Copy link
Member

tivie commented Jun 21, 2016

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

This should be fixed now.

@qyvlik
Copy link
Author

qyvlik commented Jun 21, 2016

@tivie Thank for reply. That's nice.

@tivie
Copy link
Member

tivie commented Jul 21, 2016

SInce it seems fixed, closing the issue

@tivie tivie closed this as completed Jul 21, 2016
@qyvlik
Copy link
Author

qyvlik commented Feb 5, 2017

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

@tivie tivie reopened this Feb 5, 2017
@tivie tivie closed this as completed Feb 5, 2017
tivie added a commit that referenced this issue Feb 5, 2017
QML has a bug that changes the behavior or String.search().
This prevents blocks from being correctly unhashified.
This commit works around that bug, using RegExp.test
instead of String.search.
Credits to @qyvlik

Closes #246, Closes #338
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants