• How to store a blog post in a database?

     

    When you want to create dynamic blog,  you should store the text in your database in some formatted way. Otherwise you have no way to distinguish between headers and paragraphs.

    A good option is to store the text in Markdown. Markdown is a language created by John Gruber. Here are the rules: http://daringfireball.net/projects/markdown/syntax

    SimpleMDE - Markdown Editor

    A drop-in JavaScript textarea replacement for writing beautiful and understandable Markdown. The WYSIWYG-esque editor allows users who may be less experienced with Markdown to use familiar toolbar buttons and shortcuts. In addition, the syntax is rendered while editing to clearly show the expected result. Headings are larger, emphasized words are italicized, links are underlined, etc. SimpleMDE is one of the first editors to feature both built-in autosaving and spell checking.


    Why not a WYSIWYG editor or pure Markdown?

    WYSIWYG editors that produce HTML are often complex and buggy. Markdown solves this problem in many ways, plus Markdown can be rendered natively on more platforms than HTML. However, Markdown is not a syntax that an average user will be familiar with, nor is it visually clear while editing. In other words, for an unfamiliar user, the syntax they write will make little sense until they click the preview button. SimpleMDE has been designed to bridge this gap for non-technical users who are less familiar with or just learning Markdown syntax.

    Link : https://github.com/sparksuite/simplemde-markdown-editor

    Markdown to HTML(Using  Codeigniter) 

    CI Markdown

    CI Markdown is a modified rendition of Michel Fortin's PHP Markdown and PHP Markdown Extra for CodeIgniter.

    Install

    Requirements

    Download

    Download and extract the zip release to your CoddeIgniter application/libraries/ directory.

    The extracted path should resemble:

    • application/libraries/Markdown.php

    Usage

    Configuration

    Custom PHP Markdown settings are defined in the config/markdown.php config file.

    Initializing the Markdown Class

    Like most other classes in CodeIgniter, initialize it from your controller using the $this->load->library() method:

    $this->load->library('markdown');

    To programmatically configure the Markdown instance, overriding any matched settings defined in the config file:

    $config = array(
        'tab_width' => 2,
        'no_markup' => true,
        'empty_element_suffix' => '/>'
    );
    
    $this->load->library('markdown', $config);

    Markdown to HTML

    • $this->markdown->parse()

    Accepts a single string parameter of Markdown text and returns the parsed HTML.

    $this->load->library('markdown');
    
    $markdownText = "# Heading "."\n\n"."## Sub-heading"."\n\n";
    echo $this->markdown->parse($markdownText);
    //>>> <h1>Heading</h1><h2>Sub-heading</h2>

    Markdown File to HTML

    • $this->markdown->parse_file()

    Accepts a single string parameter for a Markdown file path and returns the parsed HTML.

    $this->load->library('markdown');
    
    echo $this->markdown->parse_file('/path/to/markdown/file.md');
    //>>> <h1>CI Markdown</h1><p>CI Markdown is a modified rendition...</p>


  • 0 comments:

    Post a Comment

    FAVOURITE LINE

    To steal ideas from one is plagiarism. To steal from many is Research.

    ADDRESS

    Mumbai , Maharashtra

    EMAIL

    shikha.pathak6@gmail.com
    shikha.the.swt.pari@gmail.com

    Skype

    shikha_pari