fix code context description parsing to filename & range
This commit is contained in:
parent
d5491cc21c
commit
7ec29ba7e6
5 changed files with 16 additions and 9 deletions
|
|
@ -57,9 +57,12 @@ async function resolveEditorContent(
|
|||
}
|
||||
} else if (p.type === "codeBlock") {
|
||||
if (!p.attrs.item.editing) {
|
||||
let meta = p.attrs.item.description.split(" ");
|
||||
let relativePath = meta[0] || "";
|
||||
let extName = relativePath.split(".").slice(-1)[0];
|
||||
const text =
|
||||
"```" +
|
||||
p.attrs.item.description +
|
||||
"\n\n" +
|
||||
"```" + extName + " " + p.attrs.item.description +
|
||||
"\n" +
|
||||
p.attrs.item.content +
|
||||
"\n```";
|
||||
|
|
|
|||
|
|
@ -86,6 +86,7 @@ interface CodeBlockToolBarProps {
|
|||
language: string | undefined;
|
||||
isNextCodeBlock: boolean;
|
||||
filepath?: string;
|
||||
range?: string;
|
||||
}
|
||||
|
||||
const terminalLanguages = ["bash", "sh"];
|
||||
|
|
|
|||
|
|
@ -95,7 +95,7 @@ function CodeSnippetPreview(props: CodeSnippetPreviewProps) {
|
|||
.split(")")[0]
|
||||
.split("-");
|
||||
ideMessenger.ide.showLines(
|
||||
props.item.description,
|
||||
props.item.description.split(" ")[0],
|
||||
parseInt(lines[0]) - 1,
|
||||
parseInt(lines[1]) - 1,
|
||||
);
|
||||
|
|
@ -145,8 +145,8 @@ function CodeSnippetPreview(props: CodeSnippetPreviewProps) {
|
|||
>
|
||||
<StyledMarkdownPreview
|
||||
source={`${fence}${getMarkdownLanguageTagForFile(
|
||||
props.item.description,
|
||||
)}\n${content}\n${fence}`}
|
||||
props.item.description.split(" ")[0],
|
||||
)} ${props.item.description}\n${content}\n${fence}`}
|
||||
showCodeBorder={false}
|
||||
/>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@ function PreWithToolbar(props: {
|
|||
language: string | null;
|
||||
codeBlockIndex: number;
|
||||
filepath?: string | undefined;
|
||||
range?: string;
|
||||
}) {
|
||||
const uiConfig = useUIConfig();
|
||||
const toolbarBottom = uiConfig?.codeBlockToolbarPosition == "bottom";
|
||||
|
|
|
|||
|
|
@ -126,14 +126,15 @@ const StyledMarkdownPreview = memo(function StyledMarkdownPreview(
|
|||
visit(tree, "code", (node: any) => {
|
||||
if (!node.lang) {
|
||||
node.lang === "javascript";
|
||||
} else if (node.lang.includes(".")) {
|
||||
node.lang = node.lang.split(".").slice(-1)[0];
|
||||
}
|
||||
|
||||
if (node.meta) {
|
||||
node.data = node.data || {};
|
||||
node.data.hProperties = node.data.hProperties || {};
|
||||
node.data.hProperties.filepath = node.meta;
|
||||
|
||||
let meta = node.meta.split(" ");
|
||||
node.data.hProperties.filepath = meta[0];
|
||||
node.data.hProperties.range = meta[1];
|
||||
}
|
||||
});
|
||||
};
|
||||
|
|
@ -172,13 +173,14 @@ const StyledMarkdownPreview = memo(function StyledMarkdownPreview(
|
|||
);
|
||||
},
|
||||
pre: ({ node, ...preProps }) => {
|
||||
const { className, filepath } = preProps?.children?.[0]?.props;
|
||||
const { className, filepath, range } = preProps?.children?.[0]?.props;
|
||||
|
||||
return props.showCodeBorder ? (
|
||||
<PreWithToolbar
|
||||
codeBlockIndex={preProps.codeBlockIndex}
|
||||
language={getLanuageFromClassName(className)}
|
||||
filepath={filepath}
|
||||
range={range}
|
||||
>
|
||||
<SyntaxHighlightedPre {...preProps}></SyntaxHighlightedPre>
|
||||
</PreWithToolbar>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue