Skip to content

Commit 6c739a8

Browse files
author
my0n
committed
Initial commit
0 parents  commit 6c739a8

File tree

3 files changed

+75
-0
lines changed

3 files changed

+75
-0
lines changed

plugin.info.txt

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
base marginnotes
2+
author my0n
3+
4+
date 2019-11-23
5+
name marginnotes plugin
6+
desc Display notes in the margin using <mnote>

style.css

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.marginnote {
2+
left: -17.5em;
3+
position: absolute;
4+
width: 16em;
5+
background-color: #feff9c;
6+
box-shadow: inset -0.3em 0 4px -4px #bbb, -0.125em 0 0.5em -0.25em #777;
7+
padding: 0.5em 0.5em 0.5em 1em;
8+
border-radius: 0.25em 0 0 0.25em;
9+
}

syntax.php

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
if(!defined('DOKU_INC')) die();
3+
require_once(DOKU_PLUGIN.'syntax.php');
4+
5+
class syntax_plugin_marginnotes extends DokuWiki_Syntax_Plugin {
6+
public function getPluginName() {
7+
return $this->getInfo()['base'];
8+
}
9+
10+
public function connectTo($mode) {
11+
$this->Lexer->addEntryPattern('<mnote>(?=.*</mnote>)', $mode, 'plugin_' . $this->getPluginName());
12+
}
13+
14+
public function postConnect() {
15+
$this->Lexer->addExitPattern('</mnote>', 'plugin_' . $this->getPluginName());
16+
}
17+
18+
function getSort() {
19+
return 69;
20+
}
21+
22+
function getType() {
23+
return 'protected';
24+
}
25+
26+
function getPType(){
27+
return 'block';
28+
}
29+
30+
function handle($match, $state, $pos, Doku_Handler $handler) {
31+
switch ($state) {
32+
case DOKU_LEXER_UNMATCHED:
33+
return [
34+
'state' => $state,
35+
'match' => $match,
36+
'pos' => $pos - strlen('<mnote>'),
37+
];
38+
}
39+
40+
return [
41+
'state' => $state
42+
];
43+
}
44+
45+
function render($mode, Doku_Renderer $renderer, $data) {
46+
switch ($data['state']) {
47+
case DOKU_LEXER_ENTER:
48+
$renderer->doc .= '<div class="marginnote">';
49+
break;
50+
case DOKU_LEXER_UNMATCHED:
51+
$renderer->doc .= '<span>' . $data['match'] . '</span>';
52+
break;
53+
case DOKU_LEXER_EXIT:
54+
$renderer->doc .= '</div>';
55+
break;
56+
}
57+
58+
return true;
59+
}
60+
}

0 commit comments

Comments
 (0)