Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DEVENGAGE-2875 Fix code fence examples - markdown renderer #14

Merged
merged 4 commits into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

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