diff --git a/packages/plugin-code-blocks/__tests__/integration/__snapshots__/monorepo.spec.ts.snap b/packages/plugin-code-blocks/__tests__/integration/__snapshots__/monorepo.spec.ts.snap index 8d77042d..7424b041 100644 --- a/packages/plugin-code-blocks/__tests__/integration/__snapshots__/monorepo.spec.ts.snap +++ b/packages/plugin-code-blocks/__tests__/integration/__snapshots__/monorepo.spec.ts.snap @@ -69,8 +69,8 @@ exports[`Real behavior should render correctly 1`] = ` @@ -101,7 +101,7 @@ exports[`Real behavior should render correctly 1`] = `
-

From ./packages/a/blocks/test.json

+

From ./packages/a/examples/test.json

{"pkg": "a"}
 
@@ -135,7 +135,7 @@ exports[`Real behavior should render correctly 1`] = `
-

From ./packages/b/blocks/test.json

+

From ./packages/b/examples/test.json

{"pkg": "b"}
 
@@ -146,14 +146,14 @@ exports[`Real behavior should render correctly 1`] = ` -
-

testNoPrefixImplicitInBlocks +
+

testNoPrefixImplicitInExamples

    -
  • testNoPrefixImplicitInBlocks(): number
  • +
  • testNoPrefixImplicitInExamples(): number
  • @@ -164,12 +164,12 @@ exports[`Real behavior should render correctly 1`] = `
    -

    A test code block for unprefixed path implicitly in blocks directory

    +

    A test code block for unprefixed path implicitly in examples directory

    -

    From ./packages/a/blocks/test.json

    +

    From ./packages/a/examples/test.json

    {"pkg": "a"}
     
    @@ -180,14 +180,14 @@ exports[`Real behavior should render correctly 1`] = `

-
-

testNoPrefixInBlocks +
+

testNoPrefixInExamples

    -
  • testNoPrefixInBlocks(): number
  • +
  • testNoPrefixInExamples(): number

@@ -362,7 +362,7 @@ exports[`Real behavior should render correctly 2`] = `
-

From ./packages/a/blocks/test.json

+

From ./packages/a/examples/test.json

{"pkg": "a"}
 
@@ -396,7 +396,7 @@ exports[`Real behavior should render correctly 2`] = `
-

From ./packages/b/blocks/test.json

+

From ./packages/b/examples/test.json

{"pkg": "b"}
 
@@ -407,14 +407,14 @@ exports[`Real behavior should render correctly 2`] = ` -
-

testNoPrefixImplicitInBlocks +
+

testNoPrefixImplicitInExamples

    -
  • testNoPrefixImplicitInBlocks(): number
  • +
  • testNoPrefixImplicitInExamples(): number
  • @@ -425,12 +425,12 @@ exports[`Real behavior should render correctly 2`] = `
    -

    A test code block for unprefixed path implicitly in blocks directory

    +

    A test code block for unprefixed path implicitly in examples directory

    -

    From ./packages/b/blocks/test.json

    +

    From ./packages/b/examples/test.json

    {"pkg": "b"}
     
    @@ -441,14 +441,14 @@ exports[`Real behavior should render correctly 2`] = `

-
-

testNoPrefixInBlocks +
+

testNoPrefixInExamples

    -
  • testNoPrefixInBlocks(): number
  • +
  • testNoPrefixInExamples(): number

Functions

-
-

testNoPrefixImplicitInBlocks +
+

testNoPrefixImplicitInExamples

    -
  • testNoPrefixImplicitInBlocks(): number
  • +
  • testNoPrefixImplicitInExamples(): number
  • -

    A test code block for unprefixed path implicitly in blocks directory

    +

    A test code block for unprefixed path implicitly in examples directory

    -

    From ./blocks/test.json

    +

    From ./examples/test.json

    {"Hello": "World"}
     
    @@ -109,30 +109,30 @@ exports[`Real behavior should render correctly 1`] = `

