Giter Club home page Giter Club logo

php-ext-hoedown's Introduction

PHP Extension for Hoedown

Build Status

This extension allows Hoedown.

Build

% phpize
% ./configure
% make
% make test
% make install

Configration

hoedown.ini:

extension=hoedown.so

Usage

$hoedown = new Hoedown;
echo $hoedown->parse('markdown text');

Runtime Configuration

Name Default Changeable
hoedown.disable_default_options 0 PHP_INI_ALL
  • hoedown.disable_default_options

    It does not set the valid options for default of Hoedown class if you have to On.

    • Hoedown::TABLES
    • Hoedown::FENCED_CODE
    • Hoedown::AUTOLINK
    • Hoedown::STRIKETHROUGH
    • Hoedown::NO_INTRA_EMPHASIS

Class synopsis

Hoedown {
  public __construct(array $options = [])
  public mixed getOption(int $option)
  public bool setOption(int $option, mixed $value)
  public void setOptions(array $options = [])
  public string parse(string $string, mixed &$state = NULL)
  public string parseString(string $string, mixed &$state = NULL)
  public string parseFile(string $filename, mixed &$state = NULL)
  static public string ofString(string $string, array $options = [], mixed &$state = NULL)
  static public string ofFile(string $filename, array $options = [], mixed &$state = NULL)
}

Predefined Constants

Name Type Default Description
Hoedown::RENDERER_HTML bool TRUE Render HTML
Hoedown::RENDERER_TOC bool FALSE Render the Table of Contents in HTML
Hoedown::SKIP_HTML bool FALSE Strip all HTML tags
Hoedown::SKIP_STYLE bool FALSE Stripg <style> tags
Hoedown::SKIP_IMAGES bool FALSE Don't render images
Hoedown::SKIP_LINKS bool FALSE Don't render links
Hoedown::SAFELINK bool FALSE Only allow links to safe protocols
Hoedown::TOC bool FALSE Produce links to the Table of Contents
Hoedown::HARD_WRAP bool FALSE Render each linebreak as <br>
Hoedown::USE_XHTML bool FALSE Render XHTML
Hoedown::ESCAPE bool FALSE Escaple all HTML
Hoedown::TASK_LIST bool FALSE Render task lists
Hoedown::LINE_CONTINUE bool FALSE Render line continue
Hoedown::TABLES bool TRUE Parse PHP-Markdown style tables
Hoedown::FENCED_CODE bool TRUE Parse fenced code blocks
Hoedown::FOOTNOTES bool FALSE Parse footnotes
Hoedown::AUTOLINK bool TRUE Automatically turn URLs into links
Hoedown::STRIKETHROUGH bool TRUE Parse ~~strikethrough~~ spans
Hoedown::UNDERLINE bool FALSE Parse _underline_ instead of emphasis
Hoedown::HIGHLIGHT bool FALSE Parse ==hightlight== spans
Hoedown::QUOTE bool FALSE Render "quotes" as <q>
Hoedown::SUPERSCRIPT bool FALSE Parse super^script
Hoedown::NO_INTRA_EMPHASIS bool TRUE Disable emphasis_between_words
Hoedown::SPACE_HEADERS bool FALSE Requqire a space after '#' in headers
Hoedown::DISABLE_INDENTED_CODE bool FALSE Don't parse indented code blocks
Hoedown::SPECIA\L_ATTRIBUTE bool FALSE Parse special attributes
Hoedown::TOC_BEGIN int 0 Begin level for headers included in the TOC.
Hoedown::TOC_END int 6 End level for headers included in the TOC.
Hoedown::TOC_ESCAPE bool TRUE Escape int the TOC
Hoedown::TOC_HEADER string "" Render header in the TOC
Hoedown::TOC_FOOTER string "" Render footer in the TOC
Hoedown::CLASS_LIST string "" Render class attribute in the list
Hoedown::CLASS_ORDER_LIST string "" Render class attribute in the ordered list
Hoedown::CLASS_TASK_LIST string "" Render class attribute in the task list

Methods


Hoedown::__construct

