sample-app-aoai-chatGPT icon indicating copy to clipboard operation
sample-app-aoai-chatGPT copied to clipboard

Styling of inline code references

Open Bouke opened this issue 1 year ago • 1 comments

Describe the bug Inline

codeblocks

are not

rendered

on the

same line

.

To Reproduce Steps to reproduce the behavior:

  1. Trigger inline code blocks

Expected behavior It should render inline codeblocks on the same line.

Screenshots image

Configuration: Please provide the following N/A

Logs N/A

Additional context N/A

Bouke avatar Sep 16 '24 15:09 Bouke

I have added the following custom styles, which seem to work pretty ok:

p > div, li > div {
	display: inline;
	line-height: inherit !important;
	margin: 0 !important;
	padding: 2px 4px !important;
}

image

Bouke avatar Sep 23 '24 17:09 Bouke

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] avatar Nov 23 '24 02:11 github-actions[bot]

This issue was closed because it has been inactive for 14 days since being marked as stale.

github-actions[bot] avatar Dec 07 '24 02:12 github-actions[bot]

Not stale, just unresponsive maintainers.

Bouke avatar Dec 07 '24 05:12 Bouke

I had ChatGPT do it for me.

Image

  1. In answer.tsx, update your components definition
const components = {
  code({
    inline,
    className,
    children,
    node,
    ...props
  }: {
    inline?: boolean;
    className?: string;
    children?: React.ReactNode;
    node?: any;
  }) {
    // If this is *inline* code (single backticks), just render a normal inline <code>
    if (inline) {
      return <code {...props}>{children}</code>;
    }

    // If it's a fenced code block (triple backticks), parse the language from className
    const match = /language-(\w+)/.exec(className || '');
    const language = match ? match[1] : '';

    // Convert children to a string, removing trailing newlines
    const codeString = String(children).replace(/\n$/, '');

    // Now syntax highlight, so it appears as a block
    return (
      <SyntaxHighlighter style={nord} language={language} PreTag="div" {...props}>
        {codeString}
      </SyntaxHighlighter>
    );
  },
};
  1. In Answer.module.css, add
.answerText code {
  background-color: #f5f5f5; /* or your preferred color */
  color: #c7254e;           /* optional text color */
  padding: 2px 4px;         /* small horizontal padding */
  border-radius: 4px;       /* rounded corners */
  font-family: Menlo, Monaco, "Liberation Mono", Consolas, monospace;
  font-size: 90%;           /* typically a bit smaller than normal text */
}

koberghe avatar Mar 06 '25 21:03 koberghe