@podlite/schema
Version:
AST tools for Podlite markup language
84 lines • 3.87 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const fcparser = __importStar(require("./grammarfc"));
const makeTransformer_1 = __importDefault(require("./helpers/makeTransformer"));
const makeTransformer_2 = require("./helpers/makeTransformer");
const config_1 = __importDefault(require("./helpers/config"));
const middle = () => tree => {
const transformerBlocks = (0, makeTransformer_1.default)({
':para': (n, ctx, visiter) => {
return (0, makeTransformer_1.default)({
':text': (n, ctx) => {
return fcparser.parse(n.value);
},
':verbatim': (n, ctx) => {
return fcparser.parse(n.value);
},
})(n, { ...ctx });
return n;
},
':block': (n, ctx, visiter) => {
// only =pod may have childs blocks
if ('name' in n && n.name === 'pod')
return {
...n,
content: visiter(n.content, ctx, visiter),
};
const conf = (0, config_1.default)(n, ctx);
const isCodeBlock = 'name' in n && n.name === 'code';
const isDataBlock = 'name' in n && n.name === 'data';
const isMarkdownBlock = 'name' in n && n.name === 'markdown';
const isPictureBlock = 'name' in n && n.name === 'picture';
const isFormulaBlock = 'name' in n && n.name === 'formula';
const allowValues = [...conf.getAllValues('allow'), ...(isCodeBlock ? ['NONE'] : [])];
if ((0, makeTransformer_2.isNamedBlock)(n.name))
return n;
// for code block not parse content by default
if ((isCodeBlock || isDataBlock || isMarkdownBlock || isPictureBlock || isFormulaBlock) &&
allowValues.length == 0)
return n;
const allowed = allowValues.sort();
const transformer = (0, makeTransformer_1.default)({
':verbatim': (n, ctx) => {
// special case for code block, 'NONE' - flag disabled all markup codes
// do not parse content by default
if (allowed.length == 1 && allowed.includes('NONE'))
return n;
return fcparser.parse(n.value, { allowed });
},
':text': (n, ctx) => {
return fcparser.parse(n.value, { allowed });
},
':block': (n, ctx) => {
return transformerBlocks(n, { ...ctx });
},
});
return { ...n, content: transformer(n.content, { ...ctx }) };
},
});
return transformerBlocks(tree, {});
};
exports.default = middle;
//# sourceMappingURL=plugin-formatting-codes.js.map