Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

General Discussion

Creating a Writing application

Hi,

I am creating a simple Markdown styled writing application whit PHP and Javascript. But I can't figure out what element to use for the writing part. It needs to be a full page writing application that works like Markdown. But I don't know do i need to use a Canvas element or iFrame, Textarea or something different.

And how would I create a match system if some text begins whit # it would wrap it in a <h1> html element.

Example: #This is a level one heading. = <h1>This is a level one heading </h1>

1 Answer

Markdown interpretation can involve a lot of logics that you just have to tackle one step at a time. The initial user interface probably just accepts plain text input via a textarea. Then your backend/javascript interpreter can just parse the text as needed and return the result as embedded code in whatever element you find appropriate.

For your example, a way to parse a simple mark down like #-><h1> it would be to break the entire text by line (\n) or by paragraphs (\n\n) and check if it begins with #, then do the appropriate substitution. For more complicated markdowns, you would need to use regular expression.