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

Fix markdown table to honor alignment directives (#4774)

* Extract withChildren

* Handle table cell alignment

* 🎨 add missing semicolon
This commit is contained in:
ento 2020-07-31 04:01:21 -08:00 committed by GitHub
parent 5a6e35b4b0
commit 7acb9a255b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -69,7 +69,7 @@ function findTagWithType(nodes, startPoint, type, level) {
function convertNodes(remarkableTree, isStartOfInline) { function convertNodes(remarkableTree, isStartOfInline) {
let out = []; let out = [];
var accumulatedText = ''; var accumulatedText = '';
function wrappedElement(elementTag, currentIndex, currentLevel, closingType, nodes) { function withChildren(currentIndex, currentLevel, closingType, nodes, callback) {
var j = findTagWithType(nodes, currentIndex + 1, closingType, currentLevel); var j = findTagWithType(nodes, currentIndex + 1, closingType, currentLevel);
if (j === false) { if (j === false) {
console.error("Failed to find a " + closingType + " node after position " + currentIndex); console.error("Failed to find a " + closingType + " node after position " + currentIndex);
@ -77,14 +77,18 @@ function convertNodes(remarkableTree, isStartOfInline) {
return currentIndex + 1; return currentIndex + 1;
} }
let children = convertNodes(nodes.slice(currentIndex + 1, j)); let children = convertNodes(nodes.slice(currentIndex + 1, j));
callback(children);
out.push({
type: "element",
tag: elementTag,
children: children
});
return j; return j;
} }
function wrappedElement(elementTag, currentIndex, currentLevel, closingType, nodes) {
return withChildren(currentIndex, currentLevel, closingType, nodes, function(children) {
out.push({
type: "element",
tag: elementTag,
children: children
});
});
}
for (var i = 0; i < remarkableTree.length; i++) { for (var i = 0; i < remarkableTree.length; i++) {
var currentNode = remarkableTree[i]; var currentNode = remarkableTree[i];
@ -110,33 +114,32 @@ function convertNodes(remarkableTree, isStartOfInline) {
break; break;
case "link_open": case "link_open":
var j = findTagWithType(remarkableTree, i + 1, "link_close", currentNode.level); i = withChildren(i, currentNode.level, "link_close", remarkableTree, function(children) {
if (currentNode.href[0] !== "#") {
if (currentNode.href[0] !== "#") { // External link
// External link var attributes = {
var attributes = { href: { type: "string", value: currentNode.href }
href: { type: "string", value: currentNode.href } };
}; if (pluginOpts.linkNewWindow) {
if (pluginOpts.linkNewWindow) { attributes.target = { type: "string", value: "_blank" };
attributes.target = { type: "string", value: "_blank" }; }
out.push({
type: "element",
tag: "a",
attributes: attributes,
children: children
});
} else {
// Internal link
out.push({
type: "link",
attributes: {
to: { type: "string", value: decodeURI(currentNode.href.substr(1)) }
},
children: children
});
} }
out.push({ });
type: "element",
tag: "a",
attributes: attributes,
children: convertNodes(remarkableTree.slice(i + 1, j))
});
} else {
// Internal link
out.push({
type: "link",
attributes: {
to: { type: "string", value: decodeURI(currentNode.href.substr(1)) }
},
children: convertNodes(remarkableTree.slice(i + 1, j))
});
}
i = j;
break; break;
case "code": case "code":
@ -185,6 +188,23 @@ function convertNodes(remarkableTree, isStartOfInline) {
}); });
break; break;
case "th_open":
case "td_open":
var elementTag = currentNode.type.slice(0, 2);
i = withChildren(i, currentNode.level, elementTag + "_close", remarkableTree, function(children) {
var attributes = {};
if (currentNode.align) {
attributes.style = { type: "string", value: "text-align:" + currentNode.align };
}
out.push({
type: "element",
tag: elementTag,
attributes: attributes,
children: children
});
});
break;
case "hr": case "hr":
out.push({ out.push({
type: 'element', type: 'element',