1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-06-25 06:43:15 +00:00

Allow Markdown dialect to be configured

This commit is contained in:
Jermolene 2014-08-27 11:09:59 +01:00
parent 13c4e028b1
commit 32b795452f
3 changed files with 31 additions and 8 deletions

View File

@ -1,13 +1,34 @@
title: HelloThere
This is a demo of TiddlyWiki5 incorporating a plugin for the [[markdown-js|https://github.com/evilstreak/markdown-js]] Markdown parser from Dominic Baggott.
This is a demo of TiddlyWiki5 incorporating a plugin for the [[markdown-js|https://github.com/evilstreak/markdown-js]] Markdown parser from Dominic Baggott. The MarkdownExample tiddler below is written in Markdown.
The MarkdownExample tiddler below is written in Markdown. Create wiki links with the usual Markdown link syntax targeting `#` and the target tiddler title:
! Installation
To add the plugin to your own TiddlyWiki5, just drag this link to the browser window:
[[$:/plugins/tiddlywiki/markdown]]
! Markdown Dialects
By default the markdown parser recognises the original dialect of Markdown [[as described by John Gruber|http://daringfireball.net/projects/markdown/]]. An extended dialect called "Maruku" is also included that provides table support and other advanced features. The syntax extensions are modelled on those of [[PHP Markdown Extra|https://michelf.ca/projects/php-markdown/extra/]].
The configuration tiddler [[$:/config/markdown/dialect]] determines which dialect is used:
|!Dialect |!Description |
|Gruber |Standard Markdown |
|Maruku |Extended Maruku Markdown |
! Creating ~WikiLinks
Create wiki links with the usual Markdown link syntax targeting `#` and the target tiddler title:
```
[link text](#TiddlerTitle)
```
! Images
Markdown image syntax can be used to reference images by tiddler title or an external URI. For example:
```
@ -15,8 +36,3 @@ Markdown image syntax can be used to reference images by tiddler title or an ext
![alt text](Motovun Jack.jpg "Title")
```
To add the plugin to your own TiddlyWiki5, just drag this link to the browser window:
[[$:/plugins/tiddlywiki/markdown]]

View File

@ -0,0 +1,3 @@
title: $:/config/markdown/dialect
Gruber

View File

@ -14,6 +14,9 @@ Wraps up the markdown-js parser for use in TiddlyWiki5
var markdown = require("$:/plugins/tiddlywiki/markdown/markdown.js");
var CONFIG_DIALECT_TIDDLER = "$:/config/markdown/dialect",
DEFAULT_DIALECT = "Gruber";
function transformNodes(nodes) {
var results = [];
for(var index=0; index<nodes.length; index++) {
@ -52,7 +55,8 @@ function transformNode(node) {
}
var MarkdownParser = function(type,text,options) {
var markdownTree = markdown.toHTMLTree(text);
var dialect = options.wiki.getTiddlerText(CONFIG_DIALECT_TIDDLER,DEFAULT_DIALECT),
markdownTree = markdown.toHTMLTree(text,dialect);
this.tree = transformNodes(markdownTree.slice(1));
};