PluginMarkdown
in package
NacoWiki MarkDown
This plugin is used to provide Markdown functionality to NacoWiki. It provides the following:
- Markdown renderer with extended syntax.
- CodeMirror for editor.
- Allows the inclusion of a YAML block at the beginning to store meta data.
Meta data
Meta data is stored in a block at the top of the file of the form:
---
title: sample block
date: "2023-03-02"
---
Only the title
attribute is used by NacoWiki. But any data can be stored in the
YAML block.
Markup
In addition to Parsedown and ParsedownExtra markup it adds the following extensions:
- checkboxes in lists [x] and [ ] markup
- table span. See markup
-
~~
~~strike-through~~ (del) -
++
++insert++ (ins) -
^^
^^superscript^^ (sup) -
,,
,,subscript,, (sub) -
==
==keyboard== (kbd) -
??
??highlight?? (mark) - "\" at the end of the line to generate a line break
- Links ending with
^
will open in a new window. - headown
- header html tags in the content start at H2 (since H1 is used by the wiki's document title.
-
#++
and#--
is used to increment headown level. (Use this in combination with file includes.
- diagrams in fenced code blocks.
- Adding to a fenced code block a tag such as:
- graphviz-dot
- graphviz-neato
- graphviz-fdp
- graphviz-sfdp
- graphviz-twopi
- graphviz-circo
-
lineart
orbob
oraafigure
: parsed using svgbob
- This will render the given code as a SVG.
- Adding to a fenced code block a tag such as:
- Allows the use of fenced code blocks with tags to allow for syntax highlighting.
- Lines begining with ```tag
where
tag
is a language for syntax highlighting.
- Lines begining with ```tag
where
- Markdown libraries:
- Parsedown
- PardownExtra
-
[toc]
tag implemented using the TOC extension but tweaked to allow for case insensitive tags.
- Unordered list are tweaked to my personal preferences.
Tags
Table of Contents
Constants
- VERSION = '2.0.0'
- var string
Methods
- edit() : bool|null
- Edit event handler
- load() : void
- Loading entry point for this class
- makeSource() : string
- Formats metadata and Markdown content
- preSave() : bool|null
- preSave event handler
- read() : bool|null
- Read event handler
- readStruct() : string
- Read structured data
- render() : bool|null
- Render event handler
Constants
VERSION
var string
public
mixed
VERSION
= '2.0.0'
Methods
edit()
Edit event handler
public
static edit(NanoWikiApp $wiki, array<string|int, mixed> &$data) : bool|null
Handles edit:[ext]
events.
It creates a page with CodeMirror configured in Markdown mode.
Parameters
- $wiki : NanoWikiApp
-
running wiki instance
- $data : array<string|int, mixed>
Return values
bool|nullload()
Loading entry point for this class
public
static load(array<string|int, mixed> $cfg) : void
Hooks Markdown media implemented by this class
Parameters
- $cfg : array<string|int, mixed>
makeSource()
Formats metadata and Markdown content
public
static makeSource(array<string|int, mixed> $meta, string $body) : string
Formats the file contents to have a metadata in a YAML block at the top, followed by Markdown content right afterwards.
Parameters
- $meta : array<string|int, mixed>
- $body : string
-
Markdown payload
Return values
string —full file with YAML block and Markdown content
preSave()
preSave event handler
public
static preSave(NanoWikiApp $wiki, array<string|int, mixed> &$ev) : bool|null
Handles preSave:[ext]
events.
Reads from the submitted text and modifes it to make sure that there is a YAML block followed by the Markdown text.
This makes the saved file in a consistent format.
Parameters
- $wiki : NanoWikiApp
-
running wiki instance
- $ev : array<string|int, mixed>
-
passed event
Return values
bool|nullread()
Read event handler
public
static read(NanoWikiApp $wiki, array<string|int, mixed> &$ev) : bool|null
Handles read:[ext]
events.
Reads the file extract meta data tags from the YAML block and separates the Markdown content.
Parameters
- $wiki : NanoWikiApp
-
running wiki instance
- $ev : array<string|int, mixed>
-
passed event
Return values
bool|nullreadStruct()
Read structured data
public
static readStruct(string $source, array<string|int, mixed> &$meta) : string
Extracts meta data from the YAML from matter at the beginning of the file. And the MarkDown source right after.
Parameters
- $source : string
-
text to process
- $meta : array<string|int, mixed>
-
receives the read meta data
Return values
string —Returns Markdown payload
render()
Render event handler
public
static render(NanoWikiApp $wiki, array<string|int, mixed> &$ev) : bool|null
Handles render:[ext]
events.
Convert Markdown to HTML
Parameters
- $wiki : NanoWikiApp
-
running wiki instance
- $ev : array<string|int, mixed>
-
passed event