Skip to content

Commit

Permalink
Merge pull request #14 from purecloudlabs/DEVENGAGE-2875-code-fence-l…
Browse files Browse the repository at this point in the history
…iteral

DEVENGAGE-2875 Fix code fence examples - markdown renderer
  • Loading branch information
timsmithgenesys authored Feb 7, 2025
2 parents bb7d6d4 + bb2add5 commit c5bf695
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 10 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions yeast-markdown-renderer/dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion yeast-markdown-renderer/dist/index.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions yeast-markdown-renderer/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion yeast-markdown-renderer/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "yeast-markdown-renderer",
"version": "1.1.0",
"version": "1.2.0",
"description": "The yeast markdown renderer project provides a class to render yeast documents in markdown ",
"exports": {
"require": "./src/index.ts",
Expand Down
10 changes: 8 additions & 2 deletions yeast-markdown-renderer/src/YeastNodeTypes/BlockCodeNode.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { MarkdownRenderer } from '../MarkdownRenderer';
import { BlockCodeNode } from 'yeast-core';

// Matches case when codeblock content is a literal codeblock example
const LITERAL_BACKTICK_REGEX = /((?:^|\n+)(?:\t+|\s+)*)(`{3})/ig;
const LITERAL_TILDE_REGEX = /((?:^|\n+)(?:\t+|\s+)*)(~{3})/ig;

export default function renderBlockCodeNode(node: BlockCodeNode, renderer: MarkdownRenderer) {
const jsonOptions = {
title: node.title,
Expand All @@ -10,7 +14,9 @@ export default function renderBlockCodeNode(node: BlockCodeNode, renderer: Markd
tabsToSpaces: node.tabsToSpaces,
showLineNumbers: node.showLineNumbers,
};
const children = node.value.split('\n');
const backtickEscapedVal = node.value.replace(LITERAL_BACKTICK_REGEX, '$1\\$2');
const tildeEscapedVal = backtickEscapedVal.replace(LITERAL_TILDE_REGEX, '$1\\$2');
const children = tildeEscapedVal.split('\n');
let finalVal = '';
const indentation = '\t';
children.forEach((child, index) => {
Expand All @@ -23,7 +29,7 @@ export default function renderBlockCodeNode(node: BlockCodeNode, renderer: Markd
);
if (!hasOptions)
return `\n${indentation.repeat(node.indentation)}\`\`\`${node.language}\n${finalVal}\n${indentation.repeat(node.indentation)}\`\`\`\n`;
return `\n${indentation.repeat(node.indentation)}\`\`\`${JSON.stringify(jsonOptions)}\n${node.value}\n${indentation.repeat(
return `\n${indentation.repeat(node.indentation)}\`\`\`${JSON.stringify(jsonOptions)}\n${tildeEscapedVal}\n${indentation.repeat(
node.indentation
)}\`\`\`\n`;
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export const GENERAL_DATA = {
type: 'code',
language: 'java',
indentation: 2,
value: "console.log('hello world, I'm codefence')",
value: "```\n// Code goes here\nString str = \"my string\";\n```",
},
{
type: 'callout',
Expand Down

0 comments on commit c5bf695

Please sign in to comment.