1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2025-07-30 04:23:11 +03:00

Rolled out text alignment to other block types

Completed off alignment types and markdown handling in the process.
This commit is contained in:
Dan Brown
2022-01-12 10:18:06 +00:00
parent 6744ab2ff9
commit 717557df89
3 changed files with 102 additions and 44 deletions

View File

@ -4,10 +4,12 @@ import {docToHtml} from "./util";
const nodes = defaultMarkdownSerializer.nodes;
const marks = defaultMarkdownSerializer.marks;
nodes.callout = function(state, node) {
writeNodeAsHtml(state, node);
};
marks.underline = {
open: '<span style="text-decoration: underline;">',
close: '</span>',
@ -28,12 +30,28 @@ marks.subscript = {
close: '</sub>',
};
function writeNodeAsHtml(state, node) {
const html = docToHtml({ content: [node] });
state.write(html);
state.ensureNewLine();
state.write('\n');
state.closeBlock();
}
// Update serializers to just write out as HTML if we have an attribute
// or element that cannot be represented in commonmark without losing
// formatting or content.
for (const [nodeType, serializerFunction] of Object.entries(nodes)) {
nodes[nodeType] = function(state, node) {
if (node.attrs.align) {
writeNodeAsHtml(state, node);
} else {
serializerFunction(state, node);
}
}
}
const serializer = new MarkdownSerializer(nodes, marks);