PHP Classes

File: test_markdown_parser.php

Recommend this page to a friend!
  Classes of Manuel Lemos   PHP Markdown Parser   test_markdown_parser.php   Download  
File: test_markdown_parser.php
Role: Example script
Content type: text/plain
Description: Test markdown parser class
Class: PHP Markdown Parser
Parse Markdown documents and generate HTML tags
Author: By
Last change:
Date: 9 years ago
Size: 2,023 bytes
 

Contents

Class file image Download
<?php
/*
 * test_markdown_parser.php
 *
 * @(#) $Id: test_markdown_parser.php,v 1.4 2012/11/18 05:18:41 mlemos Exp $
 *
 */

   
require_once('markdown_parser.php');

   
$message_file = ((IsSet($_SERVER['argv']) && count($_SERVER['argv'])>1) ? $_SERVER['argv'][1] : 'test/sample/sample.md');
   
$markdown=new markdown_parser_class;

   
/* Set to 1 if the you need to track line numbers of errors or element
     * positions
     */
   
$markdown->track_lines = 1;

   
$parameters=array(
       
'File'=>$message_file,

       
/* Read a markdown from a string instead of a file */
        /* 'Data'=>'Markdown data here', */
   
);

/*
 * The following lines are for testing purposes.
 * Remove these lines when adapting this example to real applications.
 */
   
if(defined('__TEST'))
    {
        if(IsSet(
$__test_options['parameters']))
           
$parameters = $__test_options['parameters'];
       
$markdown->buffer_length = (IsSet($__test_options['buffer_length']) ? $__test_options['buffer_length'] : 8000);
       
$markdown->track_lines = (IsSet($__test_options['track_lines']) ? $__test_options['track_lines'] : 0);
    }

    if((
$success = $markdown->StartParsing($parameters)))
    {
        do
        {
            if(!(
$success = $markdown->Parse($end, $elements)))
                break;
           
$te = count($elements);
            for(
$e = 0; $e < $te; ++$e)
               
var_dump($elements[$e]);
        }
        while(!
$end);
        if(
$success)
           
$success = $markdown->FinishParsing();
    }
    if(!
$success)
    {
        echo
'Markdown parsing error: '.$markdown->error.' at position '.$markdown->error_position;
        if(
$markdown->track_lines
       
&& $markdown->GetPositionLine($markdown->error_position, $line, $column))
            echo
' line '.$line.' column '.$column;
        echo
"\n";
    }
    for(
$warning = 0, Reset($markdown->warnings); $warning < count($markdown->warnings); Next($markdown->warnings), $warning++)
    {
       
$w = Key($markdown->warnings);
        echo
'Warning: ', $markdown->warnings[$w], ' at position ', $w;
        if(
$markdown->track_lines
       
&& $markdown->GetPositionLine($w, $line, $column))
            echo
' line '.$line.' column '.$column;
        echo
"\n";
    }
?>