-
Notifications
You must be signed in to change notification settings - Fork 0
/
TMarqueur.images.php
77 lines (52 loc) · 1.52 KB
/
TMarqueur.images.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php namespace TMarqueur\Images;
/**
||TMarqueur|| is an alternative lightweight markup language
for creating formatted text using a plain-text editor.
||TMarqueur.php|| converts TMarqueur document to HTML.
||TMarqueur.images.php|| adds a variant to the preformated
code block to convert its content into a HTML images.
Example :
```````````````` image 1.2.3 ```````````````
http://www.example.com/url_image.jpg
ASCII art version
Alternative description of the image
````````````````````````````````````````````
*/
\TMarqueur\plug_block_variant( '`' , [
'type' => 'image' ,
'test_attribute' => 'lang' ,
'detector' => '/^image[ ]*(.*)$/i' ,
'tags' => [ 'div class="image-div"' ] , // TODO add support for class
'attr' => [ 'title' ] ,
'formating' => false ,
'callback' => function( $_content , $_attributes )
{
$pos_ = 0 ;
$url_ = '';
$alt_ = '';
$content_len = strlen( $_content );
$line_count_ = 0 ;
while( $pos_ < $content_len )
{
$len_ = \TMarqueur\line_byte_length_at( $_content , $pos_ );
$line_ = substr( $_content , $pos_ , $len_ );
$line_ = str_replace( ' ' , ' ' , $line_ );
$line_ = trim( $line_ );
$line_len = strlen( $line_ );
if ( $line_count_ == 0 )
{
$url_ = $line_ ;
}
else
{
$alt_ = $line_ ;
}
$pos_ += $len_ ;
if ( $_content[ $pos_ ] == "\r" ) $pos_++;
if ( $_content[ $pos_ ] == "\n" ) $pos_++;
$line_count_++;
}
return '<img src="'.rawurlencode($url_).'" alt="'.htmlentities($alt_).'">'.PHP_EOL;
}
]);
// EOF