MCPcopy Create free account
hub / github.com/TruthHun/BookStack / markdownWriter

Function markdownWriter

static/word2md/mammoth.browser.js:3529–3592  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

3527}
3528
3529function markdownWriter() {
3530 var fragments = [];
3531 var elementStack = [];
3532 var list = null;
3533 var listItem = {};
3534
3535 function open(tagName, attributes) {
3536 attributes = attributes || {};
3537
3538 var createElement = htmlToMarkdown[tagName] || function() {
3539 return {};
3540 };
3541 var element = createElement(attributes, list, listItem);
3542 elementStack.push({end: element.end, list: list});
3543
3544 if (element.list) {
3545 list = element.list;
3546 }
3547
3548 var anchorBeforeStart = element.anchorPosition === "before";
3549 if (anchorBeforeStart) {
3550 writeAnchor(attributes);
3551 }
3552
3553 fragments.push(element.start || "");
3554 if (!anchorBeforeStart) {
3555 writeAnchor(attributes);
3556 }
3557 }
3558
3559 function writeAnchor(attributes) {
3560 if (attributes.id) {
3561 fragments.push('<a id="' + attributes.id + '"></a>');
3562 }
3563 }
3564
3565 function close(tagName) {
3566 var element = elementStack.pop();
3567 list = element.list;
3568 var end = _.isFunction(element.end) ? element.end() : element.end;
3569 fragments.push(end || "");
3570 }
3571
3572 function selfClosing(tagName, attributes) {
3573 open(tagName, attributes);
3574 close(tagName);
3575 }
3576
3577 function text(value) {
3578 fragments.push(escapeMarkdown(value));
3579 }
3580
3581 function asString() {
3582 return fragments.join("");
3583 }
3584
3585 return {
3586 asString: asString,

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected