function appendEscapedMarkdownCodeBlockFence(code, langId) {
    var _a, _b;
    const longestFenceLength = (_b = (_a = code.match(/^`+/gm)) === null || _a === void 0 ? void 0 : _a.reduce((a, b) => (a.length > b.length ? a : b)).length) !== null && _b !== void 0 ? _b : 0;
    const desiredFenceLength = longestFenceLength >= 3 ? longestFenceLength + 1 : 3;
    // the markdown result
    return [
        `${'`'.repeat(desiredFenceLength)}${langId}`,
        code,
        `${'`'.repeat(desiredFenceLength)}`,
    ].join('\n');
}
@see https://github.com/microsoft/vscode/issues/193746