Skip to content
This repository has been archived by the owner on May 27, 2020. It is now read-only.

Commit

Permalink
Revert "Attempted node renderer"
Browse files Browse the repository at this point in the history
This reverts commit d98563d.
  • Loading branch information
anstosa committed Mar 12, 2018
1 parent d98563d commit e0b0ef8
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 68 deletions.
1 change: 0 additions & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,3 @@ cp node_modules/markdown-it/dist/markdown-it.min.js files/
cp node_modules/markdown-it-task-checkbox/index.js files/markdown-it-checkbox.min.js
cp node_modules/highlightjs/highlight.pack.min.js files/
cp node_modules/highlightjs/styles/github.css files/
cp node_modules/htmlparser/lib/htmlparser.min.js files/
22 changes: 0 additions & 22 deletions files/htmlparser.min.js

This file was deleted.

6 changes: 0 additions & 6 deletions files/node-htmlparser.min.js

This file was deleted.

8 changes: 0 additions & 8 deletions files/tiddlywiki.files
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,6 @@
"title": "$:/plugins/anstosa/tw5-markdown/markdown-checkbox.js",
"module-type": "library"
}
},
{
"file": "htmlparser.min.js",
"fields": {
"type": "application/javascript",
"title": "$:/plugins/anstosa/tw5-markdown/htmlparser.js",
"module-type": "library"
}
}
]
}
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
{
"name": "tw5-markdown",
"version": "1.1.1",
"version": "1.1.4",
"private": true,
"scripts": {
"build": "./build.sh"
},
"dependencies": {
"highlightjs": "^9.10.0",
"htmlparser": "^1.7.7",
"markdown-it": "^8.4.0",
"markdown-it-task-checkbox": "^1.0.4"
}
Expand Down
2 changes: 1 addition & 1 deletion plugin.info
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"title": "$:/plugins/anstosa/tw5-markdown",
"description": "Markdown",
"author": "Ansel Santosa",
"version": "1.1.3",
"version": "1.1.4",
"core-version": ">=5.0.0",
"source": "https://github.com/anstosa/tw5-markdown",
"plugin-type": "plugin",
Expand Down
43 changes: 15 additions & 28 deletions wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ Wraps up the markdown-it parser for use in TiddlyWiki5

const TYPE_WIKI = 'text/vnd.tiddlywiki';

let dom;
if (typeof(window) !== 'undefined') {
dom = new DOMParser();
}
const highlight = require('$:/plugins/anstosa/tw5-markdown/highlight.js');
const htmlparser = require('$:/plugins/anstosa/tw5-markdown/htmlparser.js');
const MarkdownIt = require('$:/plugins/anstosa/tw5-markdown/markdown.js');
const markdown = new MarkdownIt({
highlight: (source, syntax) => {
Expand All @@ -34,10 +37,10 @@ Wraps up the markdown-it parser for use in TiddlyWiki5
});

const tiddlify = (node, forceText) => {
if (node.type === 'text') {
if (node.nodeType === Node.TEXT_NODE) {
let subtree;
try {
const children = new $tw.Wiki.parsers[TYPE_WIKI](TYPE_WIKI, node.data, {}).tree[0].children;
const children = new $tw.Wiki.parsers[TYPE_WIKI](TYPE_WIKI, node.textContent, {}).tree[0].children;
if (children.length === 0) {
subtree = null;
}
Expand All @@ -60,32 +63,25 @@ Wraps up the markdown-it parser for use in TiddlyWiki5
}
else {
return {
text: node.data,
text: node.textContent,
type: 'text'
};
}
}
if (node.name) {
if (node.tagName) {
const widget = {
attributes: {},
tag: node.name,
tag: node.tagName.toLowerCase(),
type: 'element'
};
$tw.utils.each(node.attribs, (value, attribute) => {
widget.attributes[attribute] = {
$tw.utils.each(node.attributes, (attribute) => {
widget.attributes[attribute.nodeName] = {
type: 'string',
value: value,
value: attribute.nodeValue
};
});
if (widget.tag === 'a') {
widget.attributes.class = widget.attributes.class || {
type: 'string',
value: '',
};
widget.attributes.class.value += ' tc-tiddlylink';
}
widget.children = [];
node.children.forEach((child) => {
node.childNodes.forEach((child) => {
const isPlainText = (
forceText ||
widget.tag === 'code' ||
Expand All @@ -100,17 +96,8 @@ Wraps up the markdown-it parser for use in TiddlyWiki5
class MarkdownParser {
constructor(type, text, options) {
const source = markdown.render(text);
const handler = new Tautologistics.NodeHtmlParser.DefaultHandler((error, dom) => {
if (error) { console.error(error); }
}, {verbose: true});
const parser = new Tautologistics.NodeHtmlParser.Parser(handler);
parser.parseComplete(source);
this.tree = tiddlify({
children: handler.dom,
name: 'body',
type: 'tag',
}).children;
console.log(this.tree);
const tree = dom.parseFromString(source, 'text/html');
this.tree = tiddlify(tree.body).children;
}
}

Expand Down

0 comments on commit e0b0ef8

Please sign in to comment.