public __construct(array $options = [])

Create a Hoedown instance.

Parameters:

  • options

    An associative array of options where the key is the option to set and the value is the new value for the option.

Return Values:

Returns a new Hoedown object


Hoedown::getOption

public mixed getOption(int $option)

Retrieve a Hoedown option value.

Parameters:

  • option

    One of the Hoedown::* constants.

Return Values:

Returns the value of the requested option, or FALSE on error.


Hoedown::setOption

public bool setOption(int $option, mixed $value)

Set Hoedown option.

Parameters:

  • option

    One of the Hoedown::* constants.

  • value

    Set option value.

Return Values:

Returns TRUE on success or FALSE on failure.


Hoedown::setOptions

public void setOptions(array $options = [])

Set Hoedown options.

Parameters:

  • options

    An associative array of options where the key is the option to set and the value is the new value for the option.


Hoedown::parse

public string parse(string $string, mixed &$state = NULL)

retrieve html by parse text as markdown.

Parameters:

  • string

    Markdown text string.

  • state

    Returns the value of extend parse.

Return Values:

Returns the retrieve html, or FALSE on error.


Hoedown::parseString

public string parseString(string $string, mixed &$state = NULL)

retrieve html by parse string as markdown.

alias: Hoedown::parse


Hoedown::parseFile

public string parseFile(string $filename, mixed &$state = NULL)

retrieve html by parse file as markdown.

Parameters:

  • filename

    Markdown file name.

  • state

    Returns the value of extend parse.

Return Values:

Returns the retrieve html, or FALSE on error.


Hoedown::ofString

static public string ofString(string $string, array $options = [], mixed &$state = NULL)

retrieve html by parse string as markdown (static method).

Parameters:

  • string

    Markdown text string.

  • options

    An associative array of options where the key is the option to set and the value is the new value for the option.

  • state

    Returns the value of extend parse.

Return Values:

Returns the retrieve html, or FALSE on error.


Hoedown::ofFile

static public string ofFile(string $filename, array $options = [], mixed &$state = NULL)

retrieve html by parse file as markdown (static method).

Parameters:

  • filename

    Markdown file name.

  • options

    An associative array of options where the key is the option to set and the value is the new value for the option.

  • state

    Returns the value of extend parse.

Return Values:

Returns the retrieve html, or FALSE on error.

Examples

  • Setting a Hoedown option
$hoedown = new Hoedown;
$hoedown->setOption(Hoedown::USE_XHTML, true);
$hoedown->setOption(Hoedown::HARD_WRAP, true);
// or $hoedown->setOptions([Hoedown::USE_XHTML => true, Hoedown::HARD_WRAP => true]);
// or new Hoedown([Hoedown::USE_XHTML => true, Hoedown::HARD_WRAP => true]);
echo $hoedown->parse("markdown\ntext");

The above example will output:

<p>markdown<br/>
text</p>
  • Retrieve the Table of Contents
$hoedown = new Hoedown;
$hoedown->setOption(Hoedown::TOC, true);
echo $hoedown->parse("# header\n##a\n##b", $state);
echo "-- Table of Contents --\n";
echo $state['toc'];

The above example will output:

<h1 id="toc_header">header</h1>

<h2 id="toc_a">a</h2>

<h2 id="toc_b">b</h2>
-- Table of Contents --
<ul>
<li>
<a href="#toc_header">header</a>
<ul>
<li>
<a href="#toc_a">a</a>
</li>
<li>
<a href="#toc_b">b</a>
</li>
</ul>
</li>
</ul>

Only retrieve the Table of Contents.

$hoedown = new Hoedown;
$hoedown->setOption(Hoedown::TOC, true);
$hoedown->setOption(Hoedown::RENDERER_TOC, true);
echo $hoedown->parse("# header\n##a\n##b");

The above example will output:

<ul>
<li>
<a href="#toc_header">header</a>
<ul>
<li>
<a href="#toc_a">a</a>
</li>
<li>
<a href="#toc_b">b</a>
</li>
</ul>
</li>
</ul>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.