honkit
Version:
HonKit is building beautiful books using Markdown.
28 lines (26 loc) • 1.19 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const is_1 = __importDefault(require("is"));
const removeArticle_1 = __importDefault(require("./removeArticle"));
const insertArticle_1 = __importDefault(require("./insertArticle"));
/**
Returns a new summary, with the given article removed from its
origin level, and placed at the given target level.
@param {Summary} summary
@param {String|SummaryArticle} origin: level to remove
@param {String|SummaryArticle} target: the level where the article will be found
@return {Summary}
*/
function moveArticle(summary, origin, target) {
// Coerce to level
const originLevel = is_1.default.string(origin) ? origin : origin.getLevel();
const targetLevel = is_1.default.string(target) ? target : target.getLevel();
const article = summary.getByLevel(originLevel);
// Remove first
const removed = (0, removeArticle_1.default)(summary, originLevel);
return (0, insertArticle_1.default)(removed, article, targetLevel);
}
exports.default = moveArticle;