cincheo/jsweet-examples

Markdown example

Closed this issue · 3 comments

mb720 commented

Hi!

I'd like to contribute an example that uses Showdown for converting Markdown to HTML in the browser. A simplified version of this, if you will.

This is what I've done so far:

I source both MarkdownExample.js and showdown.js in index.html.

Still, I get a ReferenceError: Showdown is not defined when opening index.html.

Any help is very much appreciated.

To run my fork of jsweet-examples, you can

git clone git@github.com:mb720/jsweet-examples.git
cd jsweet-examples
./gradlew jsweet

Hi!
This looks like a very cool initiative and contribution. Thanks a lot.
I don't see anything wrong with your approach.

On the other hand, I see a problem in the showdown definition file in definitelytyped because it seems to me that it is made for using the showdown lib with modules (commonjs or amd). What makes me say this is that I have tried to use showdown directly with TypeScript and I get the same error...

Typically, when I compile with TypeScript the following code, I get the same problem:

namespace org.jsweet.examples.markdown {
    import Converter = Showdown.Converter;

    /**
     * Lets the user enter text and converts it from Markdown to HTML.
     * Created by Matthias Braun on 6/25/2016.
     */
    export class MarkdownExample {
        private markdownConverter : Converter = new Converter();

        public constructor() {
            var form : HTMLFormElement = <HTMLFormElement>document.querySelector("form");
            var markdownInput : HTMLInputElement = <HTMLInputElement>form.querySelector("#markdownInput");
            this.addHitListener(markdownInput);
        }

        public static main(...args : string[]) {
            new MarkdownExample();
        }

        private addHitListener(element : HTMLInputElement) {
            element.addEventListener("keyup", (evt) => {
                var text : string = element.value;
                console.info("Text: " + text);
                var html : string = this.markdownConverter.makeHtml(text);
                console.info("Text as HTML: " + html);
            });
        }
    }
}

Of course if I try to replace import Converter = Showdown.Converter; with import Converter = showdown.Converter;, I get a compilation error.

IMO, we should first try to see what's wrong with TypeScript/DefinitelyTyped to understand what can be done with JSweet.

Still thinking about it... any input could help.

Thanks!

My analysis is confirmed by the showdown test file on definitelytyped...

https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/showdown/showdown-tests.ts

I am pretty sure that the definition is for the server-side (node) version. Maybe the first question to be answered is whether a client-side definition file exists.

I have created an issue on what seems to be the original repo. we will see what happens... https://github.com/retyped/showdown-tsd-ambient/issues/1

The Marked candy is available with JSweet 2. See https://github.com/jsweet-candies.