1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-14 13:54:50 +00:00
TiddlyWiki5/editions/dev/tiddlers/from tw5.com/mechanisms/ParsingMechanism.tid

46 lines
1.3 KiB
Plaintext
Raw Normal View History

2012-06-10 16:27:09 +00:00
title: ParsingMechanism
2014-09-11 19:12:25 +00:00
tags: Mechanisms
2013-11-01 15:00:17 +00:00
created: 201311011307
modified: 201311011307
2012-06-10 16:27:09 +00:00
2013-11-01 15:00:17 +00:00
! Introduction
2012-06-10 16:27:09 +00:00
2013-11-01 15:00:17 +00:00
The parsing mechanism analyses the text of a tiddler against a set of parsing rules, producing a tree representing the structure of the text. The RenderingMechanism is used to transform parse trees into render trees of widget nodes.
TiddlyWiki5 includes ParserModules for several types of tiddler:
* WikiText
* Raw HTML
* Plain text
* Images (bitmap, SVG and PDF)
The WikiText parser is the most complex, comprising separate individual WikiRuleModules encapsulating each parsing rule.
! Parse Trees
The output of parsing a tiddler is an object containing a tree of parse nodes corresponding to the original text. For example:
```
> JSON.stringify($tw.wiki.parseText("text/vnd.tiddlywiki","Some //italics// and a {{Transclusion}}.").tree)
[
{type: "element", tag: "p", children: [
{type: "text", text: "Some "},
{type: "element", tag: "em", children: [
{type: "text", text: "italics"}
]},
{type: "text", text: " and a "},
{type: "tiddler", attributes:{
tiddler: {type: "string", value: "Transclusion"}
}, children:[
{type: "transclude", attributes:{
tiddler: {type: "string", value: "Transclusion"}
}}
]},
{type: "text", text: "."}
]}
]
```
Parse tree nodes are plain JavaScript objects, and do not have a prototype.