-
-

testNoPrefixInBlocks +
+

testNoPrefixInExamples

    -
  • testNoPrefixInBlocks(): number
  • +
  • testNoPrefixInExamples(): number
  • -

    A test code block for unprefixed path in blocks directory

    +

    A test code block for unprefixed path in examples directory

    -

    From ./blocks/test.json

    +

    From ./examples/test.json

    {"Hello": "World"}
     
    @@ -143,30 +143,30 @@ exports[`Real behavior should render correctly 1`] = `

-
-

testProjImplicitInBlocks +
+

testProjImplicitInExamples

    -
  • testProjImplicitInBlocks(): number
  • +
  • testProjImplicitInExamples(): number
  • -

    A test code block for project path implicitly in blocks directory

    +

    A test code block for project path implicitly in examples directory

    -

    From ./blocks/test.json

    +

    From ./examples/test.json

    {"Hello": "World"}
     
    @@ -177,30 +177,30 @@ exports[`Real behavior should render correctly 1`] = `

-
-

testProjInBlocks +
+

testProjInExamples

    -
  • testProjInBlocks(): number
  • +
  • testProjInExamples(): number
  • -

    A test code block for project path in blocks directory

    +

    A test code block for project path in examples directory

    -

    From ./blocks/test.json

    +

    From ./examples/test.json

    {"Hello": "World"}
     
    @@ -255,10 +255,10 @@ exports[`Real behavior should render correctly 1`] = ` diff --git a/packages/plugin-code-blocks/__tests__/integration/monorepo.spec.ts b/packages/plugin-code-blocks/__tests__/integration/monorepo.spec.ts index 75ab4f8b..93d982f5 100644 --- a/packages/plugin-code-blocks/__tests__/integration/monorepo.spec.ts +++ b/packages/plugin-code-blocks/__tests__/integration/monorepo.spec.ts @@ -23,19 +23,19 @@ describe( 'Real behavior', () => { const pkgA = await readFile( resolve( rootDir, 'docs/modules/pkg_a.html' ), 'utf-8' ); const domA = new JSDOM( pkgA ); - checkDef( domA, 'testInProjA', formatExpanded( './packages/a/blocks/test.json', testJsonA ) ); - checkDef( domA, 'testInProjB', formatExpanded( './packages/b/blocks/test.json', testJsonB ) ); - checkDef( domA, 'testNoPrefixImplicitInBlocks', formatExpanded( './packages/a/blocks/test.json', testJsonA ) ); - checkDef( domA, 'testNoPrefixInBlocks', formatExpanded( './packages/a/blocks/test.json', testJsonA ) ); + checkDef( domA, 'testInProjA', formatExpanded( './packages/a/examples/test.json', testJsonA ) ); + checkDef( domA, 'testInProjB', formatExpanded( './packages/b/examples/test.json', testJsonB ) ); + checkDef( domA, 'testNoPrefixImplicitInExamples', formatExpanded( './packages/a/examples/test.json', testJsonA ) ); + checkDef( domA, 'testNoPrefixInExamples', formatExpanded( './packages/a/examples/test.json', testJsonA ) ); expect( pkgA ).toMatch( // ); expect( formatHtml( pkgA ) ).toMatchSnapshot(); const pkgB = await readFile( resolve( rootDir, 'docs/modules/pkg_b.html' ), 'utf-8' ); const domB = new JSDOM( pkgB ); - checkDef( domB, 'testInProjA', formatExpanded( './packages/a/blocks/test.json', testJsonA ) ); - checkDef( domB, 'testInProjB', formatExpanded( './packages/b/blocks/test.json', testJsonB ) ); - checkDef( domB, 'testNoPrefixImplicitInBlocks', formatExpanded( './packages/b/blocks/test.json', testJsonB ) ); - checkDef( domB, 'testNoPrefixInBlocks', formatExpanded( './packages/b/blocks/test.json', testJsonB ) ); + checkDef( domB, 'testInProjA', formatExpanded( './packages/a/examples/test.json', testJsonA ) ); + checkDef( domB, 'testInProjB', formatExpanded( './packages/b/examples/test.json', testJsonB ) ); + checkDef( domB, 'testNoPrefixImplicitInExamples', formatExpanded( './packages/b/examples/test.json', testJsonB ) ); + checkDef( domB, 'testNoPrefixInExamples', formatExpanded( './packages/b/examples/test.json', testJsonB ) ); expect( pkgB ).toMatch( // ); expect( formatHtml( pkgB ) ).toMatchSnapshot(); } ); diff --git a/packages/plugin-code-blocks/__tests__/integration/simple.spec.ts b/packages/plugin-code-blocks/__tests__/integration/simple.spec.ts index a7edfb73..ba731a73 100644 --- a/packages/plugin-code-blocks/__tests__/integration/simple.spec.ts +++ b/packages/plugin-code-blocks/__tests__/integration/simple.spec.ts @@ -21,10 +21,10 @@ describe( 'Real behavior', () => { '{"Hello": "World"}\n'+ ''; const testJsonFooBar = testJson.replace( 'Hello', 'Foo' ).replace( 'World', 'Bar' ); - checkDef( dom, 'testProjImplicitInBlocks', formatExpanded( './blocks/test.json', testJson ) ); - checkDef( dom, 'testProjInBlocks', formatExpanded( './blocks/test.json', testJson ) ); - checkDef( dom, 'testNoPrefixImplicitInBlocks', formatExpanded( './blocks/test.json', testJson ) ); - checkDef( dom, 'testNoPrefixInBlocks', formatExpanded( './blocks/test.json', testJson ) ); + checkDef( dom, 'testProjImplicitInExamples', formatExpanded( './examples/test.json', testJson ) ); + checkDef( dom, 'testProjInExamples', formatExpanded( './examples/test.json', testJson ) ); + checkDef( dom, 'testNoPrefixImplicitInExamples', formatExpanded( './examples/test.json', testJson ) ); + checkDef( dom, 'testNoPrefixInExamples', formatExpanded( './examples/test.json', testJson ) ); checkDef( dom, 'testRel', formatExpanded( './src/test.json', testJsonFooBar ) ); expect( c ).toMatch( // ); expect( formatHtml( c ) ).toMatchSnapshot(); diff --git a/packages/plugin-code-blocks/__tests__/mock-fs/monorepo/packages/a/blocks/test.json b/packages/plugin-code-blocks/__tests__/mock-fs/monorepo/packages/a/examples/test.json similarity index 100% rename from packages/plugin-code-blocks/__tests__/mock-fs/monorepo/packages/a/blocks/test.json rename to packages/plugin-code-blocks/__tests__/mock-fs/monorepo/packages/a/examples/test.json diff --git a/packages/plugin-code-blocks/__tests__/mock-fs/monorepo/packages/a/src/index.ts b/packages/plugin-code-blocks/__tests__/mock-fs/monorepo/packages/a/src/index.ts index 757929eb..7a623ac6 100644 --- a/packages/plugin-code-blocks/__tests__/mock-fs/monorepo/packages/a/src/index.ts +++ b/packages/plugin-code-blocks/__tests__/mock-fs/monorepo/packages/a/src/index.ts @@ -18,16 +18,16 @@ export const testInProjB = stub; // #region inPackage /** - * A test code block for unprefixed path implicitly in blocks directory + * A test code block for unprefixed path implicitly in `examples` directory * * {@codeblock test.json} */ -export const testNoPrefixImplicitInBlocks = stub; +export const testNoPrefixImplicitInExamples = stub; /** - * A test code block for unprefixed path in blocks directory + * A test code block for unprefixed path in `examples` directory * - * {@codeblock blocks/test.json} + * {@codeblock examples/test.json} */ -export const testNoPrefixInBlocks = stub; +export const testNoPrefixInExamples = stub; // #endregion diff --git a/packages/plugin-code-blocks/__tests__/mock-fs/monorepo/packages/b/blocks/test.json b/packages/plugin-code-blocks/__tests__/mock-fs/monorepo/packages/b/examples/test.json similarity index 100% rename from packages/plugin-code-blocks/__tests__/mock-fs/monorepo/packages/b/blocks/test.json rename to packages/plugin-code-blocks/__tests__/mock-fs/monorepo/packages/b/examples/test.json diff --git a/packages/plugin-code-blocks/__tests__/mock-fs/monorepo/packages/b/src/index.ts b/packages/plugin-code-blocks/__tests__/mock-fs/monorepo/packages/b/src/index.ts index 757929eb..7a623ac6 100644 --- a/packages/plugin-code-blocks/__tests__/mock-fs/monorepo/packages/b/src/index.ts +++ b/packages/plugin-code-blocks/__tests__/mock-fs/monorepo/packages/b/src/index.ts @@ -18,16 +18,16 @@ export const testInProjB = stub; // #region inPackage /** - * A test code block for unprefixed path implicitly in blocks directory + * A test code block for unprefixed path implicitly in `examples` directory * * {@codeblock test.json} */ -export const testNoPrefixImplicitInBlocks = stub; +export const testNoPrefixImplicitInExamples = stub; /** - * A test code block for unprefixed path in blocks directory + * A test code block for unprefixed path in `examples` directory * - * {@codeblock blocks/test.json} + * {@codeblock examples/test.json} */ -export const testNoPrefixInBlocks = stub; +export const testNoPrefixInExamples = stub; // #endregion diff --git a/packages/plugin-code-blocks/__tests__/mock-fs/monorepo/typedoc.js b/packages/plugin-code-blocks/__tests__/mock-fs/monorepo/typedoc.js index a0edeb08..130c563d 100644 --- a/packages/plugin-code-blocks/__tests__/mock-fs/monorepo/typedoc.js +++ b/packages/plugin-code-blocks/__tests__/mock-fs/monorepo/typedoc.js @@ -1,7 +1,6 @@ module.exports = { - 'entryPoints': [ + entryPoints: [ 'packages/*', ], - 'entryPointStrategy': 'packages', - 'pluginCodeBlocks:source': 'blocks', + entryPointStrategy: 'packages', }; diff --git a/packages/plugin-code-blocks/__tests__/mock-fs/simple/blocks/test.json b/packages/plugin-code-blocks/__tests__/mock-fs/simple/blocks/test.json deleted file mode 100644 index 2e57bd1e..00000000 --- a/packages/plugin-code-blocks/__tests__/mock-fs/simple/blocks/test.json +++ /dev/null @@ -1 +0,0 @@ -{"Hello": "World"} \ No newline at end of file diff --git a/packages/plugin-code-blocks/__tests__/mock-fs/monorepo/blocks/test.json b/packages/plugin-code-blocks/__tests__/mock-fs/simple/examples/test.json similarity index 100% rename from packages/plugin-code-blocks/__tests__/mock-fs/monorepo/blocks/test.json rename to packages/plugin-code-blocks/__tests__/mock-fs/simple/examples/test.json diff --git a/packages/plugin-code-blocks/__tests__/mock-fs/simple/src/test.ts b/packages/plugin-code-blocks/__tests__/mock-fs/simple/src/test.ts index cca8a907..f6da1d58 100644 --- a/packages/plugin-code-blocks/__tests__/mock-fs/simple/src/test.ts +++ b/packages/plugin-code-blocks/__tests__/mock-fs/simple/src/test.ts @@ -9,32 +9,32 @@ const stub = () => 1; export const testRel = stub; // #endregion -// #region projPath /** - * A test code block for unprefixed path implicitly in blocks directory + * A test code block for unprefixed path implicitly in `examples` directory * * {@codeblock test.json} */ -export const testNoPrefixImplicitInBlocks = stub; +export const testNoPrefixImplicitInExamples = stub; /** - * A test code block for unprefixed path in blocks directory + * A test code block for unprefixed path in `examples` directory * - * {@codeblock blocks/test.json} + * {@codeblock examples/test.json} */ -export const testNoPrefixInBlocks = stub; +export const testNoPrefixInExamples = stub; +// #region projPath /** - * A test code block for project path in blocks directory + * A test code block for project path implicitly in `examples` directory * - * {@codeblock ~~/blocks/test.json} + * {@codeblock ~~/test.json} */ -export const testProjInBlocks = stub; +export const testProjImplicitInExamples = stub; +// #endregion /** - * A test code block for project path implicitly in blocks directory + * A test code block for project path in `examples` directory * - * {@codeblock ~~/test.json} + * {@codeblock ~~/examples/test.json} */ -export const testProjImplicitInBlocks = stub; -// #endregion +export const testProjInExamples = stub; diff --git a/packages/plugin-code-blocks/__tests__/mock-fs/simple/typedoc.js b/packages/plugin-code-blocks/__tests__/mock-fs/simple/typedoc.js index 3e2629da..bd55053b 100644 --- a/packages/plugin-code-blocks/__tests__/mock-fs/simple/typedoc.js +++ b/packages/plugin-code-blocks/__tests__/mock-fs/simple/typedoc.js @@ -1,6 +1,5 @@ module.exports = { - 'entryPoints': [ + entryPoints: [ './src/test.ts', ], - 'pluginCodeBlocks:source': 'blocks', }; diff --git a/packages/plugin-code-blocks/src/code-blocks/default-code-block-renderer.tsx b/packages/plugin-code-blocks/src/code-blocks/default-code-block-renderer.tsx index 4906cae0..62c8bf3e 100644 --- a/packages/plugin-code-blocks/src/code-blocks/default-code-block-renderer.tsx +++ b/packages/plugin-code-blocks/src/code-blocks/default-code-block-renderer.tsx @@ -5,7 +5,7 @@ import { DefaultTheme, JSX, PageEvent, RendererEvent } from 'typedoc'; import type { CodeBlockPlugin } from '../plugin'; import { ICodeBlocksPluginThemeMethods } from '../theme'; -import { EBlockMode, ICodeBlock } from '../types'; +import { EBlockMode, ICodeBlock, IInlineCodeBlock } from '../types'; const CSS_FILE_NAME = 'assets/code-blocks.css'; export class DefaultCodeBlockRenderer implements ICodeBlocksPluginThemeMethods { @@ -16,17 +16,23 @@ export class DefaultCodeBlockRenderer implements ICodeBlocksPluginThemeMethods { renderer.hooks.on( 'head.end', context => ); } - public readonly renderCodeBlock = ( { asFile, sourceFile, mode, content, url }: ICodeBlock ) => { - const header =

    - From {url ? {asFile} : <>{asFile}} -

    ; + public readonly renderInlineCodeBlock = ( { fileName, markdownCode, mode }: IInlineCodeBlock ) => this._wrapCode( + <>From {fileName}, + this.theme.getRenderContext( new PageEvent( fileName ) ).markdown( markdownCode ), + mode, + ); - content = content.replace( /\\/g, '\\\\' ).replace( /`/g, '\\`' ); - content = `\`\`\`${extname( sourceFile ).slice( 1 )} -${content} -\`\`\``; - const code = ; + public readonly renderCodeBlock = ( { asFile, sourceFile, mode, content, url }: ICodeBlock ) => this._wrapCode( + <>From {url ? {asFile} : <>{asFile}}, + this.theme.getRenderContext( new PageEvent( asFile ) ).markdown( `\`\`\`${extname( sourceFile ).slice( 1 )} +${content.replace( /\\/g, '\\\\' ).replace( /`/g, '\\`' )} +\`\`\`` ), + mode, + ); + private readonly _wrapCode = ( header: string | JSX.Element, codeHighlighted: string, mode: EBlockMode ) => { + header =

    {header}

    ; + const code = ; switch( mode ){ case EBlockMode.DEFAULT: { return
    diff --git a/packages/plugin-code-blocks/src/index.ts b/packages/plugin-code-blocks/src/index.ts index 6c1c7fca..683866b4 100644 --- a/packages/plugin-code-blocks/src/index.ts +++ b/packages/plugin-code-blocks/src/index.ts @@ -1,4 +1,4 @@ export { load } from './load'; export { ICodeBlocksPluginTheme, ICodeBlocksPluginThemeMethods } from './theme'; export { EInvalidBlockLinkHandling } from './options'; -export { EBlockMode, ICodeBlock } from './types'; +export { EBlockMode, ICodeBlock, IInlineCodeBlock } from './types'; diff --git a/packages/plugin-code-blocks/src/plugin.spec.ts b/packages/plugin-code-blocks/src/plugin.spec.ts index 7aa7d275..69bf45b0 100644 --- a/packages/plugin-code-blocks/src/plugin.spec.ts +++ b/packages/plugin-code-blocks/src/plugin.spec.ts @@ -14,7 +14,7 @@ const { DEFAULT_BLOCK_NAME, readCodeSample: readCodeSampleMock } = require( './c /* eslint-enable @typescript-eslint/no-var-requires */ import { CodeBlockPlugin } from './plugin'; -import { EBlockMode, ICodeBlock } from './types'; +import { EBlockMode, ICodeBlock, IInlineCodeBlock } from './types'; class FakeGitHub { public static readonly REPO_URL = 'https://example.repo.com'; @@ -58,7 +58,8 @@ describe( 'Behavior', () => { const uuid = new Date().toISOString(); const elem = factory( uuid ); const renderCodeBlock = jest.fn().mockReturnValue( elem ); - getCodeBlockRendererMock.mockReturnValue( { renderCodeBlock } ); + const renderInlineCodeBlock = jest.fn().mockReturnValue( elem ); + getCodeBlockRendererMock.mockReturnValue( { renderCodeBlock, renderInlineCodeBlock } ); return { renderCodeBlock, elem, elemStr: JSX.renderElement( elem ) }; }; const sourceFile = resolve( rootDir, file ); diff --git a/packages/plugin-code-blocks/src/plugin.ts b/packages/plugin-code-blocks/src/plugin.ts index 9f5f034a..cab21665 100644 --- a/packages/plugin-code-blocks/src/plugin.ts +++ b/packages/plugin-code-blocks/src/plugin.ts @@ -1,7 +1,7 @@ import assert from 'assert'; import { relative } from 'path'; -import { once } from 'lodash'; +import { escapeRegExp, isString, once } from 'lodash'; import { Application, JSX, LogLevel, PageEvent, Reflection } from 'typedoc'; import { ABasePlugin, CurrentPageMemo, EventsExtra, MarkdownReplacer, PathReflectionResolver } from '@knodes/typedoc-pluginutils'; @@ -12,7 +12,8 @@ import { buildOptions } from './options'; import { CodeBlockReflection } from './reflections'; import { EBlockMode } from './types'; -const EXTRACT_CODE_BLOCKS_REGEX = /\{@codeblock\s+(\S+?\w+?)(?:#(.+?))?(?:\s+(\w+))?(?:\s*\|\s*(.*?))?\}/g; +const EXTRACT_CODE_BLOCKS_REGEX = /\{\\?@codeblock\s+(\S+?\w+?)(?:#(.+?))?(?:\s+(\w+))?(?:\s*\|\s*(.*?))?\s*\}/g; +const EXTRACT_INLINE_CODE_BLOCKS_REGEX = /\{\\?@inline-codeblock\s+(\S+?\w+?)(?:\s+(\w+))?\s*}\n(\s*)(```.*?```)/gs; /** * Pages plugin for integrating your own pages into documentation output */ @@ -35,7 +36,8 @@ export class CodeBlockPlugin extends ABasePlugin { */ public initialize(): void { // Hook over each markdown events to replace code blocks - this._markdownReplacer.bindReplace( EXTRACT_CODE_BLOCKS_REGEX, this._replaceCodeBlock.bind( this ), 'replace code blocks' ); + this._markdownReplacer.bindReplace( EXTRACT_CODE_BLOCKS_REGEX, this._replaceCodeBlock.bind( this ), '{@codeblock}' ); + this._markdownReplacer.bindReplace( EXTRACT_INLINE_CODE_BLOCKS_REGEX, this._replaceInlineCodeBlock.bind( this ), '{@inline-codeblock}' ); this._currentPageMemo.initialize(); EventsExtra.for( this.application ) .onThemeReady( this._codeBlockRenderer.bind( this ) ) @@ -44,6 +46,44 @@ export class CodeBlockPlugin extends ABasePlugin { } ); } + /** + * Transform the parsed inline code block. + * + * @param capture - The captured infos. + * @param sourceHint - The best guess to the source of the match, + * @returns the replaced content. + */ + private _replaceInlineCodeBlock( + { captures, fullMatch }: Parameters[0], + sourceHint: Parameters[1], + ): ReturnType { + // Support escaped tags + if( fullMatch.startsWith( '{\\@' ) ){ + this.logger.verbose( () => `Found an escaped tag "${fullMatch}" in "${sourceHint()}"` ); + return fullMatch.replace( '{\\@', '{@' ); + } + // Extract informations + const [ fileName, blockModeStr, blockIndent, markdownCodeSource ] = captures; + const blockMode = blockModeStr ? + EBlockMode[blockModeStr.toUpperCase() as keyof typeof EBlockMode] ?? assert.fail( `Invalid block mode "${blockModeStr}".` ) : + this.pluginOptions.getValue().defaultBlockMode ?? EBlockMode.EXPANDED; + assert.ok( fileName ); + assert.ok( markdownCodeSource ); + assert.ok( isString( blockIndent ) ); + const markdownCode = markdownCodeSource.replace( new RegExp( `^${escapeRegExp( blockIndent )}`, 'gm' ), '' ); + + // Render + const rendered = this._codeBlockRenderer().renderInlineCodeBlock( { + fileName, + markdownCode, + mode: blockMode, + } ); + if( typeof rendered === 'string' ){ + return rendered; + } else { + return JSX.renderElement( rendered ); + } + } /** * Transform the parsed code block. diff --git a/packages/plugin-code-blocks/src/theme.ts b/packages/plugin-code-blocks/src/theme.ts index 2fa62de3..e6c5e7f1 100644 --- a/packages/plugin-code-blocks/src/theme.ts +++ b/packages/plugin-code-blocks/src/theme.ts @@ -1,9 +1,10 @@ import { RenderTemplate, Theme } from 'typedoc'; -import { ICodeBlock } from './types'; +import { ICodeBlock, IInlineCodeBlock } from './types'; export interface ICodeBlocksPluginThemeMethods { renderCodeBlock: RenderTemplate; + renderInlineCodeBlock: RenderTemplate; } export interface ICodeBlocksPluginTheme extends Theme { codeBlocksPlugin: ICodeBlocksPluginThemeMethods; diff --git a/packages/plugin-code-blocks/src/types.ts b/packages/plugin-code-blocks/src/types.ts index f31745d9..f5476975 100644 --- a/packages/plugin-code-blocks/src/types.ts +++ b/packages/plugin-code-blocks/src/types.ts @@ -10,3 +10,8 @@ export interface ICodeBlock { content: string; url?: string; } +export interface IInlineCodeBlock { + mode: EBlockMode; + fileName: string; + markdownCode: string; +}