Skip to content

Commit

Permalink
rename renderInline method to renderMarkdown
Browse files Browse the repository at this point in the history
  • Loading branch information
ZeeshanTamboli committed Sep 14, 2023
1 parent e1fe40a commit 6e790fc
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 25 deletions.
4 changes: 2 additions & 2 deletions docs/src/pages/production-error/ErrorDecoder.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useRouter } from 'next/router';
import Link from '@mui/material/Link';
import Typography from '@mui/material/Typography';
import { styled } from '@mui/material/styles';
import { renderInline as renderInlineMarkdown } from '@mui/markdown';
import { renderMarkdown } from '@mui/markdown';
import MarkdownElement from 'docs/src/modules/components/MarkdownElement';

const ErrorMessageSection = styled('div')({
Expand Down Expand Up @@ -86,7 +86,7 @@ export default function ErrorDecoder() {
return div.innerHTML;
});

return renderInlineMarkdown(readableMessage);
return renderMarkdown(readableMessage);
}, [args, code, data.errorCodes]);

if (data.state === 'loading') {
Expand Down
23 changes: 11 additions & 12 deletions packages/api-docs-builder/ApiBuilders/ComponentApiBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import remarkVisit from 'unist-util-visit';
import { Link } from 'mdast';
import { defaultHandlers, parse as docgenParse, ReactDocgenApi } from 'react-docgen';
import { unstable_generateUtilityClass as generateUtilityClass } from '@mui/utils';
import { renderInline as renderMarkdownInline } from '@mui/markdown';
import { renderMarkdown } from '@mui/markdown';
import { LANGUAGES } from 'docs/config';
import { ComponentInfo, writePrettifiedFile } from '../buildApiUtils';
import muiDefaultPropsHandler from '../utils/defaultPropsHandler';
Expand Down Expand Up @@ -333,19 +333,19 @@ function extractClassConditions(descriptions: any) {

if (conditions && conditions[6]) {
classConditions[className] = {
description: renderMarkdownInline(
description: renderMarkdown(
description.replace(stylesRegex, '$1{{nodeName}}$5{{conditions}}.'),
),
nodeName: renderMarkdownInline(conditions[3]),
conditions: renderMarkdownInline(conditions[6].replace(/`(.*?)`/g, '<code>$1</code>')),
nodeName: renderMarkdown(conditions[3]),
conditions: renderMarkdown(conditions[6].replace(/`(.*?)`/g, '<code>$1</code>')),
};
} else if (conditions && conditions[3] && conditions[3] !== 'the root element') {
classConditions[className] = {
description: renderMarkdownInline(description.replace(stylesRegex, '$1{{nodeName}}$5.')),
nodeName: renderMarkdownInline(conditions[3]),
description: renderMarkdown(description.replace(stylesRegex, '$1{{nodeName}}$5.')),
nodeName: renderMarkdown(conditions[3]),
};
} else {
classConditions[className] = { description: renderMarkdownInline(description) };
classConditions[className] = { description: renderMarkdown(description) };
}
}
});
Expand Down Expand Up @@ -517,13 +517,13 @@ const attachTranslations = (reactApi: ReactApi) => {

const typeDescriptions: { [t: string]: string } = {};
(signatureArgs || []).concat(signatureReturn || []).forEach(({ name, description }) => {
typeDescriptions[name] = renderMarkdownInline(description);
typeDescriptions[name] = renderMarkdown(description);
});

translations.propDescriptions[propName] = {
description: renderMarkdownInline(jsDocText),
description: renderMarkdown(jsDocText),
requiresRef: requiresRef || undefined,
deprecated: renderMarkdownInline(deprecated) || undefined,
deprecated: renderMarkdown(deprecated) || undefined,
typeDescriptions: Object.keys(typeDescriptions).length > 0 ? typeDescriptions : undefined,
};
}
Expand Down Expand Up @@ -631,8 +631,7 @@ const attachPropsTable = (reactApi: ReactApi) => {
// undefined values are not serialized => saving some bytes
required: requiredProp || undefined,
deprecated: !!deprecation || undefined,
deprecationInfo:
renderMarkdownInline(deprecation?.groups?.info || '').trim() || undefined,
deprecationInfo: renderMarkdown(deprecation?.groups?.info || '').trim() || undefined,
signature,
additionalInfo:
Object.keys(additionalPropsInfo).length === 0 ? undefined : additionalPropsInfo,
Expand Down
11 changes: 5 additions & 6 deletions packages/api-docs-builder/ApiBuilders/HookApiBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import traverse from '@babel/traverse';
import { defaultHandlers, parse as docgenParse, ReactDocgenApi } from 'react-docgen';
import kebabCase from 'lodash/kebabCase';
import upperFirst from 'lodash/upperFirst';
import { renderInline as renderMarkdownInline } from '@mui/markdown';
import { renderMarkdown } from '@mui/markdown';
import { LANGUAGES } from 'docs/config';
import { toGitHubPath, computeApiDescription } from './ComponentApiBuilder';
import {
Expand Down Expand Up @@ -328,8 +328,7 @@ const attachTable = (
// undefined values are not serialized => saving some bytes
required: requiredProp || undefined,
deprecated: !!deprecation || undefined,
deprecationInfo:
renderMarkdownInline(deprecation?.groups?.info || '').trim() || undefined,
deprecationInfo: renderMarkdown(deprecation?.groups?.info || '').trim() || undefined,
},
};
})
Expand All @@ -351,7 +350,7 @@ const attachTable = (
};

