mirror of
				https://github.com/Jermolene/TiddlyWiki5
				synced 2025-10-31 07:32:59 +00:00 
			
		
		
		
	Allow Markdown dialect to be configured
This commit is contained in:
		| @@ -1,13 +1,34 @@ | |||||||
| title: HelloThere | 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) | [link text](#TiddlerTitle) | ||||||
| ``` | ``` | ||||||
|  |  | ||||||
|  | ! Images | ||||||
|  |  | ||||||
| Markdown image syntax can be used to reference images by tiddler title or an external URI. For example: | 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 | |||||||
|  |  | ||||||
|  |  | ||||||
| ``` | ``` | ||||||
|  |  | ||||||
| To add the plugin to your own TiddlyWiki5, just drag this link to the browser window: |  | ||||||
|  |  | ||||||
| [[$:/plugins/tiddlywiki/markdown]] |  | ||||||
|  |  | ||||||
|   | |||||||
							
								
								
									
										3
									
								
								plugins/tiddlywiki/markdown/dialect.tid
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								plugins/tiddlywiki/markdown/dialect.tid
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,3 @@ | |||||||
|  | title: $:/config/markdown/dialect | ||||||
|  |  | ||||||
|  | Gruber | ||||||
| @@ -14,6 +14,9 @@ Wraps up the markdown-js parser for use in TiddlyWiki5 | |||||||
|  |  | ||||||
| var markdown = require("$:/plugins/tiddlywiki/markdown/markdown.js"); | var markdown = require("$:/plugins/tiddlywiki/markdown/markdown.js"); | ||||||
|  |  | ||||||
|  | var CONFIG_DIALECT_TIDDLER = "$:/config/markdown/dialect", | ||||||
|  | 	DEFAULT_DIALECT = "Gruber"; | ||||||
|  |  | ||||||
| function transformNodes(nodes) { | function transformNodes(nodes) { | ||||||
| 	var results = []; | 	var results = []; | ||||||
| 	for(var index=0; index<nodes.length; index++) { | 	for(var index=0; index<nodes.length; index++) { | ||||||
| @@ -52,7 +55,8 @@ function transformNode(node) { | |||||||
| } | } | ||||||
|  |  | ||||||
| var MarkdownParser = function(type,text,options) { | 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)); | 	this.tree = transformNodes(markdownTree.slice(1)); | ||||||
| }; | }; | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Jermolene
					Jermolene