/**
* Copyright (c) 2017-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
const React = require('react');
const MarkdownBlock = require('./MarkdownBlock.js');
const CodeTabsMarkdownBlock = require('./CodeTabsMarkdownBlock.js');
const translate = require('../server/translate.js').translate;
const editThisDoc = translate(
'Edit this Doc|recruitment message asking to edit the doc source',
);
const translateThisDoc = translate(
'Translate this Doc|recruitment message asking to translate the docs',
);
const splitTabsToTitleAndContent = content => {
const titles = content.match(//gms);
const tabs = content.split(//gms);
if (!titles || !tabs || !titles.length || !tabs.length) {
return [];
}
tabs.shift();
return titles.map((title, idx) => ({
title: title.substring(4, title.length - 3).trim(),
content: tabs[idx],
}));
};
// inner doc component for article itself
class Doc extends React.Component {
renderContent() {
const {content} = this.props;
let inCodeTabs = false;
const contents = content.split(
/(\n)(.*?)(\n)/gms,
);
const renderResult = contents.map((c, index) => {
if (c === '\n') {
inCodeTabs = true;
return null;
}
if (c === '\n') {
inCodeTabs = false;
return null;
}
if (inCodeTabs) {
return (