const generateTranslationDescription = (description: string) => {
return renderMarkdownInline(description.replace(/\n@default.*$/, ''));
return renderMarkdown(description.replace(/\n@default.*$/, ''));
};

const attachTranslations = (reactApi: ReactApi) => {
Expand All @@ -369,7 +368,7 @@ const attachTranslations = (reactApi: ReactApi) => {
const deprecation = (description || '').match(/@deprecated(\s+(?<info>.*))?/);
if (deprecation !== null) {
translations.parametersDescriptions[propName].deprecated =
renderMarkdownInline(deprecation?.groups?.info || '').trim() || undefined;
renderMarkdown(deprecation?.groups?.info || '').trim() || undefined;
}
}
});
Expand All @@ -382,7 +381,7 @@ const attachTranslations = (reactApi: ReactApi) => {
const deprecation = (description || '').match(/@deprecated(\s+(?<info>.*))?/);
if (deprecation !== null) {
translations.parametersDescriptions[propName].deprecated =
renderMarkdownInline(deprecation?.groups?.info || '').trim() || undefined;
renderMarkdown(deprecation?.groups?.info || '').trim() || undefined;
}
}
});
Expand Down
2 changes: 1 addition & 1 deletion packages/markdown/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ export function getHeaders(markdown: string): Record<string, string | string[]>;

export function getTitle(markdown: string): string;

export function renderInline(markdown: string): string;
export function renderMarkdown(markdown: string): string;
4 changes: 2 additions & 2 deletions packages/markdown/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
const { createRender, getHeaders, getTitle, renderInline } = require('./parseMarkdown');
const { createRender, getHeaders, getTitle, renderMarkdown } = require('./parseMarkdown');

module.exports = { createRender, getHeaders, getTitle, renderInline };
module.exports = { createRender, getHeaders, getTitle, renderMarkdown };
4 changes: 2 additions & 2 deletions packages/markdown/parseMarkdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ function getCodeblock(content) {
/**
* @param {string} markdown
*/
function renderInline(markdown) {
function renderMarkdown(markdown) {
// Check if the markdown contains an inline list. Unordered lists are block elements and cannot be parsed inline.
if (/[-*+] `([A-Za-z]+)`/g.test(markdown)) {
return marked.parse(markdown, markedOptions);
Expand Down Expand Up @@ -475,5 +475,5 @@ module.exports = {
getCodeblock,
getHeaders,
getTitle,
renderInline,
renderMarkdown,
};

0 comments on commit 6e790fc

Please sign in to comment.